Skip to content
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

cargo login with 2nd alternate registry overwrites 1st alternate registry's token in ~/.cargo/credentials #7701

Closed
carols10cents opened this issue Dec 12, 2019 · 1 comment · Fixed by #7708
Labels
A-registries Area: registries C-bug Category: bug Command-login

Comments

@carols10cents
Copy link
Member

Problem

When working on crates.io, I often run an instance locally and interact with it through cargo. We also have a staging instance where I test things out. So this is 2 alternate registries in addition to the main crates.io.

My ~/.cargo/config looks like this:

[registries]
staging = { index = "https://github.com/rust-lang/staging.crates.io-index" }
local = { index = "file:///Users/carolnichols/rust/crates.io/tmp/index-bare" }

If I run cargo login --registry staging [token] then run cargo login --registry local [other-token], ~/.cargo/credentials only contains the credentials for the local registry.

Steps

  1. Using rustc 1.39.0 (4560ea788 2019-11-04)/cargo 1.39.0 (1c6ec66 2019-09-30), create a ~/.cargo/config containing 2 alternate registries as shown above.

  2. Move your existing ~/.cargo/credentials file elsewhere if you don't want to mess it up reproducing this.

  3. Run cargo login abcde to set your token for the main crates.io registry.

  4. Observe that ~/.cargo/credentials contains these contents, as expected:

[registry]
token = "abcde"
  1. Run cargo login --registry staging fghij.
  2. Observe that ~/.cargo/credentials contains these contents, as expected:
[registries.staging]
token = "fghij"

[registry]
token = "abcde"
  1. Run cargo login --registry local klmno.
  2. Observe that ~/.cargo/credentials contains these contents, with local and the main registry present as expected, but with staging gone:
[registries.local]
token = "klmno"

[registry]
token = "abcde"

The contents I expected to have would contain tokens for all 3 registries, like:

[registries.local]
token = "klmno"

[registries.staging]
token = "fghij"

[registry]
token = "abcde"

Possible Solution(s)

Unclear, I was going to go poking around after filing this.

Notes

Output of cargo version: cargo 1.39.0 (1c6ec66d5 2019-09-30), current stable on macOS.

I was also able to reproduce with rustc 1.41.0-nightly (27d6f55f4 2019-12-11)/cargo 1.41.0-nightly (626f0f40e 2019-12-03).

@carols10cents carols10cents added C-bug Category: bug Command-login A-registries Area: registries labels Dec 12, 2019
@giraffate
Copy link
Contributor

When registries is set for key,

(
"registries".into(),
CV::Table(map, file.path().to_path_buf()),
)

it seems to overwrite value here.
toml.as_table_mut().unwrap().insert(key, value.into_toml());

When key registries has the value, it seems better to fix to merge the original value with the new value, but what about?

bors added a commit that referenced this issue Dec 17, 2019
Fix overwriting alternate registry token

When executing `cargo login`, 2nd alternate registry token overwrites
1st alternate registry token.

Fixes #7701.
@bors bors closed this as completed in 6cbde6e Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-registries Area: registries C-bug Category: bug Command-login
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants