Skip to content

Commit 7371cf4

Browse files
committed
Move CompositeAuthorizationProvider to SwiftTool
1 parent d728e49 commit 7371cf4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

Sources/Basics/AuthorizationProvider.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,10 @@ public struct CompositeAuthorizationProvider: AuthorizationProvider {
269269
switch provider {
270270
case let provider as NetrcAuthorizationProvider:
271271
ObservabilitySystem.topScope.emit(info: "Credentials for \(url) found in netrc file at \(provider.path)")
272+
#if canImport(Security)
272273
case is KeychainAuthorizationProvider:
273274
ObservabilitySystem.topScope.emit(info: "Credentials for \(url) found in keychain")
275+
#endif
274276
default:
275277
ObservabilitySystem.topScope.emit(info: "Credentials for \(url) found in \(provider)")
276278
}

Sources/Commands/SwiftTool.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,16 @@ public class SwiftTool {
493493
}
494494

495495
func getAuthorizationProvider() throws -> AuthorizationProvider? {
496-
// currently only single provider: netrc
497-
return try self.getNetrcConfig()?.get()
496+
var providers = [AuthorizationProvider]()
497+
// netrc file has higher specificity than keychain so use it first
498+
if let workspaceNetrc = try self.getNetrcConfig()?.get() {
499+
providers.append(workspaceNetrc)
500+
}
501+
#if canImport(Security)
502+
providers.append(KeychainAuthorizationProvider())
503+
#endif
504+
return CompositeAuthorizationProvider(providers)
505+
498506
}
499507

500508
func getNetrcConfig() -> Workspace.Configuration.Netrc? {

Sources/Workspace/WorkspaceConfiguration.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,7 @@ extension Workspace.Configuration {
350350
}
351351

352352
private static func load(_ path: AbsolutePath, fileSystem: FileSystem) throws -> AuthorizationProvider {
353-
var providers = [AuthorizationProvider]()
354-
// netrc file has higher specificity than keychain so use it first
355-
providers.append(try NetrcAuthorizationProvider(path: path, fileSystem: fileSystem))
356-
#if canImport(Security)
357-
providers.append(KeychainAuthorizationProvider())
358-
#endif
359-
return CompositeAuthorizationProvider(providers)
353+
try NetrcAuthorizationProvider(path: path, fileSystem: fileSystem)
360354
}
361355
}
362356
}

0 commit comments

Comments
 (0)