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

Fix overwriting alternate registry token #7708

Merged
merged 6 commits into from
Dec 17, 2019

Conversation

giraffate
Copy link
Contributor

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

Fixes #7701.

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

Fixes rust-lang#7701.
@rust-highfive
Copy link

r? @ehuss

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 13, 2019
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I think it would be best to avoid creating a second registry unconditionally in all tests, since it affects hundreds of tests (creating thousands of extra files). Perhaps some changes like this:

  • Move the code for creating a registry into a separate function (so it is not repeated 3 times).
  • Instead of adding "alt2" functions, add functions with a parameter (like registry_path(name)), and have the existing functions call that instead.
  • Change registry_credentials so that is the only place where the second registry is created. It can modify the .cargo/config file with the [registries] definitions as needed.

@giraffate
Copy link
Contributor Author

Thank you for reviewing!

As you say, it seems better to avoid creating a second registry in the other tests, so I fix it. Could you review this again?

I will squashed these commits at the end.

Comment on lines 69 to 72
fn generate_dl_url(name: &str) -> String {
let base = Url::from_file_path(generate_path(name)).ok().unwrap();
format!("{}/{{crate}}/{{version}}/{{crate}}-{{version}}.crate", base)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can all the other functions (the alt_* functions) be changed to call these new functions instead of duplicating the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I fixed it like that. I also corrected registry_path function etc., but is this OK?

Comment on lines 180 to 182

[registries.alternative2]
index = '{alt2}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best to not set this here, and only set it in the registry_credentials test. Can probably just append to the config file.

@@ -214,6 +229,23 @@ pub fn init() {
fs::create_dir_all(alt_api_path().join("api/v1/crates")).unwrap();
}

pub fn init_alt2_registry() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be written so that the other two registries reuse the same code instead of duplicating it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced this with a new function init_registry and the existing codes for creating registry call the new function. I am a little worried that there are many arguments for this new function, but I couldn't come up with another good way to write it.

Comment on lines 195 to 196
.arg("-Zunstable-options")
.masquerade_as_nightly_cargo()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines can be removed, I think we just forgot to remove them when stabilized. And remove the same 2 lines in the call above.

@ehuss
Copy link
Contributor

ehuss commented Dec 17, 2019

Looks good to me, thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Dec 17, 2019

📌 Commit b7bc069 has been approved by ehuss

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 17, 2019
@bors
Copy link
Contributor

bors commented Dec 17, 2019

⌛ Testing commit b7bc069 with merge fc29c9c...

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

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

Fixes #7701.
@bors
Copy link
Contributor

bors commented Dec 17, 2019

☀️ Test successful - checks-azure
Approved by: ehuss
Pushing fc29c9c to master...

@bors bors merged commit b7bc069 into rust-lang:master Dec 17, 2019
@giraffate giraffate deleted the fix_overwriting_credentials branch December 18, 2019 00:20
@ehuss ehuss added this to the 1.42.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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