mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-04 03:47:42 +00:00
Many S3 compatibility improvements:
- return XML errors - implement AuthorizationHeaderMalformed error to redirect clients to correct location (used by minio client) - implement GetBucketLocation - fix DeleteObjects XML parsing and response
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
use std::fmt::Write;
|
||||
|
||||
use err_derive::Error;
|
||||
use hyper::StatusCode;
|
||||
|
||||
use garage_util::error::Error as GarageError;
|
||||
|
||||
use crate::encoding::*;
|
||||
|
||||
/// Errors of this crate
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
@@ -24,6 +28,10 @@ pub enum Error {
|
||||
#[error(display = "Forbidden: {}", _0)]
|
||||
Forbidden(String),
|
||||
|
||||
/// Authorization Header Malformed
|
||||
#[error(display = "Authorization header malformed, expected scope: {}", _0)]
|
||||
AuthorizationHeaderMalformed(String),
|
||||
|
||||
/// The object requested don't exists
|
||||
#[error(display = "Not found")]
|
||||
NotFound,
|
||||
@@ -77,6 +85,29 @@ impl Error {
|
||||
_ => StatusCode::BAD_REQUEST,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn aws_code(&self) -> &'static str {
|
||||
match self {
|
||||
Error::NotFound => "NoSuchKey",
|
||||
Error::Forbidden(_) => "AccessDenied",
|
||||
Error::AuthorizationHeaderMalformed(_) => "AuthorizationHeaderMalformed",
|
||||
Error::InternalError(GarageError::RPC(_)) => "ServiceUnavailable",
|
||||
Error::InternalError(_) | Error::Hyper(_) | Error::HTTP(_) => "InternalError",
|
||||
_ => "InvalidRequest",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn aws_xml(&self, garage_region: &str, path: &str) -> String {
|
||||
let mut xml = String::new();
|
||||
writeln!(&mut xml, r#"<?xml version="1.0" encoding="UTF-8"?>"#).unwrap();
|
||||
writeln!(&mut xml, "<Error>").unwrap();
|
||||
writeln!(&mut xml, "\t<Code>{}</Code>", self.aws_code()).unwrap();
|
||||
writeln!(&mut xml, "\t<Message>{}</Message>", self).unwrap();
|
||||
writeln!(&mut xml, "\t<Resource>{}</Resource>", xml_escape(path)).unwrap();
|
||||
writeln!(&mut xml, "\t<Region>{}</Region>", garage_region).unwrap();
|
||||
writeln!(&mut xml, "</Error>").unwrap();
|
||||
xml
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait to map error to the Bad Request error code
|
||||
|
||||
Reference in New Issue
Block a user