Skip to content

Commit

Permalink
feat: support identity token field for auth config (#14)
Browse files Browse the repository at this point in the history
Signed-off-by: Saul Paredes <saulparedes@microsoft.com>
  • Loading branch information
Redent0r committed Mar 13, 2024
1 parent b79d3fc commit d695d34
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::io::Read;
#[derive(Deserialize)]
pub(crate) struct AuthConfig {
pub(crate) auth: Option<String>,
pub(crate) identitytoken: Option<String>,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -231,6 +235,7 @@ mod tests {
String::from("some server"),
config::AuthConfig {
auth: Some(encoded_auth),
identitytoken: None,
},
);
let auth_config = config::DockerConfig {
Expand Down Expand Up @@ -266,6 +271,7 @@ mod tests {
String::from("some server"),
config::AuthConfig {
auth: Some(encoded_auth),
identitytoken: None,
},
)]);

Expand Down

0 comments on commit d695d34

Please sign in to comment.