credential: rename cargo:basic to cargo:token-from-stdout

This commit is contained in:
Arlo Siemsen 2023-08-15 23:56:11 -05:00
parent 93e1aa2ea1
commit 1065f213e3
4 changed files with 16 additions and 10 deletions

View File

@ -448,7 +448,7 @@ fn credential_action(
let provider: Box<dyn Credential> = match process { let provider: Box<dyn Credential> = match process {
"cargo:token" => Box::new(TokenCredential::new(config)), "cargo:token" => Box::new(TokenCredential::new(config)),
"cargo:paseto" => Box::new(PasetoCredential::new(config)), "cargo:paseto" => Box::new(PasetoCredential::new(config)),
"cargo:basic" => Box::new(BasicProcessCredential {}), "cargo:token-from-stdout" => Box::new(BasicProcessCredential {}),
"cargo:1password" => Box::new(cargo_credential_1password::OnePasswordCredential {}), "cargo:1password" => Box::new(cargo_credential_1password::OnePasswordCredential {}),
"cargo:wincred" => Box::new(cargo_credential_wincred::WindowsCredential {}), "cargo:wincred" => Box::new(cargo_credential_wincred::WindowsCredential {}),
"cargo:macos-keychain" => Box::new(cargo_credential_macos_keychain::MacKeychain {}), "cargo:macos-keychain" => Box::new(cargo_credential_macos_keychain::MacKeychain {}),

View File

@ -23,7 +23,7 @@ impl Credential for BasicProcessCredential {
Action::Get(_) => { Action::Get(_) => {
let mut args = args.iter(); let mut args = args.iter();
let exe = args.next() let exe = args.next()
.ok_or("The first argument to the `cargo:basic` adaptor must be the path to the credential provider executable.")?; .ok_or("The first argument to `cargo:token-from-stdout` must be a command that prints a token on stdout")?;
let args = args.map(|arg| arg.replace("{index_url}", registry.index_url)); let args = args.map(|arg| arg.replace("{index_url}", registry.index_url));
let mut cmd = Command::new(exe); let mut cmd = Command::new(exe);

View File

@ -1094,9 +1094,9 @@ executed within the Cargo process. They are identified with the `cargo:` prefix.
* `cargo:token` - Uses Cargo's config and `credentials.toml` to store the token (default). * `cargo:token` - Uses Cargo's config and `credentials.toml` to store the token (default).
* `cargo:wincred` - Uses the Windows Credential Manager to store the token. * `cargo:wincred` - Uses the Windows Credential Manager to store the token.
* `cargo:macos-keychain` - Uses the macOS Keychain to store the token. * `cargo:macos-keychain` - Uses the macOS Keychain to store the token.
* `cargo:basic` - A basic authenticator is a process that returns a token on stdout. Newlines * `cargo:token-from-stdout <command>` - Launch a subprocess that returns a token
will be trimmed. The process inherits the user's stdin and stderr. It should on stdout. Newlines will be trimmed. The process inherits the user's stdin and stderr.
exit 0 on success, and nonzero on error. It should exit 0 on success, and nonzero on error.
With this form, [`cargo login`] and [`cargo logout`] are not supported and With this form, [`cargo login`] and [`cargo logout`] are not supported and
return an error if used. return an error if used.

View File

@ -148,7 +148,7 @@ fn basic_unsupported() {
// Non-action commands don't support login/logout. // Non-action commands don't support login/logout.
let registry = registry::RegistryBuilder::new() let registry = registry::RegistryBuilder::new()
.no_configure_token() .no_configure_token()
.credential_provider(&["cargo:basic", "false"]) .credential_provider(&["cargo:token-from-stdout", "false"])
.build(); .build();
cargo_process("login -Z credential-process abcdefg") cargo_process("login -Z credential-process abcdefg")
@ -158,7 +158,7 @@ fn basic_unsupported() {
.with_stderr( .with_stderr(
"\ "\
[UPDATING] crates.io index [UPDATING] crates.io index
[ERROR] credential provider `cargo:basic false` failed action `login` [ERROR] credential provider `cargo:token-from-stdout false` failed action `login`
Caused by: Caused by:
requested operation not supported requested operation not supported
@ -172,7 +172,7 @@ Caused by:
.with_status(101) .with_status(101)
.with_stderr( .with_stderr(
"\ "\
[ERROR] credential provider `cargo:basic false` failed action `logout` [ERROR] credential provider `cargo:token-from-stdout false` failed action `logout`
Caused by: Caused by:
requested operation not supported requested operation not supported
@ -262,7 +262,10 @@ fn invalid_token_output() {
cred_proj.cargo("build").run(); cred_proj.cargo("build").run();
let _server = registry::RegistryBuilder::new() let _server = registry::RegistryBuilder::new()
.alternative() .alternative()
.credential_provider(&["cargo:basic", &toml_bin(&cred_proj, "test-cred")]) .credential_provider(&[
"cargo:token-from-stdout",
&toml_bin(&cred_proj, "test-cred"),
])
.no_configure_token() .no_configure_token()
.build(); .build();
@ -523,7 +526,10 @@ fn basic_provider() {
let _server = registry::RegistryBuilder::new() let _server = registry::RegistryBuilder::new()
.no_configure_token() .no_configure_token()
.credential_provider(&["cargo:basic", &toml_bin(&cred_proj, "test-cred")]) .credential_provider(&[
"cargo:token-from-stdout",
&toml_bin(&cred_proj, "test-cred"),
])
.token(cargo_test_support::registry::Token::Plaintext( .token(cargo_test_support::registry::Token::Plaintext(
"sekrit".to_string(), "sekrit".to_string(),
)) ))