From cb19bbef2276abf1fd4de59be40040fc8abe9ba8 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 2 Jul 2025 12:14:22 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9AApply=20suggestions=20from=20clippy?= =?UTF-8?q?=201.88=20(#20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/signer/src/request_signature_streaming.rs | 2 +- crates/signer/src/request_signature_v2.rs | 6 +++--- crates/signer/src/request_signature_v4.rs | 13 +++++-------- ecstore/src/disk/os.rs | 2 +- rustfs/src/admin/handlers/event.rs | 10 +++++----- rustfs/src/admin/handlers/tier.rs | 8 ++++---- rustfs/src/update_checker.rs | 16 +++++++--------- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/crates/signer/src/request_signature_streaming.rs b/crates/signer/src/request_signature_streaming.rs index b280e074..a96796ba 100644 --- a/crates/signer/src/request_signature_streaming.rs +++ b/crates/signer/src/request_signature_streaming.rs @@ -87,7 +87,7 @@ pub fn streaming_sign_v4( headers.insert("X-Amz-Date", HeaderValue::from_str(&req_time.format(&format).unwrap()).expect("err")); //req.content_length = 100; - headers.insert("x-amz-decoded-content-length", format!("{:010}", data_len).parse().unwrap()); + headers.insert("x-amz-decoded-content-length", format!("{data_len:010}").parse().unwrap()); req } diff --git a/crates/signer/src/request_signature_v2.rs b/crates/signer/src/request_signature_v2.rs index 58569763..04a647f6 100644 --- a/crates/signer/src/request_signature_v2.rs +++ b/crates/signer/src/request_signature_v2.rs @@ -35,7 +35,7 @@ pub fn pre_sign_v2( let headers = req.headers_mut().expect("headers_mut err"); let expires_str = headers.get("Expires"); if expires_str.is_none() { - headers.insert("Expires", format!("{:010}", epoch_expires).parse().unwrap()); + headers.insert("Expires", format!("{epoch_expires:010}").parse().unwrap()); } let string_to_sign = pre_string_to_sign_v2(&req, virtual_host); @@ -49,7 +49,7 @@ pub fn pre_sign_v2( query.insert("AWSAccessKeyId".to_string(), access_key_id.to_string()); } - query.insert("Expires".to_string(), format!("{:010}", epoch_expires)); + query.insert("Expires".to_string(), format!("{epoch_expires:010}")); let uri = req.uri_ref().unwrap().clone(); let mut parts = req.uri_ref().unwrap().clone().into_parts(); @@ -95,7 +95,7 @@ pub fn sign_v2( ); } - let auth_header = format!("{} {}:", SIGN_V2_ALGORITHM, access_key_id); + let auth_header = format!("{SIGN_V2_ALGORITHM} {access_key_id}:"); let auth_header = format!("{}{}", auth_header, base64_encode(&hmac_sha1(secret_access_key, string_to_sign))); headers.insert("Authorization", auth_header.parse().unwrap()); diff --git a/crates/signer/src/request_signature_v4.rs b/crates/signer/src/request_signature_v4.rs index b27d3499..e3ef97e2 100644 --- a/crates/signer/src/request_signature_v4.rs +++ b/crates/signer/src/request_signature_v4.rs @@ -166,7 +166,7 @@ fn get_canonical_request(req: &request::Builder, ignored_headers: &HashMap = query_params.iter().map(|(k, v)| format!("{}={}", k, v)).collect(); + let sorted_params: Vec = query_params.iter().map(|(k, v)| format!("{k}={v}")).collect(); canonical_query_string = sorted_params.join("&"); canonical_query_string = canonical_query_string.replace("+", "%20"); @@ -219,7 +219,7 @@ pub fn pre_sign_v4( query.push(("X-Amz-Algorithm".to_string(), SIGN_V4_ALGORITHM.to_string())); let format = format_description!("[year][month][day]T[hour][minute][second]Z"); query.push(("X-Amz-Date".to_string(), t.format(&format).unwrap().to_string())); - query.push(("X-Amz-Expires".to_string(), format!("{:010}", expires))); + query.push(("X-Amz-Expires".to_string(), format!("{expires:010}"))); query.push(("X-Amz-SignedHeaders".to_string(), signed_headers)); query.push(("X-Amz-Credential".to_string(), credential)); if !session_token.is_empty() { @@ -300,7 +300,7 @@ fn sign_v4_inner( } headers.insert("Content-Encoding", "aws-chunked".parse().unwrap()); - headers.insert("x-amz-decoded-content-length", format!("{:010}", content_len).parse().unwrap()); + headers.insert("x-amz-decoded-content-length", format!("{content_len:010}").parse().unwrap()); } if service_type == SERVICE_TYPE_STS { @@ -318,10 +318,7 @@ fn sign_v4_inner( let headers = req.headers_mut().expect("err"); - let auth = format!( - "{} Credential={}, SignedHeaders={}, Signature={}", - SIGN_V4_ALGORITHM, credential, signed_headers, signature - ); + let auth = format!("{SIGN_V4_ALGORITHM} Credential={credential}, SignedHeaders={signed_headers}, Signature={signature}"); headers.insert("Authorization", auth.parse().unwrap()); if !trailer.is_empty() { @@ -350,7 +347,7 @@ fn _unsigned_trailer(mut req: request::Builder, content_len: i64, trailer: Heade } headers.insert("Content-Encoding", "aws-chunked".parse().unwrap()); - headers.insert("x-amz-decoded-content-length", format!("{:010}", content_len).parse().unwrap()); + headers.insert("x-amz-decoded-content-length", format!("{content_len:010}").parse().unwrap()); if !trailer.is_empty() { for (_, v) in &trailer { diff --git a/ecstore/src/disk/os.rs b/ecstore/src/disk/os.rs index 67df445b..37f583d0 100644 --- a/ecstore/src/disk/os.rs +++ b/ecstore/src/disk/os.rs @@ -91,7 +91,7 @@ pub async fn read_dir(path: impl AsRef, count: i32) -> std::io::Result = version.split('.').collect(); if parts.len() < 3 { - return Err(UpdateCheckError::VersionParseError(format!("Invalid version format: {}", version))); + return Err(UpdateCheckError::VersionParseError(format!("Invalid version format: {version}"))); } let major = parts[0] @@ -292,7 +290,7 @@ mod tests { async fn test_get_current_version() { let version = get_current_version(); assert!(!version.is_empty()); - println!("Current version: {}", version); + println!("Current version: {version}"); } #[test] @@ -341,7 +339,7 @@ mod tests { assert_eq!(cloned_result.check_time, result.check_time); // Test Debug functionality (should not panic) - let debug_output = format!("{:?}", result); + let debug_output = format!("{result:?}"); assert!(debug_output.contains("UpdateCheckResult")); assert!(debug_output.contains("1.1.0")); assert!(debug_output.contains("1.2.0")); @@ -403,7 +401,7 @@ mod tests { assert_eq!(cloned_info.download_url, version_info.download_url); // Test Debug functionality - let debug_output = format!("{:?}", version_info); + let debug_output = format!("{version_info:?}"); assert!(debug_output.contains("VersionInfo")); assert!(debug_output.contains("2.0.0")); @@ -422,7 +420,7 @@ mod tests { // Test JSON serialization/deserialization let json_string = serde_json::to_string(&version_info).unwrap(); - println!("json_string: {}", json_string); + println!("json_string: {json_string}"); assert!(json_string.contains("2.0.0")); assert!(json_string.contains("Major release"));