Skip to content

[5.9] Add token-file option to 'package-registry login' #6593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/PackageRegistryTool/PackageRegistryTool+Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ extension SwiftPackageRegistryTool {
@Option(help: "Access token")
var token: String?

@Option(
name: .customLong("token-file"),
help: "Path to the file containing access token"
)
var tokenFilePath: AbsolutePath?

@Flag(help: "Allow writing to netrc file without confirmation")
var noConfirm: Bool = false

Expand Down Expand Up @@ -144,6 +150,10 @@ extension SwiftPackageRegistryTool {
if let token = self.token {
// User provided token
storePassword = token
} else if let tokenFilePath {
print("Reading access token from \(tokenFilePath).")
storePassword = try localFileSystem.readFileContents(tokenFilePath)
.trimmingCharacters(in: .whitespacesAndNewlines)
} else if let stored = authorizationProvider.authentication(for: registryURL),
stored.user == storeUsername
{
Expand Down