Skip to content

Commit

Permalink
Credential provider implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosi authored and Arlo committed Jul 18, 2023
1 parent 1b15556 commit 3b8e2c0
Show file tree
Hide file tree
Showing 47 changed files with 2,087 additions and 1,808 deletions.
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 @@ -87,7 +90,7 @@ syn = { version = "2.0.14", features = ["extra-traits", "full"] }
tar = { version = "0.4.38", default-features = false }
tempfile = "3.1.0"
termcolor = "1.1.2"
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 @@ -118,6 +121,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

0 comments on commit 3b8e2c0

Please sign in to comment.