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

credential provider implementation #12334

Merged
merged 2 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
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
19 changes: 14 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ anyhow = "1.0.47"
base64 = "0.21.0"
bytesize = "1.0"
cargo = { path = "" }
cargo-credential = { version = "0.2.0", path = "credential/cargo-credential" }
cargo-credential = { version = "0.3.0", path = "credential/cargo-credential" }
cargo-credential-1password = { version = "0.3.0", path = "credential/cargo-credential-1password" }
cargo-credential-wincred = { version = "0.3.0", path = "credential/cargo-credential-wincred" }
cargo-credential-macos-keychain = { version = "0.3.0", path = "credential/cargo-credential-macos-keychain" }
cargo-platform = { path = "crates/cargo-platform", version = "0.1.4" }
cargo-test-macro = { path = "crates/cargo-test-macro" }
cargo-test-support = { path = "crates/cargo-test-support" }
Expand Down Expand Up @@ -88,7 +91,7 @@ tar = { version = "0.4.38", default-features = false }
tempfile = "3.1.0"
termcolor = "1.1.2"
thiserror = "1.0.40"
time = { version = "0.3", features = ["parsing", "formatting"] }
time = { version = "0.3", features = ["parsing", "formatting", "serde"] }
toml = "0.7.0"
toml_edit = "0.19.0"
unicode-width = "0.1.5"
Expand Down Expand Up @@ -119,6 +122,10 @@ anyhow.workspace = true
base64.workspace = true
bytesize.workspace = true
cargo-platform.workspace = true
cargo-credential.workspace = true
cargo-credential-1password.workspace = true
cargo-credential-macos-keychain.workspace = true
cargo-credential-wincred.workspace = true
cargo-util.workspace = true
clap = { workspace = true, features = ["wrap_help"] }
crates-io.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ fn substitute_macros(input: &str) -> String {
("[CHECKING]", " Checking"),
("[COMPLETED]", " Completed"),
("[CREATED]", " Created"),
("[CREDENTIAL]", " Credential"),
("[DOWNGRADING]", " Downgrading"),
("[FINISHED]", " Finished"),
("[ERROR]", "error:"),
Expand Down
36 changes: 36 additions & 0 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub struct RegistryBuilder {
not_found_handler: RequestCallback,
/// If nonzero, the git index update to be delayed by the given number of seconds.
delayed_index_update: usize,
/// Credential provider in configuration
credential_provider: Option<String>,
}

pub struct TestRegistry {
Expand Down Expand Up @@ -172,6 +174,7 @@ impl RegistryBuilder {
custom_responders: HashMap::new(),
not_found_handler: Box::new(not_found),
delayed_index_update: 0,
credential_provider: None,
}
}

Expand Down Expand Up @@ -266,6 +269,13 @@ impl RegistryBuilder {
self
}

/// The credential provider to configure for this registry.
#[must_use]
pub fn credential_provider(mut self, provider: &[&str]) -> Self {
self.credential_provider = Some(format!("['{}']", provider.join("','")));
self
}

/// Initializes the registry.
#[must_use]
pub fn build(self) -> TestRegistry {
Expand Down Expand Up @@ -336,6 +346,18 @@ impl RegistryBuilder {
.as_bytes(),
)
.unwrap();
if let Some(p) = &self.credential_provider {
append(
&config_path,
&format!(
"
credential-provider = {p}
"
)
.as_bytes(),
)
.unwrap()
}
} else {
append(
&config_path,
Expand All @@ -351,6 +373,20 @@ impl RegistryBuilder {
.as_bytes(),
)
.unwrap();

if let Some(p) = &self.credential_provider {
append(
&config_path,
&format!(
"
[registry]
credential-provider = {p}
"
)
.as_bytes(),
)
.unwrap()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion credential/cargo-credential-1password/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-credential-1password"
version = "0.2.0"
version = "0.3.0"
edition.workspace = true
license.workspace = true
repository = "https://github.com/rust-lang/cargo"
Expand Down
Loading