From 3aa3b0c9b5a658264dda8de2b0fbc695494660ce Mon Sep 17 00:00:00 2001 From: bors Date: Thu, 16 Nov 2023 20:22:53 +0000 Subject: [PATCH 1/2] Auto merge of #12985 - Turbo87:fix-1password-account-usage, r=ehuss cargo-credential-1password: Add missing `--account` argument to `op signin` command ### What does this PR try to resolve? Without this the account chooser is shown by the `op signin` command, even though the user has already specified an account via the `--account` command line argument to the `cargo-credential-1password` CLI. Note that the `--vault` in this case does not need to be forwarded to `op`, since it is irrelevant for the `op signin` command. ### How should we test and review this PR? - Have a 1password installation with multiple accounts - Use `global-credential-providers = ["cargo-credential-1password --account my.1password.com"]` in the cargo config file - Run e.g. `cargo publish` - Notice how you are seeing an account switcher even though `--account` was used - Apply this patch and notice that the account switcher is no longer there and the correct account is selected automatically ### Additional information see https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/1password.20credentials.20provider --- credential/cargo-credential-1password/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/credential/cargo-credential-1password/src/main.rs b/credential/cargo-credential-1password/src/main.rs index 921b521456a..321a99c5168 100644 --- a/credential/cargo-credential-1password/src/main.rs +++ b/credential/cargo-credential-1password/src/main.rs @@ -79,6 +79,10 @@ impl OnePasswordKeychain { } let mut cmd = Command::new("op"); cmd.args(["signin", "--raw"]); + if let Some(account) = &self.account { + cmd.arg("--account"); + cmd.arg(account); + } cmd.stdout(Stdio::piped()); let mut child = cmd .spawn() From 8862fd33a092eede4f68e09e7016421c51c34dff Mon Sep 17 00:00:00 2001 From: bors Date: Thu, 16 Nov 2023 19:08:14 +0000 Subject: [PATCH 2/2] Auto merge of #12986 - Turbo87:1password-readme, r=ehuss cargo-credential-1password: Fix README ### What does this PR try to resolve? The README.md file of the cargo-credential-1password package does not match the implemented reality (anymore?). - `--sign-in-address` and `--email` are not actually supported by the implementation - manually calling `op signin` appears to be unnecessary This PR also adds configuration instructions directly to the README.md so that they show up on crates.io. --- Cargo.lock | 2 +- .../cargo-credential-1password/Cargo.toml | 2 +- .../cargo-credential-1password/README.md | 38 +++++++++++++------ .../src/reference/registry-authentication.md | 2 +- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d0c034adf4..318280011e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -314,7 +314,7 @@ dependencies = [ [[package]] name = "cargo-credential-1password" -version = "0.4.1" +version = "0.4.2" dependencies = [ "cargo-credential", "serde", diff --git a/credential/cargo-credential-1password/Cargo.toml b/credential/cargo-credential-1password/Cargo.toml index 24dfdd930ff..9e5b1e63545 100644 --- a/credential/cargo-credential-1password/Cargo.toml +++ b/credential/cargo-credential-1password/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-credential-1password" -version = "0.4.1" +version = "0.4.2" edition.workspace = true license.workspace = true rust-version = "1.70.0" # MSRV:3 diff --git a/credential/cargo-credential-1password/README.md b/credential/cargo-credential-1password/README.md index 3648efe4bda..fc3c9460a56 100644 --- a/credential/cargo-credential-1password/README.md +++ b/credential/cargo-credential-1password/README.md @@ -2,17 +2,31 @@ A Cargo [credential provider] for [1password]. -`cargo-credential-1password` uses the 1password `op` CLI to store the token. You must -install the `op` CLI from the [1password -website](https://1password.com/downloads/command-line/). You must run `op signin` -at least once with the appropriate arguments (such as `op signin my.1password.com user@example.com`), -unless you provide the sign-in-address and email arguments. The master password will be required on each request -unless the appropriate `OP_SESSION` environment variable is set. It supports -the following command-line arguments: -* `--account`: The account shorthand name to use. -* `--vault`: The vault name to use. -* `--sign-in-address`: The sign-in-address, which is a web address such as `my.1password.com`. -* `--email`: The email address to sign in with. +## Usage + +`cargo-credential-1password` uses the 1password `op` CLI to store the token. You +must install the `op` CLI from the [1password +website](https://1password.com/downloads/command-line/). + +Afterward you need to configure `cargo` to use `cargo-credential-1password` as +the credential provider. You can do this by adding something like the following +to your [cargo config file][credential provider]: + +```toml +[registry] +global-credential-providers = ["cargo-credential-1password --account my.1password.com"] +``` + +Finally, run `cargo login` to save your registry token in 1password. + +## CLI Arguments + +`cargo-credential-1password` supports the following command-line arguments: + +* `--account`: The account name to use. For a list of available accounts, + run `op account list`. +* `--vault`: The vault name to use. For a list of available vaults, + run `op vault list`. [1password]: https://1password.com/ -[credential provider]: https://doc.rust-lang.org/nightly/cargo/reference/registry-authentication.html +[credential provider]: https://doc.rust-lang.org/stable/cargo/reference/registry-authentication.html diff --git a/src/doc/src/reference/registry-authentication.md b/src/doc/src/reference/registry-authentication.md index 9f8f7e9796b..f07bf7066a5 100644 --- a/src/doc/src/reference/registry-authentication.md +++ b/src/doc/src/reference/registry-authentication.md @@ -103,7 +103,7 @@ Install the provider with `cargo install cargo-credential-1password` In the config, add to (or create) `registry.global-credential-providers`: ```toml [registry] -global-credential-providers = ["cargo:token", "cargo-credential-1password --email you@example.com"] +global-credential-providers = ["cargo:token", "cargo-credential-1password --account my.1password.com"] ``` The values in `global-credential-providers` are split on spaces into path and command-line arguments. To