This is an automated email from the ASF dual-hosted git repository. xuanwo pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git
The following commit(s) were added to refs/heads/main by this push: new 8f89556 chore: Make clippy happy (#633) 8f89556 is described below commit 8f89556e54099497f6797844147d72b288b45ff5 Author: meteorgan <meteorite....@gmail.com> AuthorDate: Mon Sep 22 17:08:46 2025 +0800 chore: Make clippy happy (#633) --- .gitignore | 1 + core/src/time.rs | 2 +- .../aws-v4/src/provide_credential/assume_role.rs | 4 +- .../assume_role_with_web_identity.rs | 22 ++++---- services/aws-v4/src/provide_credential/cognito.rs | 2 +- services/aws-v4/src/provide_credential/ecs.rs | 29 +++++------ services/aws-v4/src/provide_credential/imds.rs | 23 ++++----- services/aws-v4/src/provide_credential/utils.rs | 59 +++++++++++----------- .../google/src/provide_credential/vm_metadata.rs | 5 +- 9 files changed, 69 insertions(+), 78 deletions(-) diff --git a/.gitignore b/.gitignore index 302ff9b..1da474f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ Cargo.lock .env .claude/*.local.json +.idea diff --git a/core/src/time.rs b/core/src/time.rs index e317164..b8cb500 100644 --- a/core/src/time.rs +++ b/core/src/time.rs @@ -107,7 +107,7 @@ pub fn format_rfc3339(t: DateTime) -> String { pub fn parse_rfc3339(s: &str) -> crate::Result<DateTime> { Ok(chrono::DateTime::parse_from_rfc3339(s) .map_err(|err| { - Error::unexpected(format!("parse '{}' into rfc3339 failed", s)).with_source(err) + Error::unexpected(format!("parse '{s}' into rfc3339 failed")).with_source(err) })? .with_timezone(&Utc)) } diff --git a/services/aws-v4/src/provide_credential/assume_role.rs b/services/aws-v4/src/provide_credential/assume_role.rs index 256bf3e..e5ba258 100644 --- a/services/aws-v4/src/provide_credential/assume_role.rs +++ b/services/aws-v4/src/provide_credential/assume_role.rs @@ -190,7 +190,7 @@ impl ProvideCredential for AssumeRoleCredentialProvider { Error::request_invalid("failed to build STS AssumeRole request") .with_source(e) .with_context(format!("role_arn: {}", self.role_arn)) - .with_context(format!("endpoint: https://{}", endpoint)) + .with_context(format!("endpoint: https://{endpoint}")) })?; let (mut parts, body) = req.into_parts(); @@ -201,7 +201,7 @@ impl ProvideCredential for AssumeRoleCredentialProvider { Error::unexpected("failed to send AssumeRole request to STS") .with_source(e) .with_context(format!("role_arn: {}", self.role_arn)) - .with_context(format!("endpoint: https://{}", endpoint)) + .with_context(format!("endpoint: https://{endpoint}")) .set_retryable(true) })?; diff --git a/services/aws-v4/src/provide_credential/assume_role_with_web_identity.rs b/services/aws-v4/src/provide_credential/assume_role_with_web_identity.rs index 7bef29f..7c055d3 100644 --- a/services/aws-v4/src/provide_credential/assume_role_with_web_identity.rs +++ b/services/aws-v4/src/provide_credential/assume_role_with_web_identity.rs @@ -121,7 +121,7 @@ impl ProvideCredential for AssumeRoleWithWebIdentityCredentialProvider { let token = ctx.file_read_as_string(&token_file).await.map_err(|e| { Error::config_invalid("failed to read web identity token file") .with_source(e) - .with_context(format!("file: {}", token_file)) + .with_context(format!("file: {token_file}")) .with_context("hint: check if the token file exists and is readable") })?; @@ -140,7 +140,7 @@ impl ProvideCredential for AssumeRoleWithWebIdentityCredentialProvider { }); let endpoint = sts_endpoint(region.as_deref(), use_regional) - .map_err(|e| e.with_context(format!("role_arn: {}", role_arn)))?; + .map_err(|e| e.with_context(format!("role_arn: {role_arn}")))?; // Get session name from config or environment or use default let session_name = self @@ -163,15 +163,15 @@ impl ProvideCredential for AssumeRoleWithWebIdentityCredentialProvider { .map_err(|e| { Error::request_invalid("failed to build STS AssumeRoleWithWebIdentity request") .with_source(e) - .with_context(format!("role_arn: {}", role_arn)) - .with_context(format!("endpoint: https://{}", endpoint)) + .with_context(format!("role_arn: {role_arn}")) + .with_context(format!("endpoint: https://{endpoint}")) })?; let resp = ctx.http_send_as_string(req).await.map_err(|e| { Error::unexpected("failed to send AssumeRoleWithWebIdentity request to STS") .with_source(e) - .with_context(format!("role_arn: {}", role_arn)) - .with_context(format!("endpoint: https://{}", endpoint)) + .with_context(format!("role_arn: {role_arn}")) + .with_context(format!("endpoint: https://{endpoint}")) .set_retryable(true) })?; @@ -191,9 +191,9 @@ impl ProvideCredential for AssumeRoleWithWebIdentityCredentialProvider { &content, request_id.as_deref(), ) - .with_context(format!("role_arn: {}", role_arn)) - .with_context(format!("session_name: {}", session_name)) - .with_context(format!("token_file: {}", token_file))); + .with_context(format!("role_arn: {role_arn}")) + .with_context(format!("session_name: {session_name}")) + .with_context(format!("token_file: {token_file}"))); } let body = resp.into_body(); @@ -201,7 +201,7 @@ impl ProvideCredential for AssumeRoleWithWebIdentityCredentialProvider { Error::unexpected("failed to parse STS AssumeRoleWithWebIdentity response") .with_source(e) .with_context(format!("response_length: {}", body.len())) - .with_context(format!("role_arn: {}", role_arn)) + .with_context(format!("role_arn: {role_arn}")) })?; let resp_cred = resp.result.credentials; @@ -213,7 +213,7 @@ impl ProvideCredential for AssumeRoleWithWebIdentityCredentialProvider { Error::unexpected("failed to parse web identity credential expiration") .with_source(e) .with_context(format!("expiration_value: {}", resp_cred.expiration)) - .with_context(format!("role_arn: {}", role_arn)) + .with_context(format!("role_arn: {role_arn}")) })?), }; diff --git a/services/aws-v4/src/provide_credential/cognito.rs b/services/aws-v4/src/provide_credential/cognito.rs index 69621b6..52ce42b 100644 --- a/services/aws-v4/src/provide_credential/cognito.rs +++ b/services/aws-v4/src/provide_credential/cognito.rs @@ -275,7 +275,7 @@ impl ProvideCredential for CognitoIdentityCredentialProvider { // Get or create identity ID let identity_id = self.get_identity_id(ctx).await?; - debug!("Cognito Identity: using identity ID: {}", identity_id); + debug!("Cognito Identity: using identity ID: {identity_id}"); // Get credentials for the identity let creds = self.get_credentials_for_identity(ctx, &identity_id).await?; diff --git a/services/aws-v4/src/provide_credential/ecs.rs b/services/aws-v4/src/provide_credential/ecs.rs index 6f869e2..ee25bb5 100644 --- a/services/aws-v4/src/provide_credential/ecs.rs +++ b/services/aws-v4/src/provide_credential/ecs.rs @@ -144,7 +144,7 @@ impl ECSCredentialProvider { let token = ctx.file_read(token_file).await.map_err(|e| { Error::config_invalid("failed to read ECS auth token file") .with_source(e) - .with_context(format!("file: {}", token_file)) + .with_context(format!("file: {token_file}")) })?; return Ok(Some(String::from_utf8_lossy(&token).trim().to_string())); } @@ -159,7 +159,7 @@ impl ECSCredentialProvider { let token = ctx.file_read(&token_file).await.map_err(|e| { Error::config_invalid("failed to read ECS auth token file") .with_source(e) - .with_context(format!("file: {}", token_file)) + .with_context(format!("file: {token_file}")) })?; return Ok(Some(String::from_utf8_lossy(&token).trim().to_string())); } @@ -230,10 +230,7 @@ impl ProvideCredential for ECSCredentialProvider { } }; - debug!( - "ECS credential provider: fetching credentials from {}", - endpoint - ); + debug!("ECS credential provider: fetching credentials from {endpoint}"); let mut req = Request::builder() .method(Method::GET) @@ -242,7 +239,7 @@ impl ProvideCredential for ECSCredentialProvider { .map_err(|e| { Error::request_invalid("failed to build ECS credentials request") .with_source(e) - .with_context(format!("endpoint: {}", endpoint)) + .with_context(format!("endpoint: {endpoint}")) })?; // Add authorization token if available @@ -260,7 +257,7 @@ impl ProvideCredential for ECSCredentialProvider { let resp = ctx.http_send(req).await.map_err(|e| { Error::unexpected("failed to fetch ECS credentials") .with_source(e) - .with_context(format!("endpoint: {}", endpoint)) + .with_context(format!("endpoint: {endpoint}")) .with_context("hint: check if running on ECS/Fargate with proper IAM role") .set_retryable(true) })?; @@ -271,24 +268,22 @@ impl ProvideCredential for ECSCredentialProvider { let error = match status.as_u16() { 401 | 403 => Error::permission_denied(format!( - "ECS task not authorized to fetch credentials: {}", - body + "ECS task not authorized to fetch credentials: {body}" )) .with_context("hint: check if task has proper IAM role attached"), 404 => Error::config_invalid("ECS credentials endpoint not found") - .with_context(format!("endpoint: {}", endpoint)) + .with_context(format!("endpoint: {endpoint}")) .with_context("hint: verify the container credentials URI"), - 500..=599 => Error::unexpected(format!("ECS metadata service error: {}", body)) + 500..=599 => Error::unexpected(format!("ECS metadata service error: {body}")) .set_retryable(true), _ => Error::unexpected(format!( - "ECS metadata endpoint returned unexpected status {}: {}", - status, body + "ECS metadata endpoint returned unexpected status {status}: {body}" )), }; return Err(error - .with_context(format!("http_status: {}", status)) - .with_context(format!("endpoint: {}", endpoint))); + .with_context(format!("http_status: {status}")) + .with_context(format!("endpoint: {endpoint}"))); } let body = resp.into_body(); @@ -296,7 +291,7 @@ impl ProvideCredential for ECSCredentialProvider { Error::unexpected("failed to parse ECS credentials response") .with_source(e) .with_context(format!("response_length: {}", body.len())) - .with_context(format!("endpoint: {}", endpoint)) + .with_context(format!("endpoint: {endpoint}")) })?; let expires_in = creds.expiration.parse().map_err(|e| { diff --git a/services/aws-v4/src/provide_credential/imds.rs b/services/aws-v4/src/provide_credential/imds.rs index 656e12e..61db8b5 100644 --- a/services/aws-v4/src/provide_credential/imds.rs +++ b/services/aws-v4/src/provide_credential/imds.rs @@ -74,7 +74,7 @@ impl IMDSv2CredentialProvider { } let endpoint = self.get_endpoint(ctx); - let url = format!("{}/latest/api/token", endpoint); + let url = format!("{endpoint}/latest/api/token"); let req = http::Request::builder() .uri(&url) .method(Method::PUT) @@ -136,7 +136,7 @@ impl ProvideCredential for IMDSv2CredentialProvider { // List all credentials that node has. let endpoint = self.get_endpoint(ctx); - let url = format!("{}/latest/meta-data/iam/security-credentials/", endpoint); + let url = format!("{endpoint}/latest/meta-data/iam/security-credentials/"); let req = http::Request::builder() .uri(&url) .method(Method::GET) @@ -175,10 +175,7 @@ impl ProvideCredential for IMDSv2CredentialProvider { // Get the credentials via role_name. let endpoint = self.get_endpoint(ctx); - let url = format!( - "{}/latest/meta-data/iam/security-credentials/{profile_name}", - endpoint - ); + let url = format!("{endpoint}/latest/meta-data/iam/security-credentials/{profile_name}"); let req = http::Request::builder() .uri(url) .method(Method::GET) @@ -188,20 +185,20 @@ impl ProvideCredential for IMDSv2CredentialProvider { .map_err(|e| { Error::request_invalid("failed to build IMDS credentials fetch request") .with_source(e) - .with_context(format!("profile: {}", profile_name)) + .with_context(format!("profile: {profile_name}")) })?; let resp = ctx.http_send_as_string(req).await.map_err(|e| { Error::unexpected("failed to fetch IMDS credentials") .with_source(e) - .with_context(format!("profile: {}", profile_name)) + .with_context(format!("profile: {profile_name}")) .set_retryable(true) })?; if resp.status() != http::StatusCode::OK { return Err( parse_imds_error("fetch_credentials", resp.status(), resp.body()) - .with_context(format!("profile: {}", profile_name)), + .with_context(format!("profile: {profile_name}")), ); } @@ -211,7 +208,7 @@ impl ProvideCredential for IMDSv2CredentialProvider { Error::unexpected("failed to parse IMDS credentials response") .with_source(e) .with_context(format!("response_length: {}", content.len())) - .with_context(format!("profile: {}", profile_name)) + .with_context(format!("profile: {profile_name}")) })?; // Check for specific error codes @@ -223,7 +220,7 @@ impl ProvideCredential for IMDSv2CredentialProvider { resp.message )) .with_context(format!("error_code: {}", resp.code)) - .with_context(format!("profile: {}", profile_name)) + .with_context(format!("profile: {profile_name}")) .with_context("hint: check if the IAM role has a trust relationship with EC2")); } code if code.contains("Expired") => { @@ -232,14 +229,14 @@ impl ProvideCredential for IMDSv2CredentialProvider { resp.message )) .with_context(format!("error_code: {}", resp.code)) - .with_context(format!("profile: {}", profile_name))); + .with_context(format!("profile: {profile_name}"))); } _ => { return Err(Error::unexpected(format!( "IMDS returned error: [{}] {}", resp.code, resp.message )) - .with_context(format!("profile: {}", profile_name))); + .with_context(format!("profile: {profile_name}"))); } } diff --git a/services/aws-v4/src/provide_credential/utils.rs b/services/aws-v4/src/provide_credential/utils.rs index bd877f6..d183af5 100644 --- a/services/aws-v4/src/provide_credential/utils.rs +++ b/services/aws-v4/src/provide_credential/utils.rs @@ -83,45 +83,45 @@ pub fn parse_sts_error( let mut error = match code.as_str() { // Permission/Authorization errors "AccessDenied" | "UnauthorizedAccess" | "Forbidden" => { - Error::permission_denied(format!("{}: {}", code, message)) + Error::permission_denied(format!("{code}: {message}")) } // Credential errors "ExpiredToken" | "TokenRefreshRequired" | "InvalidToken" => { - Error::credential_invalid(format!("token expired or invalid: {}", message)) + Error::credential_invalid(format!("token expired or invalid: {message}")) } // Configuration errors "InvalidParameterValue" | "MissingParameter" | "InvalidParameterCombination" => { - Error::config_invalid(format!("invalid configuration: {}", message)) + Error::config_invalid(format!("invalid configuration: {message}")) } // Rate limiting "Throttling" | "RequestLimitExceeded" | "TooManyRequestsException" => { - Error::rate_limited(format!("AWS API rate limit: {}", message)) + Error::rate_limited(format!("AWS API rate limit: {message}")) } // Service unavailable (retryable) "ServiceUnavailable" | "InternalError" | "InternalFailure" => { - Error::unexpected(format!("AWS service error: {}", message)).set_retryable(true) + Error::unexpected(format!("AWS service error: {message}")).set_retryable(true) } // Request errors "InvalidRequest" | "MalformedQueryString" => { - Error::request_invalid(format!("invalid request: {}", message)) + Error::request_invalid(format!("invalid request: {message}")) } // Default to unexpected - _ => Error::unexpected(format!("AWS error [{}]: {}", code, message)), + _ => Error::unexpected(format!("AWS error [{code}]: {message}")), }; // Add context error = error - .with_context(format!("operation: {}", operation)) - .with_context(format!("error_code: {}", code)); + .with_context(format!("operation: {operation}")) + .with_context(format!("error_code: {code}")); if let Some(id) = request_id { - error = error.with_context(format!("request_id: {}", id)); + error = error.with_context(format!("request_id: {id}")); } error @@ -129,26 +129,27 @@ pub fn parse_sts_error( // Failed to parse error response, return generic error based on status code let mut error = match status.as_u16() { 400..=499 if status == http::StatusCode::FORBIDDEN => { - Error::permission_denied(format!("STS request forbidden: {}", body)) + Error::permission_denied(format!("STS request forbidden: {body}")) } 400..=499 if status == http::StatusCode::UNAUTHORIZED => { - Error::credential_invalid(format!("STS authentication failed: {}", body)) + Error::credential_invalid(format!("STS authentication failed: {body}")) } - 429 => Error::rate_limited(format!("STS rate limit exceeded: {}", body)), + 429 => Error::rate_limited(format!("STS rate limit exceeded: {body}")), 400..=499 => { - Error::request_invalid(format!("STS request failed with {}: {}", status, body)) + Error::request_invalid(format!("STS request failed with {status}: {body}")) } - 500..=599 => Error::unexpected(format!("STS server error {}: {}", status, body)) - .set_retryable(true), - _ => Error::unexpected(format!("STS request failed with {}: {}", status, body)), + 500..=599 => { + Error::unexpected(format!("STS server error {status}: {body}")).set_retryable(true) + } + _ => Error::unexpected(format!("STS request failed with {status}: {body}")), }; error = error - .with_context(format!("operation: {}", operation)) - .with_context(format!("http_status: {}", status)); + .with_context(format!("operation: {operation}")) + .with_context(format!("http_status: {status}")); if let Some(id) = request_id { - error = error.with_context(format!("request_id: {}", id)); + error = error.with_context(format!("request_id: {id}")); } error @@ -184,23 +185,23 @@ pub fn parse_imds_error(operation: &str, status: http::StatusCode, body: &str) - _ => Error::unexpected(format!("IMDS error [{}]: {}", error.code, error.message)), }; - err.with_context(format!("operation: {}", operation)) + err.with_context(format!("operation: {operation}")) .with_context(format!("error_code: {}", error.code)) } else { // Generic error based on status match status.as_u16() { - 401 | 403 => Error::permission_denied(format!("IMDS access denied: {}", body)) - .with_context(format!("operation: {}", operation)) + 401 | 403 => Error::permission_denied(format!("IMDS access denied: {body}")) + .with_context(format!("operation: {operation}")) .with_context("hint: check if IMDSv2 is required"), 404 => Error::config_invalid("instance metadata not found") - .with_context(format!("operation: {}", operation)) + .with_context(format!("operation: {operation}")) .with_context("hint: are you running on EC2?"), - 500..=599 => Error::unexpected(format!("IMDS server error: {}", body)) - .with_context(format!("operation: {}", operation)) + 500..=599 => Error::unexpected(format!("IMDS server error: {body}")) + .with_context(format!("operation: {operation}")) .set_retryable(true), - _ => Error::unexpected(format!("IMDS request failed: {}", body)) - .with_context(format!("operation: {}", operation)) - .with_context(format!("http_status: {}", status)), + _ => Error::unexpected(format!("IMDS request failed: {body}")) + .with_context(format!("operation: {operation}")) + .with_context(format!("http_status: {status}")), } } } diff --git a/services/google/src/provide_credential/vm_metadata.rs b/services/google/src/provide_credential/vm_metadata.rs index c3993b7..bd09ccd 100644 --- a/services/google/src/provide_credential/vm_metadata.rs +++ b/services/google/src/provide_credential/vm_metadata.rs @@ -70,10 +70,7 @@ impl ProvideCredential for VmMetadataCredentialProvider { // Use "default" service account if not specified let service_account = "default"; - debug!( - "loading token from VM metadata service for account: {}", - service_account - ); + debug!("loading token from VM metadata service for account: {service_account}"); // Allow overriding metadata host for testing let metadata_host = self