Skip to content

Commit b0bf846

Browse files
committed
add Secret<T> to CredentialCacheValue
1 parent e69a18e commit b0bf846

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/cargo/util/auth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ pub fn cache_token(config: &Config, sid: &SourceId, token: &str) {
384384
CredentialCacheValue {
385385
from_commandline: true,
386386
independent_of_endpoint: true,
387-
token_value: token.to_string(),
387+
token_value: Secret::from(token.to_string()),
388388
},
389389
);
390390
}
@@ -425,7 +425,7 @@ fn auth_token_optional(
425425
|| cache_token_value.independent_of_endpoint
426426
|| mutation.is_none()
427427
{
428-
return Ok(Some(cache_token_value.token_value.clone()));
428+
return Ok(Some(cache_token_value.token_value.clone().expose()));
429429
}
430430
}
431431

@@ -518,7 +518,7 @@ fn auth_token_optional(
518518
CredentialCacheValue {
519519
from_commandline: false,
520520
independent_of_endpoint,
521-
token_value: token.to_string(),
521+
token_value: Secret::from(token.to_string()),
522522
},
523523
);
524524
}

src/cargo/util/config/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use crate::core::compiler::rustdoc::RustdocExternMap;
7070
use crate::core::shell::Verbosity;
7171
use crate::core::{features, CliUnstable, Shell, SourceId, Workspace, WorkspaceRootConfig};
7272
use crate::ops::{self, RegistryCredentialConfig};
73+
use crate::util::auth::Secret;
7374
use crate::util::errors::CargoResult;
7475
use crate::util::validate_package_name;
7576
use crate::util::CanonicalUrl;
@@ -137,24 +138,15 @@ enum WhyLoad {
137138
}
138139

139140
/// A previously generated authentication token and the data needed to determine if it can be reused.
141+
#[derive(Debug)]
140142
pub struct CredentialCacheValue {
141143
/// If the command line was used to override the token then it must always be reused,
142144
/// even if reading the configuration files would lead to a different value.
143145
pub from_commandline: bool,
144146
/// If nothing depends on which endpoint is being hit, then we can reuse the token
145147
/// for any future request even if some of the requests involve mutations.
146148
pub independent_of_endpoint: bool,
147-
pub token_value: String,
148-
}
149-
150-
impl fmt::Debug for CredentialCacheValue {
151-
/// This manual implementation helps ensure that the token value is redacted from all logs.
152-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153-
f.debug_struct("CredentialCacheValue")
154-
.field("from_commandline", &self.from_commandline)
155-
.field("token_value", &"REDACTED")
156-
.finish()
157-
}
149+
pub token_value: Secret<String>,
158150
}
159151

160152
/// Configuration information for cargo. This is not specific to a build, it is information

0 commit comments

Comments
 (0)