Skip to content

Commit

Permalink
Update command output and code comment
Browse files Browse the repository at this point in the history
  • Loading branch information
yim-lee committed Nov 2, 2022
1 parent 8fe8cc8 commit f69fee1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Sources/Commands/SwiftPackageRegistryTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
private static let PLACEHOLDER_TOKEN_USER = "token"

func run(_ swiftTool: SwiftTool) throws {
// Require HTTPS
guard let url = URL(string: self.url), url.scheme == "https", let host = url.host?.lowercased() else {
throw RegistryConfigurationError.invalidURL(self.url)
}

// We need to be able to read/write credentials
guard let authorizationProvider = try swiftTool.getAuthorizationProvider() else {
throw StringError("No credential storage available")
throw StringError("No credential store available")
}

let authenticationType: RegistryConfiguration.AuthenticationType
Expand All @@ -187,7 +188,7 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
// User provided password
storePassword = password
} else if let stored = authorizationProvider.authentication(for: url), stored.user == storeUsername {
// Password found in credential storage
// Password found in credential store
storePassword = stored.password
saveChanges = false
} else {
Expand All @@ -203,7 +204,7 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
// User provided token
storePassword = token
} else if let stored = authorizationProvider.authentication(for: url), stored.user == storeUsername {
// Token found in credential storage
// Token found in credential store
storePassword = stored.password
saveChanges = false
} else {
Expand All @@ -214,7 +215,7 @@ public struct SwiftPackageRegistryTool: ParsableCommand {

let authorizationWriter = authorizationProvider as? AuthorizationWriter
if saveChanges, authorizationWriter == nil {
throw StringError("Credential storage must be writable")
throw StringError("Credential store must be writable")
}

// Save in cache so we can try the credentials and persist to storage only if login succeeds
Expand All @@ -235,6 +236,7 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
loginAPIPath = url.path
}

// Require HTTPS
guard let loginURL = URL(string: "https://\(host)\(loginAPIPath ?? "/#")") else {
throw RegistryConfigurationError.invalidURL(self.url)
}
Expand Down Expand Up @@ -273,7 +275,7 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
if !osStore, !self.noConfirm {
print("""
WARNING: Secure credential storage is not supported on this platform.
WARNING: Secure credential store is not supported on this platform.
Your credentials will be written out to .netrc.
""")
print("Continue? (Y/N): ")
Expand Down Expand Up @@ -301,7 +303,7 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
}
}

// Update global registry configuration file
// Update user-level registry configuration file
let update: (inout RegistryConfiguration) throws -> Void = { configuration in
configuration.registryAuthentication[host] = .init(type: authenticationType, loginAPIPath: loginAPIPath)
}
Expand All @@ -322,13 +324,14 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
var url: String

func run(_ swiftTool: SwiftTool) throws {
// Require HTTPS
guard let url = URL(string: self.url), url.scheme == "https", let host = url.host?.lowercased() else {
throw RegistryConfigurationError.invalidURL(self.url)
}

// We need to be able to read/write credentials
guard let authorizationProvider = try swiftTool.getAuthorizationProvider() else {
throw StringError("No credential storage available")
throw StringError("No credential store available")
}

let authorizationWriter = authorizationProvider as? AuthorizationWriter
Expand All @@ -339,12 +342,12 @@ public struct SwiftPackageRegistryTool: ParsableCommand {
try tsc_await { callback in authorizationWriter?.remove(for: url, callback: callback) }
print("Credentials have been removed from operating system's secure credential store.")
} else {
print("NOTE: Please remove credentials from .netrc manually.")
print("Credentials have not been removed from .netrc. Please remove credentials from the file manually.")
}

let configuration = try getRegistriesConfig(swiftTool)

// Update global registry configuration file
// Update user-level registry configuration file
let update: (inout RegistryConfiguration) throws -> Void = { configuration in
configuration.registryAuthentication.removeValue(forKey: host)
}
Expand Down

0 comments on commit f69fee1

Please # to comment.