diff options
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/api_server.rs | 11 | ||||
-rw-r--r-- | src/api/s3_copy.rs | 4 | ||||
-rw-r--r-- | src/api/s3_delete.rs | 4 | ||||
-rw-r--r-- | src/api/s3_list.rs | 18 | ||||
-rw-r--r-- | src/api/s3_put.rs | 31 | ||||
-rw-r--r-- | src/api/signature.rs | 7 |
6 files changed, 54 insertions, 21 deletions
diff --git a/src/api/api_server.rs b/src/api/api_server.rs index c3e205ab..c6b1d483 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -160,10 +160,15 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon } else if params.contains_key(&"uploadid".to_string()) { // CompleteMultipartUpload call let upload_id = params.get("uploadid").unwrap(); - Ok( - handle_complete_multipart_upload(garage, req, &bucket, &key, upload_id, content_sha256) - .await?, + Ok(handle_complete_multipart_upload( + garage, + req, + &bucket, + &key, + upload_id, + content_sha256, ) + .await?) } else { Err(Error::BadRequest(format!( "Not a CreateMultipartUpload call, what is it?" diff --git a/src/api/s3_copy.rs b/src/api/s3_copy.rs index d764f7a8..b6ec48b0 100644 --- a/src/api/s3_copy.rs +++ b/src/api/s3_copy.rs @@ -104,6 +104,6 @@ pub async fn handle_copy( writeln!(&mut xml, "</CopyObjectResult>").unwrap(); Ok(Response::builder() - .header("Content-Type", "application/xml") - .body(Body::from(xml.into_bytes()))?) + .header("Content-Type", "application/xml") + .body(Body::from(xml.into_bytes()))?) } diff --git a/src/api/s3_delete.rs b/src/api/s3_delete.rs index 91cfbfbe..4b6a2b18 100644 --- a/src/api/s3_delete.rs +++ b/src/api/s3_delete.rs @@ -123,8 +123,8 @@ pub async fn handle_delete_objects( writeln!(&mut retxml, "</DeleteObjectsOutput>").unwrap(); Ok(Response::builder() - .header("Content-Type", "application/xml") - .body(Body::from(retxml.into_bytes()))?) + .header("Content-Type", "application/xml") + .body(Body::from(retxml.into_bytes()))?) } struct DeleteRequest { diff --git a/src/api/s3_list.rs b/src/api/s3_list.rs index 2be47091..98d774db 100644 --- a/src/api/s3_list.rs +++ b/src/api/s3_list.rs @@ -229,10 +229,20 @@ pub async fn handle_list( } else { // TODO: are these supposed to be urlencoded when encoding-type is URL?? if let Some(mkr) = &query.marker { - writeln!(&mut xml, "\t<Marker>{}</Marker>", xml_encode_key(mkr, query.urlencode_resp)).unwrap(); + writeln!( + &mut xml, + "\t<Marker>{}</Marker>", + xml_encode_key(mkr, query.urlencode_resp) + ) + .unwrap(); } if let Some(next_marker) = truncated { - writeln!(&mut xml, "\t<NextMarker>{}</NextMarker>", xml_encode_key(&next_marker, query.urlencode_resp)).unwrap(); + writeln!( + &mut xml, + "\t<NextMarker>{}</NextMarker>", + xml_encode_key(&next_marker, query.urlencode_resp) + ) + .unwrap(); } } @@ -272,6 +282,6 @@ pub async fn handle_list( debug!("{}", xml); Ok(Response::builder() - .header("Content-Type", "application/xml") - .body(Body::from(xml.into_bytes()))?) + .header("Content-Type", "application/xml") + .body(Body::from(xml.into_bytes()))?) } diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs index 969b4098..ec599a05 100644 --- a/src/api/s3_put.rs +++ b/src/api/s3_put.rs @@ -17,8 +17,8 @@ use garage_model::garage::Garage; use garage_model::object_table::*; use garage_model::version_table::*; -use crate::error::*; use crate::encoding::*; +use crate::error::*; use crate::signature::verify_signed_content; pub async fn handle_put( @@ -427,8 +427,12 @@ pub async fn handle_complete_multipart_upload( verify_signed_content(content_sha256, &body[..])?; let body_xml = roxmltree::Document::parse(&std::str::from_utf8(&body)?)?; - let body_list_of_parts = parse_complete_multpart_upload_body(&body_xml).ok_or_bad_request("Invalid CompleteMultipartUpload XML")?; - debug!("CompleteMultipartUpload list of parts: {:?}", body_list_of_parts); + let body_list_of_parts = parse_complete_multpart_upload_body(&body_xml) + .ok_or_bad_request("Invalid CompleteMultipartUpload XML")?; + debug!( + "CompleteMultipartUpload list of parts: {:?}", + body_list_of_parts + ); let version_uuid = decode_upload_id(upload_id)?; @@ -461,10 +465,16 @@ pub async fn handle_complete_multipart_upload( // Check that the list of parts they gave us corresponds to the parts we have here // TODO: check MD5 sum of all uploaded parts? but that would mean we have to store them somewhere... - let mut parts = version.blocks().iter().map(|x| x.part_number) + let mut parts = version + .blocks() + .iter() + .map(|x| x.part_number) .collect::<Vec<_>>(); parts.dedup(); - let same_parts = body_list_of_parts.iter().map(|x| &x.part_number).eq(parts.iter()); + let same_parts = body_list_of_parts + .iter() + .map(|x| &x.part_number) + .eq(parts.iter()); if !same_parts { return Err(Error::BadRequest(format!("We don't have the same parts"))); } @@ -604,7 +614,9 @@ struct CompleteMultipartUploadPart { part_number: u64, } -fn parse_complete_multpart_upload_body(xml: &roxmltree::Document) -> Option<Vec<CompleteMultipartUploadPart>> { +fn parse_complete_multpart_upload_body( + xml: &roxmltree::Document, +) -> Option<Vec<CompleteMultipartUploadPart>> { let mut parts = vec![]; let root = xml.root(); @@ -616,8 +628,11 @@ fn parse_complete_multpart_upload_body(xml: &roxmltree::Document) -> Option<Vec< for item in cmu.children() { if item.has_tag_name("Part") { let etag = item.children().find(|e| e.has_tag_name("ETag"))?.text()?; - let part_number = item.children().find(|e| e.has_tag_name("PartNumber"))?.text()?; - parts.push(CompleteMultipartUploadPart{ + let part_number = item + .children() + .find(|e| e.has_tag_name("PartNumber"))? + .text()?; + parts.push(CompleteMultipartUploadPart { etag: etag.trim_matches('"').to_string(), part_number: part_number.parse().ok()?, }); diff --git a/src/api/signature.rs b/src/api/signature.rs index b6350634..d7fbd3f7 100644 --- a/src/api/signature.rs +++ b/src/api/signature.rs @@ -295,9 +295,12 @@ fn canonical_query_string(uri: &hyper::Uri) -> String { } pub fn verify_signed_content(content_sha256: Option<Hash>, body: &[u8]) -> Result<(), Error> { - let expected_sha256 = content_sha256.ok_or_bad_request("Request content hash not signed, aborting.")?; + let expected_sha256 = + content_sha256.ok_or_bad_request("Request content hash not signed, aborting.")?; if expected_sha256 != sha256sum(body) { - return Err(Error::BadRequest(format!("Request content hash does not match signed hash"))); + return Err(Error::BadRequest(format!( + "Request content hash does not match signed hash" + ))); } Ok(()) } |