Skip to content

Commit e592978

Browse files
committed
Credential provider implementation
1 parent 1b15556 commit e592978

File tree

47 files changed

+2075
-1808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2075
-1808
lines changed

Cargo.lock

+14-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ anyhow = "1.0.47"
1919
base64 = "0.21.0"
2020
bytesize = "1.0"
2121
cargo = { path = "" }
22-
cargo-credential = { version = "0.2.0", path = "credential/cargo-credential" }
22+
cargo-credential = { version = "0.3.0", path = "credential/cargo-credential" }
23+
cargo-credential-1password = { version = "0.3.0", path = "credential/cargo-credential-1password" }
24+
cargo-credential-wincred = { version = "0.3.0", path = "credential/cargo-credential-wincred" }
25+
cargo-credential-macos-keychain = { version = "0.3.0", path = "credential/cargo-credential-macos-keychain" }
2326
cargo-platform = { path = "crates/cargo-platform", version = "0.1.4" }
2427
cargo-test-macro = { path = "crates/cargo-test-macro" }
2528
cargo-test-support = { path = "crates/cargo-test-support" }
@@ -87,7 +90,7 @@ syn = { version = "2.0.14", features = ["extra-traits", "full"] }
8790
tar = { version = "0.4.38", default-features = false }
8891
tempfile = "3.1.0"
8992
termcolor = "1.1.2"
90-
time = { version = "0.3", features = ["parsing", "formatting"] }
93+
time = { version = "0.3", features = ["parsing", "formatting", "serde"] }
9194
toml = "0.7.0"
9295
toml_edit = "0.19.0"
9396
unicode-width = "0.1.5"
@@ -118,6 +121,10 @@ anyhow.workspace = true
118121
base64.workspace = true
119122
bytesize.workspace = true
120123
cargo-platform.workspace = true
124+
cargo-credential.workspace = true
125+
cargo-credential-1password.workspace = true
126+
cargo-credential-macos-keychain.workspace = true
127+
cargo-credential-wincred.workspace = true
121128
cargo-util.workspace = true
122129
clap = { workspace = true, features = ["wrap_help"] }
123130
crates-io.workspace = true

crates/cargo-test-support/src/compare.rs

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ fn substitute_macros(input: &str) -> String {
192192
("[CHECKING]", " Checking"),
193193
("[COMPLETED]", " Completed"),
194194
("[CREATED]", " Created"),
195+
("[CREDENTIAL]", " Credential"),
195196
("[DOWNGRADING]", " Downgrading"),
196197
("[FINISHED]", " Finished"),
197198
("[ERROR]", "error:"),

crates/cargo-test-support/src/registry.rs

+36
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ pub struct RegistryBuilder {
104104
not_found_handler: RequestCallback,
105105
/// If nonzero, the git index update to be delayed by the given number of seconds.
106106
delayed_index_update: usize,
107+
/// Credential provider in configuration
108+
credential_provider: Option<String>,
107109
}
108110

109111
pub struct TestRegistry {
@@ -172,6 +174,7 @@ impl RegistryBuilder {
172174
custom_responders: HashMap::new(),
173175
not_found_handler: Box::new(not_found),
174176
delayed_index_update: 0,
177+
credential_provider: None,
175178
}
176179
}
177180

@@ -266,6 +269,13 @@ impl RegistryBuilder {
266269
self
267270
}
268271

272+
/// The credential provider to configure for this registry.
273+
#[must_use]
274+
pub fn credential_provider(mut self, provider: &[&str]) -> Self {
275+
self.credential_provider = Some(format!("['{}']", provider.join("','")));
276+
self
277+
}
278+
269279
/// Initializes the registry.
270280
#[must_use]
271281
pub fn build(self) -> TestRegistry {
@@ -336,6 +346,18 @@ impl RegistryBuilder {
336346
.as_bytes(),
337347
)
338348
.unwrap();
349+
if let Some(p) = &self.credential_provider {
350+
append(
351+
&config_path,
352+
&format!(
353+
"
354+
credential-provider = {p}
355+
"
356+
)
357+
.as_bytes(),
358+
)
359+
.unwrap()
360+
}
339361
} else {
340362
append(
341363
&config_path,
@@ -351,6 +373,20 @@ impl RegistryBuilder {
351373
.as_bytes(),
352374
)
353375
.unwrap();
376+
377+
if let Some(p) = &self.credential_provider {
378+
append(
379+
&config_path,
380+
&format!(
381+
"
382+
[registry]
383+
credential-provider = {p}
384+
"
385+
)
386+
.as_bytes(),
387+
)
388+
.unwrap()
389+
}
354390
}
355391
}
356392

credential/cargo-credential-1password/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential-1password"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition.workspace = true
55
license.workspace = true
66
repository = "https://github.com/rust-lang/cargo"

0 commit comments

Comments
 (0)