Skip to content

Commit 80f8908

Browse files
authored
Merge pull request #176 from itowlson/docker-credential-does-not-play-nice-with-schemeful-urls
Use registry host rather than URL for creds lookup
2 parents 5b80fab + 46acd2d commit 80f8908

File tree

1 file changed

+37
-24
lines changed
  • crates/wasm-pkg-client/src/oci

1 file changed

+37
-24
lines changed

crates/wasm-pkg-client/src/oci/mod.rs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,17 @@ impl OciBackend {
112112
));
113113
}
114114

115-
let server_url = format!("https://{}", self.oci_registry);
116-
match docker_credential::get_credential(&server_url) {
117-
Ok(DockerCredential::UsernamePassword(username, password)) => {
118-
return Ok(RegistryAuth::Basic(username, password));
119-
}
120-
Ok(DockerCredential::IdentityToken(_)) => {
121-
return Err(Error::CredentialError(anyhow::anyhow!(
122-
"identity tokens not supported"
123-
)));
124-
}
125-
Err(err) => {
126-
if matches!(
127-
err,
128-
CredentialRetrievalError::ConfigNotFound
129-
| CredentialRetrievalError::ConfigReadError
130-
| CredentialRetrievalError::NoCredentialConfigured
131-
| CredentialRetrievalError::HelperFailure { .. }
132-
) {
133-
tracing::debug!("Failed to look up OCI credentials: {err}");
134-
} else {
135-
tracing::warn!("Failed to look up OCI credentials: {err}");
136-
};
115+
match get_docker_credential(&self.oci_registry)? {
116+
Some(c) => Ok(c),
117+
None => {
118+
tracing::debug!("Failed to look up OCI credentials by registry, trying server URL");
119+
let server_url = format!("https://{}", self.oci_registry);
120+
match get_docker_credential(&server_url)? {
121+
Some(c) => Ok(c),
122+
None => Ok(RegistryAuth::Anonymous),
123+
}
137124
}
138125
}
139-
140-
Ok(RegistryAuth::Anonymous)
141126
}
142127

143128
pub(crate) fn make_reference(
@@ -165,3 +150,31 @@ pub(crate) fn oci_registry_error(err: OciDistributionError) -> Error {
165150
_ => Error::RegistryError(err.into()),
166151
}
167152
}
153+
154+
fn get_docker_credential(registry: &str) -> Result<Option<RegistryAuth>, Error> {
155+
match docker_credential::get_credential(registry) {
156+
Ok(DockerCredential::UsernamePassword(username, password)) => {
157+
return Ok(Some(RegistryAuth::Basic(username, password)));
158+
}
159+
Ok(DockerCredential::IdentityToken(_)) => {
160+
return Err(Error::CredentialError(anyhow::anyhow!(
161+
"identity tokens not supported"
162+
)));
163+
}
164+
Err(err) => {
165+
if matches!(
166+
err,
167+
CredentialRetrievalError::ConfigNotFound
168+
| CredentialRetrievalError::ConfigReadError
169+
| CredentialRetrievalError::NoCredentialConfigured
170+
| CredentialRetrievalError::HelperFailure { .. }
171+
) {
172+
tracing::debug!("Failed to look up OCI credentials: {err}");
173+
} else {
174+
tracing::warn!("Failed to look up OCI credentials: {err}");
175+
};
176+
}
177+
}
178+
179+
Ok(None)
180+
}

0 commit comments

Comments
 (0)