diff options
author | Alex Auvolat <alex@adnab.me> | 2021-10-26 10:20:05 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-10-26 10:20:05 +0200 |
commit | ada7899b24cacb4f95ee67ae92ddb73c04ee4d66 (patch) | |
tree | e42c200cd5eb9e9190232d4340f5be27f302342c /src/api | |
parent | b2c51844a1dccf229473ce0c27fdb02a433ac243 (diff) | |
download | garage-ada7899b24cacb4f95ee67ae92ddb73c04ee4d66.tar.gz garage-ada7899b24cacb4f95ee67ae92ddb73c04ee4d66.zip |
Fix clippy lints (fix #121)
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/api_server.rs | 35 | ||||
-rw-r--r-- | src/api/s3_delete.rs | 5 | ||||
-rw-r--r-- | src/api/s3_get.rs | 10 | ||||
-rw-r--r-- | src/api/s3_put.rs | 10 | ||||
-rw-r--r-- | src/api/signature.rs | 4 |
5 files changed, 31 insertions, 33 deletions
diff --git a/src/api/api_server.rs b/src/api/api_server.rs index 52031ae0..d51b5a28 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -39,7 +39,7 @@ pub async fn run_api_server( } }); - let server = Server::bind(&addr).serve(service); + let server = Server::bind(addr).serve(service); let graceful = server.with_graceful_shutdown(shutdown_signal); info!("API server listening on http://{}", addr); @@ -88,8 +88,8 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon let (bucket, key) = parse_bucket_key(&path)?; let allowed = match req.method() { - &Method::HEAD | &Method::GET => api_key.allow_read(&bucket), - _ => api_key.allow_write(&bucket), + &Method::HEAD | &Method::GET => api_key.allow_read(bucket), + _ => api_key.allow_write(bucket), }; if !allowed { return Err(Error::Forbidden( @@ -109,11 +109,11 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon match *req.method() { Method::HEAD => { // HeadObject query - Ok(handle_head(garage, &req, &bucket, &key).await?) + Ok(handle_head(garage, &req, bucket, key).await?) } Method::GET => { // GetObject query - Ok(handle_get(garage, &req, &bucket, &key).await?) + Ok(handle_get(garage, &req, bucket, key).await?) } Method::PUT => { if params.contains_key(&"partnumber".to_string()) @@ -125,8 +125,8 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon Ok(handle_put_part( garage, req, - &bucket, - &key, + bucket, + key, part_number, upload_id, content_sha256, @@ -136,46 +136,43 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon // CopyObject query let copy_source = req.headers().get("x-amz-copy-source").unwrap().to_str()?; let copy_source = - percent_encoding::percent_decode_str(©_source).decode_utf8()?; + percent_encoding::percent_decode_str(copy_source).decode_utf8()?; let (source_bucket, source_key) = parse_bucket_key(©_source)?; - if !api_key.allow_read(&source_bucket) { + if !api_key.allow_read(source_bucket) { return Err(Error::Forbidden(format!( "Reading from bucket {} not allowed for this key", source_bucket ))); } let source_key = source_key.ok_or_bad_request("No source key specified")?; - Ok( - handle_copy(garage, &req, &bucket, &key, &source_bucket, &source_key) - .await?, - ) + Ok(handle_copy(garage, &req, bucket, key, source_bucket, source_key).await?) } else { // PutObject query - Ok(handle_put(garage, req, &bucket, &key, content_sha256).await?) + Ok(handle_put(garage, req, bucket, key, content_sha256).await?) } } Method::DELETE => { if params.contains_key(&"uploadid".to_string()) { // AbortMultipartUpload query let upload_id = params.get("uploadid").unwrap(); - Ok(handle_abort_multipart_upload(garage, &bucket, &key, upload_id).await?) + Ok(handle_abort_multipart_upload(garage, bucket, key, upload_id).await?) } else { // DeleteObject query - Ok(handle_delete(garage, &bucket, &key).await?) + Ok(handle_delete(garage, bucket, key).await?) } } Method::POST => { if params.contains_key(&"uploads".to_string()) { // CreateMultipartUpload call - Ok(handle_create_multipart_upload(garage, &req, &bucket, &key).await?) + Ok(handle_create_multipart_upload(garage, &req, bucket, key).await?) } 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, + bucket, + key, upload_id, content_sha256, ) diff --git a/src/api/s3_delete.rs b/src/api/s3_delete.rs index efe325ae..425f86d7 100644 --- a/src/api/s3_delete.rs +++ b/src/api/s3_delete.rs @@ -55,7 +55,8 @@ async fn handle_delete_internal( ); garage.object_table.insert(&object).await?; - return Ok((deleted_version, version_uuid)); + + Ok((deleted_version, version_uuid)) } pub async fn handle_delete( @@ -82,7 +83,7 @@ pub async fn handle_delete_objects( let body = hyper::body::to_bytes(req.into_body()).await?; verify_signed_content(content_sha256, &body[..])?; - let cmd_xml = roxmltree::Document::parse(&std::str::from_utf8(&body)?)?; + let cmd_xml = roxmltree::Document::parse(std::str::from_utf8(&body)?)?; let cmd = parse_delete_objects_xml(&cmd_xml).ok_or_bad_request("Invalid delete XML query")?; let mut ret_deleted = Vec::new(); diff --git a/src/api/s3_get.rs b/src/api/s3_get.rs index b804d8ee..10d6591f 100644 --- a/src/api/s3_get.rs +++ b/src/api/s3_get.rs @@ -106,12 +106,12 @@ pub async fn handle_head( _ => unreachable!(), }; - if let Some(cached) = try_answer_cached(&version, version_meta, req) { + if let Some(cached) = try_answer_cached(version, version_meta, req) { return Ok(cached); } let body: Body = Body::empty(); - let response = object_headers(&version, version_meta) + let response = object_headers(version, version_meta) .header("Content-Length", format!("{}", version_meta.size)) .status(StatusCode::OK) .body(body) @@ -149,7 +149,7 @@ pub async fn handle_get( ObjectVersionData::FirstBlock(meta, _) => meta, }; - if let Some(cached) = try_answer_cached(&last_v, last_v_meta, req) { + if let Some(cached) = try_answer_cached(last_v, last_v_meta, req) { return Ok(cached); } @@ -179,7 +179,7 @@ pub async fn handle_get( .await; } - let resp_builder = object_headers(&last_v, last_v_meta) + let resp_builder = object_headers(last_v, last_v_meta) .header("Content-Length", format!("{}", last_v_meta.size)) .status(StatusCode::OK); @@ -190,7 +190,7 @@ pub async fn handle_get( Ok(resp_builder.body(body)?) } ObjectVersionData::FirstBlock(_, first_block_hash) => { - let read_first_block = garage.block_manager.rpc_get_block(&first_block_hash); + let read_first_block = garage.block_manager.rpc_get_block(first_block_hash); let get_next_blocks = garage.version_table.get(&last_v.uuid, &EmptyKey); let (first_block, version) = futures::try_join!(read_first_block, get_next_blocks)?; diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs index aa285232..5eae3bf5 100644 --- a/src/api/s3_put.rs +++ b/src/api/s3_put.rs @@ -193,8 +193,8 @@ async fn read_and_put_blocks( let mut next_offset = first_block.len(); let mut put_curr_version_block = put_block_meta( - &garage, - &version, + garage, + version, part_number, 0, first_block_hash, @@ -213,8 +213,8 @@ async fn read_and_put_blocks( let block_hash = blake2sum(&block[..]); let block_len = block.len(); put_curr_version_block = put_block_meta( - &garage, - &version, + garage, + version, part_number, next_offset as u64, block_hash, @@ -437,7 +437,7 @@ pub async fn handle_complete_multipart_upload( let body = hyper::body::to_bytes(req.into_body()).await?; verify_signed_content(content_sha256, &body[..])?; - let body_xml = roxmltree::Document::parse(&std::str::from_utf8(&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!( diff --git a/src/api/signature.rs b/src/api/signature.rs index fd7ad33b..53ca2ce5 100644 --- a/src/api/signature.rs +++ b/src/api/signature.rs @@ -70,7 +70,7 @@ pub async fn check_signature( let canonical_request = canonical_request( request.method(), &request.uri().path().to_string(), - &canonical_query_string(&request.uri()), + &canonical_query_string(request.uri()), &headers, &authorization.signed_headers, &authorization.content_sha256, @@ -252,7 +252,7 @@ fn canonical_request( method.as_str(), url_path, canonical_query_string, - &canonical_header_string(&headers, signed_headers), + &canonical_header_string(headers, signed_headers), "", signed_headers, content_sha256, |