Skip to content

Commit 380d526

Browse files
refactor: template with registry auth
1 parent ff15295 commit 380d526

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

  • agent-control/src/agent_type/runtime_config/on_host

agent-control/src/agent_type/runtime_config/on_host/package.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,37 @@ impl Templateable for Oci {
116116
impl Templateable for Auth {
117117
type Output = RegistryAuth;
118118
fn template_with(self, variables: &Variables) -> Result<Self::Output, AgentTypeError> {
119-
let username = self.basic.username.template_with(variables)?;
120-
let password = self.basic.password.template_with(variables)?;
121-
let token = self.bearer.template_with(variables)?;
119+
let username = self
120+
.basic
121+
.username
122+
.template_with(variables)
123+
.map_err(|err| {
124+
AgentTypeError::OCIAuthError(format!("error templating username: {err}"))
125+
})?;
126+
let password =
127+
self.basic.password.template_with(variables).map_err(|_| {
128+
AgentTypeError::OCIAuthError("error templating password".to_string())
129+
})?;
130+
let token = self
131+
.bearer
132+
.template_with(variables)
133+
.map_err(|_| AgentTypeError::OCIAuthError("error templating token".to_string()))?;
122134

123135
match (
124-
!&username.is_empty(),
125-
!&password.is_empty(),
126-
!&token.is_empty(),
136+
&username.is_empty(),
137+
&password.is_empty(),
138+
&token.is_empty(),
127139
) {
128-
(false, false, false) => Ok(RegistryAuth::Anonymous),
129-
(true, true, false) => {
140+
(true, true, true) => Ok(RegistryAuth::Anonymous),
141+
(false, false, true) => {
130142
debug!("Basic auth credentials provided, using basic auth");
131143
Ok(RegistryAuth::Basic(username, password))
132144
}
133-
(false, false, true) => {
145+
(true, true, false) => {
134146
debug!("Bearer token provided, using bearer auth");
135147
Ok(RegistryAuth::Bearer(token))
136148
}
137-
(true, true, true) => Err(AgentTypeError::OCIAuthError(
149+
(false, false, false) => Err(AgentTypeError::OCIAuthError(
138150
"multiple authentication methods provided, only one should be used".to_string(),
139151
)),
140152
(true, false, _) | (false, true, _) => Err(AgentTypeError::OCIAuthError(

0 commit comments

Comments
 (0)