Skip to content

Commit b8099be

Browse files
committed
fix: make more credential JSON fields skip_serializing if None
1 parent 5a856bf commit b8099be

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

credential/cargo-credential/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub struct CredentialRequest<'a> {
8080
#[serde(borrow, flatten)]
8181
pub action: Action<'a>,
8282
/// Additional command-line arguments passed to the credential provider.
83+
#[serde(skip_serializing_if = "Vec::is_empty", default)]
8384
pub args: Vec<&'a str>,
8485
}
8586

@@ -90,6 +91,7 @@ pub struct RegistryInfo<'a> {
9091
pub index_url: &'a str,
9192
/// Name of the registry in configuration. May not be available.
9293
/// The crates.io registry will be `crates-io` (`CRATES_IO_REGISTRY`).
94+
#[serde(skip_serializing_if = "Option::is_none")]
9395
pub name: Option<&'a str>,
9496
/// Headers from attempting to access a registry that resulted in a HTTP 401.
9597
#[serde(skip_serializing_if = "Vec::is_empty", default)]
@@ -123,8 +125,10 @@ impl<'a> Display for Action<'a> {
123125
#[serde(rename_all = "kebab-case")]
124126
pub struct LoginOptions<'a> {
125127
/// Token passed on the command line via --token or from stdin
128+
#[serde(skip_serializing_if = "Option::is_none")]
126129
pub token: Option<Secret<&'a str>>,
127130
/// Optional URL that the user can visit to log in to the registry
131+
#[serde(skip_serializing_if = "Option::is_none")]
128132
pub login_url: Option<&'a str>,
129133
}
130134

tests/testsuite/credential_process.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ fn publish() {
129129
.masquerade_as_nightly_cargo(&["credential-process"])
130130
.with_stderr(
131131
r#"[UPDATING] [..]
132-
{"v":1,"registry":{"index-url":"[..]","name":"alternative","headers":[..]},"kind":"get","operation":"read","args":[]}
132+
{"v":1,"registry":{"index-url":"[..]","name":"alternative","headers":[..]},"kind":"get","operation":"read"}
133133
[PACKAGING] foo v0.1.0 [..]
134134
[PACKAGED] [..]
135-
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.0","cksum":"[..]","args":[]}
135+
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.0","cksum":"[..]"}
136136
[UPLOADING] foo v0.1.0 [..]
137137
[UPLOADED] foo v0.1.0 [..]
138138
note: Waiting [..]
@@ -217,7 +217,7 @@ fn logout() {
217217
.masquerade_as_nightly_cargo(&["credential-process"])
218218
.replace_crates_io(server.index_url())
219219
.with_stderr(
220-
r#"{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"logout","args":[]}
220+
r#"{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"logout"}
221221
"#,
222222
)
223223
.run();
@@ -231,8 +231,8 @@ fn yank() {
231231
.masquerade_as_nightly_cargo(&["credential-process"])
232232
.with_stderr(
233233
r#"[UPDATING] [..]
234-
{"v":1,"registry":{"index-url":"[..]","name":"alternative","headers":[..]},"kind":"get","operation":"read","args":[]}
235-
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"yank","name":"foo","vers":"0.1.0","args":[]}
234+
{"v":1,"registry":{"index-url":"[..]","name":"alternative","headers":[..]},"kind":"get","operation":"read"}
235+
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"yank","name":"foo","vers":"0.1.0"}
236236
237237
"#,
238238
)
@@ -247,8 +247,8 @@ fn owner() {
247247
.masquerade_as_nightly_cargo(&["credential-process"])
248248
.with_stderr(
249249
r#"[UPDATING] [..]
250-
{"v":1,"registry":{"index-url":"[..]","name":"alternative","headers":[..]},"kind":"get","operation":"read","args":[]}
251-
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"owners","name":"foo","args":[]}
250+
{"v":1,"registry":{"index-url":"[..]","name":"alternative","headers":[..]},"kind":"get","operation":"read"}
251+
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"owners","name":"foo"}
252252
[OWNER] completed!
253253
"#,
254254
)
@@ -349,7 +349,7 @@ fn all_not_found() {
349349
.with_stderr(
350350
r#"[UPDATING] [..]
351351
[CREDENTIAL] [..]not_found[..] get crates-io
352-
{"v":1,"registry":{"index-url":"[..]","name":"crates-io","headers":[[..]"WWW-Authenticate: Cargo login_url=\"https://test-registry-login/me\""[..]]},"kind":"get","operation":"read","args":[]}
352+
{"v":1,"registry":{"index-url":"[..]","name":"crates-io","headers":[[..]"WWW-Authenticate: Cargo login_url=\"https://test-registry-login/me\""[..]]},"kind":"get","operation":"read"}
353353
[ERROR] failed to query replaced source registry `crates-io`
354354
355355
Caused by:
@@ -390,7 +390,7 @@ fn all_not_supported() {
390390
.with_stderr(
391391
r#"[UPDATING] [..]
392392
[CREDENTIAL] [..]not_supported[..] get crates-io
393-
{"v":1,"registry":{"index-url":"[..]","name":"crates-io","headers":[[..]"WWW-Authenticate: Cargo login_url=\"https://test-registry-login/me\""[..]]},"kind":"get","operation":"read","args":[]}
393+
{"v":1,"registry":{"index-url":"[..]","name":"crates-io","headers":[[..]"WWW-Authenticate: Cargo login_url=\"https://test-registry-login/me\""[..]]},"kind":"get","operation":"read"}
394394
[ERROR] failed to query replaced source registry `crates-io`
395395
396396
Caused by:
@@ -437,9 +437,9 @@ fn multiple_providers() {
437437
.with_stderr(
438438
r#"[UPDATING] [..]
439439
[CREDENTIAL] [..]url_not_supported[..] login crates-io
440-
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg","login-url":"[..]","args":[]}
440+
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg","login-url":"[..]"}
441441
[CREDENTIAL] [..]success_provider[..] login crates-io
442-
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg","login-url":"[..]","args":[]}
442+
{"v":1,"registry":{"index-url":"https://github.com/rust-lang/crates.io-index","name":"crates-io"},"kind":"login","token":"abcdefg","login-url":"[..]"}
443443
"#,
444444
)
445445
.run();
@@ -557,10 +557,10 @@ fn token_caching() {
557557
.build();
558558

559559
let output = r#"[UPDATING] `alternative` index
560-
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"read","args":[]}
560+
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"read"}
561561
[PACKAGING] foo v0.1.0 [..]
562562
[PACKAGED] [..]
563-
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.0","cksum":"[..]","args":[]}
563+
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.0","cksum":"[..]"}
564564
[UPLOADING] foo v0.1.0 [..]
565565
[UPLOADED] foo v0.1.0 [..]
566566
note: Waiting [..]

0 commit comments

Comments
 (0)