Fix some new clippy lints
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Alex 2022-03-14 12:00:23 +01:00
parent 0af314b295
commit ba6b56ae68
Signed by: lx
GPG key ID: 0E496D15096376BE
14 changed files with 22 additions and 37 deletions

View file

@ -200,12 +200,7 @@ pub fn find_matching_cors_rule<'a>(
None => vec![], None => vec![],
}; };
return Ok(cors_config.iter().find(|rule| { return Ok(cors_config.iter().find(|rule| {
cors_rule_matches( cors_rule_matches(rule, origin, req.method().as_ref(), request_headers.iter())
rule,
origin,
&req.method().to_string(),
request_headers.iter(),
)
})); }));
} }
} }

View file

@ -1042,12 +1042,12 @@ mod tests {
query.common.prefix = "a/".to_string(); query.common.prefix = "a/".to_string();
assert_eq!( assert_eq!(
common_prefix(&objs.get(0).unwrap(), &query.common), common_prefix(objs.get(0).unwrap(), &query.common),
Some("a/b/") Some("a/b/")
); );
query.common.prefix = "a/b/".to_string(); query.common.prefix = "a/b/".to_string();
assert_eq!(common_prefix(&objs.get(0).unwrap(), &query.common), None); assert_eq!(common_prefix(objs.get(0).unwrap(), &query.common), None);
} }
#[test] #[test]
@ -1272,7 +1272,7 @@ mod tests {
Version { Version {
bucket_id: uuid, bucket_id: uuid,
key: "a".to_string(), key: "a".to_string(),
uuid: uuid, uuid,
deleted: false.into(), deleted: false.into(),
blocks: crdt::Map::<VersionBlockKey, VersionBlock>::from_iter(blocks), blocks: crdt::Map::<VersionBlockKey, VersionBlock>::from_iter(blocks),
parts_etags: crdt::Map::<u64, String>::from_iter(etags), parts_etags: crdt::Map::<u64, String>::from_iter(etags),

View file

@ -259,8 +259,7 @@ impl RoutingRuleInner {
let has_prefix = self let has_prefix = self
.condition .condition
.as_ref() .as_ref()
.map(|c| c.prefix.as_ref()) .and_then(|c| c.prefix.as_ref())
.flatten()
.is_some(); .is_some();
self.redirect.validate(has_prefix) self.redirect.validate(has_prefix)
} }

View file

@ -51,7 +51,7 @@ pub async fn check_payload_signature(
let canonical_request = canonical_request( let canonical_request = canonical_request(
request.method(), request.method(),
&request.uri().path().to_string(), request.uri().path(),
&canonical_query_string(request.uri()), &canonical_query_string(request.uri()),
&headers, &headers,
&authorization.signed_headers, &authorization.signed_headers,

View file

@ -115,7 +115,7 @@ async fn cli_command(opt: Opt) -> Result<(), Error> {
} else { } else {
let node_id = garage_rpc::system::read_node_id(&config.as_ref().unwrap().metadata_dir) let node_id = garage_rpc::system::read_node_id(&config.as_ref().unwrap().metadata_dir)
.err_context(READ_KEY_ERROR)?; .err_context(READ_KEY_ERROR)?;
if let Some(a) = config.as_ref().map(|c| c.rpc_public_addr).flatten() { if let Some(a) = config.as_ref().and_then(|c| c.rpc_public_addr) {
(node_id, a) (node_id, a)
} else { } else {
let default_addr = SocketAddr::new( let default_addr = SocketAddr::new(

View file

@ -27,7 +27,7 @@ async fn test_bucket_all() {
.buckets .buckets
.as_ref() .as_ref()
.unwrap() .unwrap()
.into_iter() .iter()
.filter(|x| x.name.as_ref().is_some()) .filter(|x| x.name.as_ref().is_some())
.find(|x| x.name.as_ref().unwrap() == "hello") .find(|x| x.name.as_ref().unwrap() == "hello")
.is_some()); .is_some());
@ -79,7 +79,7 @@ async fn test_bucket_all() {
.buckets .buckets
.as_ref() .as_ref()
.unwrap() .unwrap()
.into_iter() .iter()
.filter(|x| x.name.as_ref().is_some()) .filter(|x| x.name.as_ref().is_some())
.find(|x| x.name.as_ref().unwrap() == "hello") .find(|x| x.name.as_ref().unwrap() == "hello")
.is_none()); .is_none());

View file

@ -527,8 +527,8 @@ async fn test_listmultipart() {
upnext = r.next_upload_id_marker; upnext = r.next_upload_id_marker;
loopcnt += 1; loopcnt += 1;
upcnt += r.uploads.unwrap_or(vec![]).len(); upcnt += r.uploads.unwrap_or_default().len();
pfxcnt += r.common_prefixes.unwrap_or(vec![]).len(); pfxcnt += r.common_prefixes.unwrap_or_default().len();
if next.is_none() { if next.is_none() {
break; break;

View file

@ -124,7 +124,7 @@ async fn test_uploadlistpart() {
assert!(r.part_number_marker.is_none()); assert!(r.part_number_marker.is_none());
assert!(r.next_part_number_marker.is_some()); assert!(r.next_part_number_marker.is_some());
assert_eq!(r.max_parts, 1 as i32); assert_eq!(r.max_parts, 1_i32);
assert!(r.is_truncated); assert!(r.is_truncated);
assert_eq!(r.key.unwrap(), "a"); assert_eq!(r.key.unwrap(), "a");
assert_eq!(r.upload_id.unwrap().as_str(), uid.as_str()); assert_eq!(r.upload_id.unwrap().as_str(), uid.as_str());
@ -146,7 +146,7 @@ async fn test_uploadlistpart() {
r2.part_number_marker.as_ref().unwrap(), r2.part_number_marker.as_ref().unwrap(),
r.next_part_number_marker.as_ref().unwrap() r.next_part_number_marker.as_ref().unwrap()
); );
assert_eq!(r2.max_parts, 1 as i32); assert_eq!(r2.max_parts, 1_i32);
assert!(r2.is_truncated); assert!(r2.is_truncated);
assert_eq!(r2.key.unwrap(), "a"); assert_eq!(r2.key.unwrap(), "a");
assert_eq!(r2.upload_id.unwrap().as_str(), uid.as_str()); assert_eq!(r2.upload_id.unwrap().as_str(), uid.as_str());

View file

@ -30,8 +30,7 @@ impl<'a> BucketHelper<'a> {
// the AWS spec, and hex-encoded UUIDs are 64 chars long. // the AWS spec, and hex-encoded UUIDs are 64 chars long.
let hexbucket = hex::decode(bucket_name.as_str()) let hexbucket = hex::decode(bucket_name.as_str())
.ok() .ok()
.map(|by| Uuid::try_from(&by)) .and_then(|by| Uuid::try_from(&by));
.flatten();
if let Some(bucket_id) = hexbucket { if let Some(bucket_id) = hexbucket {
Ok(self Ok(self
.0 .0
@ -46,8 +45,7 @@ impl<'a> BucketHelper<'a> {
.bucket_alias_table .bucket_alias_table
.get(&EmptyKey, bucket_name) .get(&EmptyKey, bucket_name)
.await? .await?
.map(|x| *x.state.get()) .and_then(|x| *x.state.get()))
.flatten())
} }
} }

View file

@ -106,8 +106,7 @@ impl Key {
/// Get permissions for a bucket /// Get permissions for a bucket
pub fn bucket_permissions(&self, bucket: &Uuid) -> BucketKeyPerm { pub fn bucket_permissions(&self, bucket: &Uuid) -> BucketKeyPerm {
self.params() self.params()
.map(|params| params.authorized_buckets.get(bucket)) .and_then(|params| params.authorized_buckets.get(bucket))
.flatten()
.cloned() .cloned()
.unwrap_or(BucketKeyPerm::NO_PERMISSIONS) .unwrap_or(BucketKeyPerm::NO_PERMISSIONS)
} }

View file

@ -51,10 +51,8 @@ pub async fn get_consul_nodes(
let pubkey = ent let pubkey = ent
.node_meta .node_meta
.get("pubkey") .get("pubkey")
.map(|k| hex::decode(&k).ok()) .and_then(|k| hex::decode(&k).ok())
.flatten() .and_then(|k| NodeID::from_slice(&k[..]));
.map(|k| NodeID::from_slice(&k[..]))
.flatten();
if let (Some(ip), Some(pubkey)) = (ip, pubkey) { if let (Some(ip), Some(pubkey)) = (ip, pubkey) {
ret.push((pubkey, SocketAddr::new(ip, ent.service_port))); ret.push((pubkey, SocketAddr::new(ip, ent.service_port)));
} else { } else {

View file

@ -63,10 +63,8 @@ pub async fn get_kubernetes_nodes(
let pubkey = &node let pubkey = &node
.metadata .metadata
.name .name
.map(|k| hex::decode(&k).ok()) .and_then(|k| hex::decode(&k).ok())
.flatten() .and_then(|k| NodeID::from_slice(&k[..]));
.map(|k| NodeID::from_slice(&k[..]))
.flatten();
if let Some(pubkey) = pubkey { if let Some(pubkey) = pubkey {
ret.push((*pubkey, SocketAddr::new(node.spec.address, node.spec.port))) ret.push((*pubkey, SocketAddr::new(node.spec.address, node.spec.port)))

View file

@ -322,8 +322,7 @@ impl RpcHelper {
let peer_avg_ping = peer_list let peer_avg_ping = peer_list
.iter() .iter()
.find(|x| x.id.as_ref() == to.as_slice()) .find(|x| x.id.as_ref() == to.as_slice())
.map(|pi| pi.avg_ping) .and_then(|pi| pi.avg_ping)
.flatten()
.unwrap_or_else(|| Duration::from_secs(1)); .unwrap_or_else(|| Duration::from_secs(1));
( (
to != self.0.our_node_id, to != self.0.our_node_id,

View file

@ -175,8 +175,7 @@ async fn serve_file(garage: Arc<Garage>, req: &Request<Body>) -> Result<Response
.bucket_alias_table .bucket_alias_table
.get(&EmptyKey, &bucket_name.to_string()) .get(&EmptyKey, &bucket_name.to_string())
.await? .await?
.map(|x| x.state.take()) .and_then(|x| x.state.take())
.flatten()
.ok_or(Error::NotFound)?; .ok_or(Error::NotFound)?;
// Check bucket isn't deleted and has website access enabled // Check bucket isn't deleted and has website access enabled