diff --git a/sdk/storage/src/authorization/authorization_policy.rs b/sdk/storage/src/authorization/authorization_policy.rs index aee7c1b049..110fac6625 100644 --- a/sdk/storage/src/authorization/authorization_policy.rs +++ b/sdk/storage/src/authorization/authorization_policy.rs @@ -41,10 +41,10 @@ impl Policy for AuthorizationPolicy { let auth = generate_authorization( request.headers(), request.url(), - request.method(), + *request.method(), account, key, - ctx.get() + *ctx.get() .expect("ServiceType must be in the Context at this point"), )?; request.insert_header(AUTHORIZATION, auth); @@ -87,10 +87,10 @@ impl Policy for AuthorizationPolicy { fn generate_authorization( h: &Headers, u: &Url, - method: &Method, + method: Method, account: &str, key: &str, - service_type: &ServiceType, + service_type: ServiceType, ) -> azure_core::Result { let str_to_sign = string_to_sign(h, u, method, account, service_type); let auth = crate::hmac::sign(&str_to_sign, key).context( @@ -108,46 +108,43 @@ fn add_if_exists<'a>(h: &'a Headers, key: &HeaderName) -> &'a str { fn string_to_sign( h: &Headers, u: &Url, - method: &Method, + method: Method, account: &str, - service_type: &ServiceType, + service_type: ServiceType, ) -> String { - match service_type { - ServiceType::Table => { - format!( - "{}\n{}\n{}\n{}\n{}", - method.as_ref(), - add_if_exists(h, &CONTENT_MD5), - add_if_exists(h, &CONTENT_TYPE), - add_if_exists(h, &MS_DATE), - canonicalized_resource_table(account, u) - ) - } - _ => { - // content length must only be specified if != 0 - // this is valid from 2015-02-21 - let content_length = h - .get_optional_str(&CONTENT_LENGTH) - .filter(|&v| v != "0") - .unwrap_or_default(); - format!( - "{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}{}", - method.as_ref(), - add_if_exists(h, &CONTENT_ENCODING), - add_if_exists(h, &CONTENT_LANGUAGE), - content_length, - add_if_exists(h, &CONTENT_MD5), - add_if_exists(h, &CONTENT_TYPE), - add_if_exists(h, &DATE), - add_if_exists(h, &IF_MODIFIED_SINCE), - add_if_exists(h, &IF_MATCH), - add_if_exists(h, &IF_NONE_MATCH), - add_if_exists(h, &IF_UNMODIFIED_SINCE), - add_if_exists(h, &RANGE), - canonicalize_header(h), - canonicalized_resource(account, u) - ) - } + if matches!(service_type, ServiceType::Table) { + format!( + "{}\n{}\n{}\n{}\n{}", + method.as_ref(), + add_if_exists(h, &CONTENT_MD5), + add_if_exists(h, &CONTENT_TYPE), + add_if_exists(h, &MS_DATE), + canonicalized_resource_table(account, u) + ) + } else { + // content length must only be specified if != 0 + // this is valid from 2015-02-21 + let content_length = h + .get_optional_str(&CONTENT_LENGTH) + .filter(|&v| v != "0") + .unwrap_or_default(); + format!( + "{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}{}", + method.as_ref(), + add_if_exists(h, &CONTENT_ENCODING), + add_if_exists(h, &CONTENT_LANGUAGE), + content_length, + add_if_exists(h, &CONTENT_MD5), + add_if_exists(h, &CONTENT_TYPE), + add_if_exists(h, &DATE), + add_if_exists(h, &IF_MODIFIED_SINCE), + add_if_exists(h, &IF_MATCH), + add_if_exists(h, &IF_NONE_MATCH), + add_if_exists(h, &IF_UNMODIFIED_SINCE), + add_if_exists(h, &RANGE), + canonicalize_header(h), + canonicalized_resource(account, u) + ) } } diff --git a/sdk/storage/src/cloud_location.rs b/sdk/storage/src/cloud_location.rs index 801d5baf18..7285b91d54 100644 --- a/sdk/storage/src/cloud_location.rs +++ b/sdk/storage/src/cloud_location.rs @@ -54,10 +54,10 @@ impl CloudLocation { pub fn credentials(&self) -> &StorageCredentials { match self { - CloudLocation::Public { credentials, .. } => credentials, - CloudLocation::China { credentials, .. } => credentials, + CloudLocation::Public { credentials, .. } + | CloudLocation::China { credentials, .. } + | CloudLocation::Custom { credentials, .. } => credentials, CloudLocation::Emulator { .. } => &EMULATOR_CREDENTIALS, - CloudLocation::Custom { credentials, .. } => credentials, } } } diff --git a/sdk/storage/src/connection_string.rs b/sdk/storage/src/connection_string.rs index 0fb24153e1..fd1f609c32 100644 --- a/sdk/storage/src/connection_string.rs +++ b/sdk/storage/src/connection_string.rs @@ -196,7 +196,7 @@ impl<'a> ConnectionString<'a> { account_name: Some(account), account_key: Some(key), .. - } => Ok(StorageCredentials::Key(account.to_string(), key.to_string())), + } => Ok(StorageCredentials::Key((*account).to_string(), (*key).to_string())), _ => { Err(Error::message(ErrorKind::Credential, "Could not create a `StorageCredentail` from the provided connection string. Please validate that you have specified a means of authentication (key, SAS, etc.)." diff --git a/sdk/storage/src/parsing_xml.rs b/sdk/storage/src/parsing_xml.rs index 2345014b5f..1f75c7fdb2 100644 --- a/sdk/storage/src/parsing_xml.rs +++ b/sdk/storage/src/parsing_xml.rs @@ -60,11 +60,10 @@ pub fn traverse<'a>( if vec.is_empty() { if (x + 1) >= path.len() && ignore_empty_leaf { return Ok(vec); - } else { - return Err(Error::with_message(ErrorKind::Other, || { - format!("path not found: {}", *item) - })); } + return Err(Error::with_message(ErrorKind::Other, || { + format!("path not found: {}", *item) + })); } if vec.len() > 1 && (x + 1) < path.len() { diff --git a/sdk/storage/src/shared_access_signature/account_sas.rs b/sdk/storage/src/shared_access_signature/account_sas.rs index 71d434d4d4..d7e5242275 100644 --- a/sdk/storage/src/shared_access_signature/account_sas.rs +++ b/sdk/storage/src/shared_access_signature/account_sas.rs @@ -82,6 +82,7 @@ impl fmt::Display for AccountSasResourceType { } /// Indicate which operations a `key_client` may perform on the resource ([Azure documentation](https://docs.microsoft.com/rest/api/storageservices/create-service-sas#specifying-permissions)). +#[allow(clippy::struct_excessive_bools)] #[derive(Copy, Clone, Default)] pub struct AccountSasPermissions { pub read: bool, @@ -181,12 +182,12 @@ impl AccountSharedAccessSignature { self.permissions, self.resource, self.resource_type, - self.start.map_or("".to_string(), format_date), + self.start.map_or(String::new(), format_date), format_date(self.expiry), self.ip.clone().unwrap_or_default(), self.protocol .as_ref() - .map_or("".to_string(), |v| v.to_string()), + .map_or(String::new(), ToString::to_string), self.version, ); diff --git a/sdk/storage/src/shared_access_signature/service_sas.rs b/sdk/storage/src/shared_access_signature/service_sas.rs index 09611ad9dd..4268838d8d 100644 --- a/sdk/storage/src/shared_access_signature/service_sas.rs +++ b/sdk/storage/src/shared_access_signature/service_sas.rs @@ -27,6 +27,7 @@ impl fmt::Display for BlobSignedResource { } } +#[allow(clippy::struct_excessive_bools)] #[derive(Default)] pub struct BlobSasPermissions { pub read: bool, // r - Container | Directory | Blob @@ -136,23 +137,23 @@ impl BlobSharedAccessSignature { fn sign(&self) -> String { let content = vec![ self.permissions.to_string(), - self.start.map_or("".to_string(), format_date), + self.start.map_or(String::new(), format_date), format_date(self.expiry), self.canonicalized_resource.clone(), self.identifier .as_ref() - .unwrap_or(&"".to_string()) + .unwrap_or(&String::new()) .to_string(), - self.ip.as_ref().unwrap_or(&"".to_string()).to_string(), + self.ip.as_ref().unwrap_or(&String::new()).to_string(), self.protocol.map(|x| x.to_string()).unwrap_or_default(), SERVICE_SAS_VERSION.to_string(), self.resource.to_string(), - "".to_string(), // snapshot time - "".to_string(), // rscd - "".to_string(), // rscc - "".to_string(), // rsce - "".to_string(), // rscl - "".to_string(), // rsct + String::new(), // snapshot time + String::new(), // rscd + String::new(), // rscc + String::new(), // rsce + String::new(), // rscl + String::new(), // rsct ]; hmac::sign(&content.join("\n"), &self.key).expect("HMAC signing failed")