Skip to content

Commit bbe27ed

Browse files
authored
address clippy warnings for azure_storage (Azure#1406)
1 parent 9c83e3f commit bbe27ed

File tree

6 files changed

+59
-61
lines changed

6 files changed

+59
-61
lines changed

sdk/storage/src/authorization/authorization_policy.rs

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ impl Policy for AuthorizationPolicy {
4141
let auth = generate_authorization(
4242
request.headers(),
4343
request.url(),
44-
request.method(),
44+
*request.method(),
4545
account,
4646
key,
47-
ctx.get()
47+
*ctx.get()
4848
.expect("ServiceType must be in the Context at this point"),
4949
)?;
5050
request.insert_header(AUTHORIZATION, auth);
@@ -87,10 +87,10 @@ impl Policy for AuthorizationPolicy {
8787
fn generate_authorization(
8888
h: &Headers,
8989
u: &Url,
90-
method: &Method,
90+
method: Method,
9191
account: &str,
9292
key: &str,
93-
service_type: &ServiceType,
93+
service_type: ServiceType,
9494
) -> azure_core::Result<String> {
9595
let str_to_sign = string_to_sign(h, u, method, account, service_type);
9696
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 {
108108
fn string_to_sign(
109109
h: &Headers,
110110
u: &Url,
111-
method: &Method,
111+
method: Method,
112112
account: &str,
113-
service_type: &ServiceType,
113+
service_type: ServiceType,
114114
) -> String {
115-
match service_type {
116-
ServiceType::Table => {
117-
format!(
118-
"{}\n{}\n{}\n{}\n{}",
119-
method.as_ref(),
120-
add_if_exists(h, &CONTENT_MD5),
121-
add_if_exists(h, &CONTENT_TYPE),
122-
add_if_exists(h, &MS_DATE),
123-
canonicalized_resource_table(account, u)
124-
)
125-
}
126-
_ => {
127-
// content length must only be specified if != 0
128-
// this is valid from 2015-02-21
129-
let content_length = h
130-
.get_optional_str(&CONTENT_LENGTH)
131-
.filter(|&v| v != "0")
132-
.unwrap_or_default();
133-
format!(
134-
"{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}{}",
135-
method.as_ref(),
136-
add_if_exists(h, &CONTENT_ENCODING),
137-
add_if_exists(h, &CONTENT_LANGUAGE),
138-
content_length,
139-
add_if_exists(h, &CONTENT_MD5),
140-
add_if_exists(h, &CONTENT_TYPE),
141-
add_if_exists(h, &DATE),
142-
add_if_exists(h, &IF_MODIFIED_SINCE),
143-
add_if_exists(h, &IF_MATCH),
144-
add_if_exists(h, &IF_NONE_MATCH),
145-
add_if_exists(h, &IF_UNMODIFIED_SINCE),
146-
add_if_exists(h, &RANGE),
147-
canonicalize_header(h),
148-
canonicalized_resource(account, u)
149-
)
150-
}
115+
if matches!(service_type, ServiceType::Table) {
116+
format!(
117+
"{}\n{}\n{}\n{}\n{}",
118+
method.as_ref(),
119+
add_if_exists(h, &CONTENT_MD5),
120+
add_if_exists(h, &CONTENT_TYPE),
121+
add_if_exists(h, &MS_DATE),
122+
canonicalized_resource_table(account, u)
123+
)
124+
} else {
125+
// content length must only be specified if != 0
126+
// this is valid from 2015-02-21
127+
let content_length = h
128+
.get_optional_str(&CONTENT_LENGTH)
129+
.filter(|&v| v != "0")
130+
.unwrap_or_default();
131+
format!(
132+
"{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}{}",
133+
method.as_ref(),
134+
add_if_exists(h, &CONTENT_ENCODING),
135+
add_if_exists(h, &CONTENT_LANGUAGE),
136+
content_length,
137+
add_if_exists(h, &CONTENT_MD5),
138+
add_if_exists(h, &CONTENT_TYPE),
139+
add_if_exists(h, &DATE),
140+
add_if_exists(h, &IF_MODIFIED_SINCE),
141+
add_if_exists(h, &IF_MATCH),
142+
add_if_exists(h, &IF_NONE_MATCH),
143+
add_if_exists(h, &IF_UNMODIFIED_SINCE),
144+
add_if_exists(h, &RANGE),
145+
canonicalize_header(h),
146+
canonicalized_resource(account, u)
147+
)
151148
}
152149
}
153150

sdk/storage/src/cloud_location.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ impl CloudLocation {
5454

5555
pub fn credentials(&self) -> &StorageCredentials {
5656
match self {
57-
CloudLocation::Public { credentials, .. } => credentials,
58-
CloudLocation::China { credentials, .. } => credentials,
57+
CloudLocation::Public { credentials, .. }
58+
| CloudLocation::China { credentials, .. }
59+
| CloudLocation::Custom { credentials, .. } => credentials,
5960
CloudLocation::Emulator { .. } => &EMULATOR_CREDENTIALS,
60-
CloudLocation::Custom { credentials, .. } => credentials,
6161
}
6262
}
6363
}

sdk/storage/src/connection_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'a> ConnectionString<'a> {
196196
account_name: Some(account),
197197
account_key: Some(key),
198198
..
199-
} => Ok(StorageCredentials::Key(account.to_string(), key.to_string())),
199+
} => Ok(StorageCredentials::Key((*account).to_string(), (*key).to_string())),
200200
_ => {
201201
Err(Error::message(ErrorKind::Credential,
202202
"Could not create a `StorageCredentail` from the provided connection string. Please validate that you have specified a means of authentication (key, SAS, etc.)."

sdk/storage/src/parsing_xml.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ pub fn traverse<'a>(
6060
if vec.is_empty() {
6161
if (x + 1) >= path.len() && ignore_empty_leaf {
6262
return Ok(vec);
63-
} else {
64-
return Err(Error::with_message(ErrorKind::Other, || {
65-
format!("path not found: {}", *item)
66-
}));
6763
}
64+
return Err(Error::with_message(ErrorKind::Other, || {
65+
format!("path not found: {}", *item)
66+
}));
6867
}
6968

7069
if vec.len() > 1 && (x + 1) < path.len() {

sdk/storage/src/shared_access_signature/account_sas.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl fmt::Display for AccountSasResourceType {
8282
}
8383

8484
/// 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)).
85+
#[allow(clippy::struct_excessive_bools)]
8586
#[derive(Copy, Clone, Default)]
8687
pub struct AccountSasPermissions {
8788
pub read: bool,
@@ -181,12 +182,12 @@ impl AccountSharedAccessSignature {
181182
self.permissions,
182183
self.resource,
183184
self.resource_type,
184-
self.start.map_or("".to_string(), format_date),
185+
self.start.map_or(String::new(), format_date),
185186
format_date(self.expiry),
186187
self.ip.clone().unwrap_or_default(),
187188
self.protocol
188189
.as_ref()
189-
.map_or("".to_string(), |v| v.to_string()),
190+
.map_or(String::new(), ToString::to_string),
190191
self.version,
191192
);
192193

sdk/storage/src/shared_access_signature/service_sas.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ impl fmt::Display for BlobSignedResource {
2727
}
2828
}
2929

30+
#[allow(clippy::struct_excessive_bools)]
3031
#[derive(Default)]
3132
pub struct BlobSasPermissions {
3233
pub read: bool, // r - Container | Directory | Blob
@@ -136,23 +137,23 @@ impl BlobSharedAccessSignature {
136137
fn sign(&self) -> String {
137138
let content = vec![
138139
self.permissions.to_string(),
139-
self.start.map_or("".to_string(), format_date),
140+
self.start.map_or(String::new(), format_date),
140141
format_date(self.expiry),
141142
self.canonicalized_resource.clone(),
142143
self.identifier
143144
.as_ref()
144-
.unwrap_or(&"".to_string())
145+
.unwrap_or(&String::new())
145146
.to_string(),
146-
self.ip.as_ref().unwrap_or(&"".to_string()).to_string(),
147+
self.ip.as_ref().unwrap_or(&String::new()).to_string(),
147148
self.protocol.map(|x| x.to_string()).unwrap_or_default(),
148149
SERVICE_SAS_VERSION.to_string(),
149150
self.resource.to_string(),
150-
"".to_string(), // snapshot time
151-
"".to_string(), // rscd
152-
"".to_string(), // rscc
153-
"".to_string(), // rsce
154-
"".to_string(), // rscl
155-
"".to_string(), // rsct
151+
String::new(), // snapshot time
152+
String::new(), // rscd
153+
String::new(), // rscc
154+
String::new(), // rsce
155+
String::new(), // rscl
156+
String::new(), // rsct
156157
];
157158

158159
hmac::sign(&content.join("\n"), &self.key).expect("HMAC signing failed")

0 commit comments

Comments
 (0)