-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Hello!.
Maybe, in the validate_registry_response function, there is a non-compliance with the https://github.com/opencontainers/distribution-spec/blob/main/spec.md#errors-2 standard.
Firstly the returned format may not be json ( ...A 4XX response code from the registry MAY return a body in any format....). Secondly some registries return their own code, for example Harbor v2.9.0 returns this error: r#"{"errors":[{"code": "NOT_FOUND", "message": "artifact image:0.0.1 not found"}]}]}"#.
It may be more correct to use the following variant of the validate_registry_response function:
fn validate_registry_response(status: reqwest::StatusCode, body: &[u8], url: &str) -> Result<()> {
debug!(STATUS=?status);
match status {
reqwest::StatusCode::OK => Ok(()),
reqwest::StatusCode::UNAUTHORIZED => Err(OciDistributionError::UnauthorizedError {
url: url.to_string(),
}),
s if s.is_success() => Err(OciDistributionError::SpecViolationError(format!(
"Expected HTTP Status {}, got {} instead",
reqwest::StatusCode::OK,
status,
))),
s if s.is_client_error() => {
let text = std::str::from_utf8(body)?;
// According to the OCI spec, we should see an error in the message body.
match serde_json::from_str::<OciEnvelope>(text) {
Ok(envelope) => Err(OciDistributionError::RegistryError {
envelope,
url: url.to_string(),
}),
Err(err) => {
debug!(err=?err,"Not valid json format of RegistryError (https://github.com/opencontainers/distribution-spec/blob/master/spec.md#errors-2)");
Err(OciDistributionError::ServerError {
code: s.as_u16(),
url: url.to_string(),
message: text.to_string(),
})
}
}
}
s => {
let text = std::str::from_utf8(body)?;
Err(OciDistributionError::ServerError {
code: s.as_u16(),
url: url.to_string(),
message: text.to_string(),
})
}
}
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working