From 5fdabf3e75ba16b5ceed99edb1912cb001765d03 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 14 May 2021 22:33:26 +0200 Subject: [PATCH] Add basic support for the "Versioning" command --- src/api/api_server.rs | 3 +++ src/api/s3_bucket.rs | 13 +++++++++++++ src/api/s3_xml.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/api/api_server.rs b/src/api/api_server.rs index 40862eb72..52031ae05 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -221,6 +221,9 @@ async fn handler_inner(garage: Arc, req: Request) -> Result) -> Result, .body(Body::from(xml.into_bytes()))?) } +pub fn handle_get_bucket_versioning() -> Result, Error> { + let versioning = s3_xml::VersioningConfiguration { + xmlns: (), + status: None, + }; + + let xml = s3_xml::to_xml_with_header(&versioning)?; + + Ok(Response::builder() + .header("Content-Type", "application/xml") + .body(Body::from(xml.into_bytes()))?) +} + pub fn handle_list_buckets(api_key: &Key) -> Result, Error> { let list_buckets = s3_xml::ListAllMyBucketsResult { owner: s3_xml::Owner { diff --git a/src/api/s3_xml.rs b/src/api/s3_xml.rs index ba9b90831..f05479613 100644 --- a/src/api/s3_xml.rs +++ b/src/api/s3_xml.rs @@ -195,6 +195,14 @@ pub struct ListBucketResult { pub common_prefixes: Vec, } +#[derive(Debug, Serialize, PartialEq)] +pub struct VersioningConfiguration { + #[serde(serialize_with = "xmlns_tag")] + pub xmlns: (), + #[serde(rename = "Status")] + pub status: Option, +} + #[cfg(test)] mod tests { use super::*; @@ -279,6 +287,30 @@ mod tests { Ok(()) } + #[test] + fn get_bucket_versioning_result() -> Result<(), ApiError> { + let get_bucket_versioning = VersioningConfiguration { + xmlns: (), + status: None, + }; + assert_eq!( + to_xml_with_header(&get_bucket_versioning)?, + "\ +" + ); + let get_bucket_versioning2 = VersioningConfiguration { + xmlns: (), + status: Some(Value("Suspended".to_string())), + }; + assert_eq!( + to_xml_with_header(&get_bucket_versioning2)?, + "\ +Suspended" + ); + + Ok(()) + } + #[test] fn delete_result() -> Result<(), ApiError> { let delete_result = DeleteResult {