From d695d34bdadc73e4597463614780a42860234ee4 Mon Sep 17 00:00:00 2001 From: Saul Paredes <30801614+Redent0r@users.noreply.github.com> Date: Wed, 13 Mar 2024 02:29:27 -0700 Subject: [PATCH] feat: support identity token field for auth config (#14) Signed-off-by: Saul Paredes --- src/config.rs | 19 +++++++++++++++++++ src/lib.rs | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/config.rs b/src/config.rs index 7da9b79..7e4c9bd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,6 +6,7 @@ use std::io::Read; #[derive(Deserialize)] pub(crate) struct AuthConfig { pub(crate) auth: Option, + pub(crate) identitytoken: Option, } #[derive(Deserialize)] @@ -35,6 +36,24 @@ impl DockerConfig { None } + pub fn get_identity_token(&self, image_registry: &str) -> Option<&String> { + if let Some(auths) = &self.auths { + if let Some(auth_config) = auths.get(image_registry) { + return auth_config.identitytoken.as_ref(); + } + + let image_registry = normalize_registry(image_registry); + if let Some((_, auth_config)) = auths + .iter() + .find(|(key, _)| normalize_key_to_registry(key) == image_registry) + { + return auth_config.identitytoken.as_ref(); + } + } + + None + } + pub fn get_helper(&self, server: &str) -> Option<&String> { self.cred_helpers .as_ref() diff --git a/src/lib.rs b/src/lib.rs index 9e6f246..356fea1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,6 +103,10 @@ where return from_helper(server, helper_name); } + if let Some(identity_token) = conf.get_identity_token(server) { + return Ok(DockerCredential::IdentityToken(identity_token.to_string())); + } + if let Some(auth) = conf.get_auth(server) { return decode_auth(auth); } @@ -231,6 +235,7 @@ mod tests { String::from("some server"), config::AuthConfig { auth: Some(encoded_auth), + identitytoken: None, }, ); let auth_config = config::DockerConfig { @@ -266,6 +271,7 @@ mod tests { String::from("some server"), config::AuthConfig { auth: Some(encoded_auth), + identitytoken: None, }, )]);