@@ -24,10 +24,10 @@ public protocol AuthorizationProvider {
24
24
}
25
25
26
26
public enum AuthorizationProviderError : Error {
27
- case noURLHost
27
+ case invalidURLHost
28
28
case notFound
29
- case unexpectedPasswordData
30
- case unexpectedError ( String )
29
+ case cannotEncodePassword
30
+ case other ( String )
31
31
}
32
32
33
33
extension AuthorizationProvider {
@@ -63,7 +63,7 @@ public struct NetrcAuthorizationProvider: AuthorizationProvider {
63
63
64
64
public mutating func addOrUpdate( for url: Foundation . URL , user: String , password: String , callback: @escaping ( Result < Void , Error > ) -> Void ) {
65
65
guard let machineName = self . machineName ( for: url) else {
66
- return callback ( . failure( AuthorizationProviderError . noURLHost ) )
66
+ return callback ( . failure( AuthorizationProviderError . invalidURLHost ) )
67
67
}
68
68
let machine = TSCUtility . Netrc. Machine ( name: machineName, login: user, password: password)
69
69
@@ -89,12 +89,12 @@ public struct NetrcAuthorizationProvider: AuthorizationProvider {
89
89
try self . saveToDisk ( machines: machines)
90
90
// At this point the netrc file should exist and non-empty
91
91
guard let netrc = try Self . loadFromDisk ( path: self . path) else {
92
- throw AuthorizationProviderError . unexpectedError ( " Failed to update netrc file at \( self . path) " )
92
+ throw AuthorizationProviderError . other ( " Failed to update netrc file at \( self . path) " )
93
93
}
94
94
self . underlying = netrc
95
95
callback ( . success( ( ) ) )
96
96
} catch {
97
- callback ( . failure( AuthorizationProviderError . unexpectedError ( " Failed to update netrc file at \( self . path) : \( error) " ) ) )
97
+ callback ( . failure( AuthorizationProviderError . other ( " Failed to update netrc file at \( self . path) : \( error) " ) ) )
98
98
}
99
99
}
100
100
@@ -149,10 +149,10 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
149
149
150
150
public func addOrUpdate( for url: Foundation . URL , user: String , password: String , callback: @escaping ( Result < Void , Error > ) -> Void ) {
151
151
guard let server = self . server ( for: url) else {
152
- return callback ( . failure( AuthorizationProviderError . noURLHost ) )
152
+ return callback ( . failure( AuthorizationProviderError . invalidURLHost ) )
153
153
}
154
154
guard let passwordData = password. data ( using: . utf8) else {
155
- return callback ( . failure( AuthorizationProviderError . unexpectedPasswordData ) )
155
+ return callback ( . failure( AuthorizationProviderError . cannotEncodePassword ) )
156
156
}
157
157
let `protocol` = self . `protocol` ( for: url)
158
158
@@ -181,14 +181,14 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
181
181
let passwordData = existingItem [ kSecValueData as String ] as? Data ,
182
182
let password = String ( data: passwordData, encoding: String . Encoding. utf8) ,
183
183
let account = existingItem [ kSecAttrAccount as String ] as? String else {
184
- throw AuthorizationProviderError . unexpectedError ( " Failed to extract credentials for server \( server) from keychain " )
184
+ throw AuthorizationProviderError . other ( " Failed to extract credentials for server \( server) from keychain " )
185
185
}
186
186
return ( user: account, password: password)
187
187
} catch {
188
188
switch error {
189
189
case AuthorizationProviderError . notFound:
190
190
ObservabilitySystem . topScope. emit ( info: " No credentials found for server \( server) in keychain " )
191
- case AuthorizationProviderError . unexpectedError ( let detail) :
191
+ case AuthorizationProviderError . other ( let detail) :
192
192
ObservabilitySystem . topScope. emit ( error: detail)
193
193
default :
194
194
ObservabilitySystem . topScope. emit ( error: " Failed to find credentials for server \( server) in keychain: \( error) " )
@@ -206,7 +206,7 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
206
206
207
207
let status = SecItemAdd ( query as CFDictionary , nil )
208
208
guard status == errSecSuccess else {
209
- throw AuthorizationProviderError . unexpectedError ( " Failed to save credentials for server \( server) to keychain: status \( status) " )
209
+ throw AuthorizationProviderError . other ( " Failed to save credentials for server \( server) to keychain: status \( status) " )
210
210
}
211
211
}
212
212
@@ -222,7 +222,7 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
222
222
throw AuthorizationProviderError . notFound
223
223
}
224
224
guard status == errSecSuccess else {
225
- throw AuthorizationProviderError . unexpectedError ( " Failed to update credentials for server \( server) in keychain: status \( status) " )
225
+ throw AuthorizationProviderError . other ( " Failed to update credentials for server \( server) in keychain: status \( status) " )
226
226
}
227
227
}
228
228
@@ -241,7 +241,7 @@ public struct KeychainAuthorizationProvider: AuthorizationProvider {
241
241
throw AuthorizationProviderError . notFound
242
242
}
243
243
guard status == errSecSuccess else {
244
- throw AuthorizationProviderError . unexpectedError ( " Failed to find credentials for server \( server) in keychain: status \( status) " )
244
+ throw AuthorizationProviderError . other ( " Failed to find credentials for server \( server) in keychain: status \( status) " )
245
245
}
246
246
247
247
return item
0 commit comments