mirror of
https://github.com/apple/container.git
synced 2026-09-13 11:15:41 +00:00
Handle keychain query errors in keychain helper lookup (#211)
This allows us to handle errors from lookup with only the keychain helper error types which simplifies the logic related https://github.com/apple/container/pull/331 Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
This commit is contained in:
@@ -29,17 +29,25 @@ public struct KeychainHelper: Sendable {
|
||||
public func lookup(domain: String) throws -> Authentication {
|
||||
let kq = KeychainQuery()
|
||||
|
||||
guard try kq.exists(id: self.id, host: domain) else {
|
||||
throw Self.Error.keyNotFound
|
||||
do {
|
||||
guard try kq.exists(id: self.id, host: domain) else {
|
||||
throw Self.Error.keyNotFound
|
||||
}
|
||||
guard let fetched = try kq.get(id: self.id, host: domain) else {
|
||||
throw Self.Error.keyNotFound
|
||||
}
|
||||
return BasicAuthentication(
|
||||
username: fetched.account,
|
||||
password: fetched.data
|
||||
)
|
||||
} catch let err as KeychainQuery.Error {
|
||||
switch err {
|
||||
case .keyNotPresent(_):
|
||||
throw Self.Error.keyNotFound
|
||||
default:
|
||||
throw Self.Error.queryError("query failure: \(String(describing: err))")
|
||||
}
|
||||
}
|
||||
guard let fetched = try kq.get(id: self.id, host: domain) else {
|
||||
throw Self.Error.keyNotFound
|
||||
}
|
||||
|
||||
return BasicAuthentication(
|
||||
username: fetched.account,
|
||||
password: fetched.data
|
||||
)
|
||||
}
|
||||
|
||||
/// Delete authorization data for a given domain from the keychain.
|
||||
@@ -93,6 +101,7 @@ extension KeychainHelper {
|
||||
public enum Error: Swift.Error {
|
||||
case keyNotFound
|
||||
case invalidInput
|
||||
case queryError(String)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user