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

Bump secrecy to 0.10 #1588

Merged
merged 4 commits into from
Sep 24, 2024
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ rand = "0.8.3"
rustls = { version = "0.23.0", default-features = false }
rustls-pemfile = "2.0.0"
schemars = "0.8.6"
secrecy = "0.8.0"
secrecy = "0.10.2"
serde = "1.0.130"
serde_json = "1.0.68"
serde-value = "0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion kube-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ tower-http = { workspace = true, features = ["auth", "map-response-body", "trace
hyper-timeout = { workspace = true, optional = true }
tame-oauth = { workspace = true, features = ["gcp"], optional = true }
rand = { workspace = true, optional = true }
secrecy = { workspace = true, features = ["alloc", "serde"] }
secrecy = { workspace = true }
tracing = { workspace = true, features = ["log"], optional = true }
hyper-openssl = { workspace = true, features = ["client-legacy"], optional = true }
form_urlencoded = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion kube-client/src/client/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl TokenFile {

/// Get the cached token. Returns `None` if it's expiring.
fn cached_token(&self) -> Option<&str> {
(!self.is_expiring()).then(|| self.token.expose_secret().as_ref())
(!self.is_expiring()).then(|| self.token.expose_secret())
}

/// Get a token. Reloads from file if the cached token is expiring.
Expand Down
6 changes: 3 additions & 3 deletions kube-client/src/client/auth/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
/// Retrieve the ID token. If the stored ID token is or will soon be expired, try refreshing it first.
pub async fn id_token(&mut self) -> Result<String, errors::Error> {
if self.token_valid()? {
return Ok(self.id_token.expose_secret().clone());
return Ok(self.id_token.expose_secret().to_string());

Check warning on line 190 in kube-client/src/client/auth/oidc.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/auth/oidc.rs#L190

Added line #L190 was not covered by tests
}

let id_token = self.refresher.as_mut().map_err(|e| e.clone())?.id_token().await?;
Expand Down Expand Up @@ -394,8 +394,8 @@
}
AuthStyle::Params => {
params.extend([
("client_id", self.client_id.expose_secret().as_str()),
("client_secret", self.client_secret.expose_secret().as_str()),
("client_id", self.client_id.expose_secret()),
("client_secret", self.client_secret.expose_secret()),

Check warning on line 398 in kube-client/src/client/auth/oidc.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/auth/oidc.rs#L397-L398

Added lines #L397 - L398 were not covered by tests
]);
}
};
Expand Down
20 changes: 8 additions & 12 deletions kube-client/src/config/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ where
D: Deserializer<'de>,
{
match Option::<String>::deserialize(deserializer) {
Ok(Some(secret)) => Ok(Some(SecretString::new(secret))),
Ok(Some(secret)) => Ok(Some(SecretString::new(secret.into()))),
Ok(None) => Ok(None),
Err(e) => Err(e),
}
Expand Down Expand Up @@ -533,10 +533,7 @@ impl AuthInfo {
// TODO Shouldn't error when `self.client_key_data.is_none() && self.client_key.is_none()`

load_from_base64_or_file(
&self
.client_key_data
.as_ref()
.map(|secret| secret.expose_secret().as_str()),
&self.client_key_data.as_ref().map(|secret| secret.expose_secret()),
&self.client_key,
)
.map_err(KubeconfigError::LoadClientKey)
Expand Down Expand Up @@ -664,7 +661,6 @@ mod tests {

use super::*;
use serde_json::{json, Value};
use std::str::FromStr;

#[test]
fn kubeconfig_merge() {
Expand All @@ -673,7 +669,7 @@ mod tests {
auth_infos: vec![NamedAuthInfo {
name: "red-user".into(),
auth_info: Some(AuthInfo {
token: Some(SecretString::from_str("first-token").unwrap()),
token: Some(SecretString::new("first-token".into())),
..Default::default()
}),
}],
Expand All @@ -685,15 +681,15 @@ mod tests {
NamedAuthInfo {
name: "red-user".into(),
auth_info: Some(AuthInfo {
token: Some(SecretString::from_str("second-token").unwrap()),
token: Some(SecretString::new("second-token".into())),
username: Some("red-user".into()),
..Default::default()
}),
},
NamedAuthInfo {
name: "green-user".into(),
auth_info: Some(AuthInfo {
token: Some(SecretString::from_str("new-token").unwrap()),
token: Some(SecretString::new("new-token".into())),
..Default::default()
}),
},
Expand All @@ -713,8 +709,8 @@ mod tests {
.unwrap()
.token
.as_ref()
.map(|t| t.expose_secret().to_string()),
Some("first-token".to_string())
.map(|t| t.expose_secret()),
Some("first-token")
);
// Even if it's not conflicting
assert_eq!(merged.auth_infos[0].auth_info.as_ref().unwrap().username, None);
Expand Down Expand Up @@ -910,7 +906,7 @@ password: kube_rs
let authinfo_debug_output = format!("{authinfo:?}");
let expected_output = "AuthInfo { \
username: Some(\"user\"), \
password: Some(Secret([REDACTED alloc::string::String])), \
password: Some(SecretBox<str>([REDACTED])), \
token: None, token_file: None, client_certificate: None, \
client_certificate_data: None, client_key: None, \
client_key_data: None, impersonate: None, \
Expand Down
Loading