mirror of
https://git.deuxfleurs.fr/Deuxfleurs/garage.git
synced 2024-11-25 09:31:00 +00:00
Add basic support for the "Versioning" command
This commit is contained in:
parent
6ccffc3162
commit
5fdabf3e75
3 changed files with 48 additions and 0 deletions
|
@ -221,6 +221,9 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon
|
||||||
if params.contains_key("location") {
|
if params.contains_key("location") {
|
||||||
// GetBucketLocation call
|
// GetBucketLocation call
|
||||||
Ok(handle_get_bucket_location(garage)?)
|
Ok(handle_get_bucket_location(garage)?)
|
||||||
|
} else if params.contains_key("versioning") {
|
||||||
|
// GetBucketVersioning
|
||||||
|
Ok(handle_get_bucket_versioning()?)
|
||||||
} else {
|
} else {
|
||||||
// ListObjects or ListObjectsV2 query
|
// ListObjects or ListObjectsV2 query
|
||||||
let q = parse_list_objects_query(bucket, ¶ms)?;
|
let q = parse_list_objects_query(bucket, ¶ms)?;
|
||||||
|
|
|
@ -21,6 +21,19 @@ pub fn handle_get_bucket_location(garage: Arc<Garage>) -> Result<Response<Body>,
|
||||||
.body(Body::from(xml.into_bytes()))?)
|
.body(Body::from(xml.into_bytes()))?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_get_bucket_versioning() -> Result<Response<Body>, 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<Response<Body>, Error> {
|
pub fn handle_list_buckets(api_key: &Key) -> Result<Response<Body>, Error> {
|
||||||
let list_buckets = s3_xml::ListAllMyBucketsResult {
|
let list_buckets = s3_xml::ListAllMyBucketsResult {
|
||||||
owner: s3_xml::Owner {
|
owner: s3_xml::Owner {
|
||||||
|
|
|
@ -195,6 +195,14 @@ pub struct ListBucketResult {
|
||||||
pub common_prefixes: Vec<CommonPrefix>,
|
pub common_prefixes: Vec<CommonPrefix>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, PartialEq)]
|
||||||
|
pub struct VersioningConfiguration {
|
||||||
|
#[serde(serialize_with = "xmlns_tag")]
|
||||||
|
pub xmlns: (),
|
||||||
|
#[serde(rename = "Status")]
|
||||||
|
pub status: Option<Value>,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -279,6 +287,30 @@ mod tests {
|
||||||
Ok(())
|
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)?,
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
||||||
|
<VersioningConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>"
|
||||||
|
);
|
||||||
|
let get_bucket_versioning2 = VersioningConfiguration {
|
||||||
|
xmlns: (),
|
||||||
|
status: Some(Value("Suspended".to_string())),
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
to_xml_with_header(&get_bucket_versioning2)?,
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
||||||
|
<VersioningConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Status>Suspended</Status></VersioningConfiguration>"
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn delete_result() -> Result<(), ApiError> {
|
fn delete_result() -> Result<(), ApiError> {
|
||||||
let delete_result = DeleteResult {
|
let delete_result = DeleteResult {
|
||||||
|
|
Loading…
Reference in a new issue