From 1ca36916373f7b512d5ce01a8c3f8c183e6fe34f Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 7 Jan 2022 17:05:31 +0100 Subject: [PATCH] Rename fields and fix clippy --- src/api/s3_cors.rs | 24 ++++++++++++------------ src/model/bucket_table.rs | 6 +++--- src/web/web_server.rs | 13 ++++++------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/api/s3_cors.rs b/src/api/s3_cors.rs index def7fbc3..c3329085 100644 --- a/src/api/s3_cors.rs +++ b/src/api/s3_cors.rs @@ -193,9 +193,9 @@ impl CorsRule { GarageCorsRule { id: self.id.as_ref().map(|x| x.0.to_owned()), max_age_seconds: self.max_age_seconds.as_ref().map(|x| x.0 as u64), - allowed_origins: convert_vec(&self.allowed_origins), - allowed_methods: convert_vec(&self.allowed_methods), - allowed_headers: convert_vec(&self.allowed_headers), + allow_origins: convert_vec(&self.allowed_origins), + allow_methods: convert_vec(&self.allowed_methods), + allow_headers: convert_vec(&self.allowed_headers), expose_headers: convert_vec(&self.expose_headers), } } @@ -209,9 +209,9 @@ impl CorsRule { Self { id: rule.id.as_ref().map(|x| Value(x.clone())), max_age_seconds: rule.max_age_seconds.map(|x| IntValue(x as i64)), - allowed_origins: convert_vec(&rule.allowed_origins), - allowed_methods: convert_vec(&rule.allowed_methods), - allowed_headers: convert_vec(&rule.allowed_headers), + allowed_origins: convert_vec(&rule.allow_origins), + allowed_methods: convert_vec(&rule.allow_methods), + allowed_headers: convert_vec(&rule.allow_headers), expose_headers: convert_vec(&rule.expose_headers), } } @@ -227,10 +227,10 @@ where HI: Iterator, S: AsRef, { - rule.allowed_origins.iter().any(|x| x == "*" || x == origin) - && rule.allowed_methods.iter().any(|x| x == "*" || x == method) + rule.allow_origins.iter().any(|x| x == "*" || x == origin) + && rule.allow_methods.iter().any(|x| x == "*" || x == method) && request_headers.all(|h| { - rule.allowed_headers + rule.allow_headers .iter() .any(|x| x == "*" || x == h.as_ref()) }) @@ -243,15 +243,15 @@ pub fn add_cors_headers( let h = resp.headers_mut(); h.insert( ACCESS_CONTROL_ALLOW_ORIGIN, - rule.allowed_origins.join(", ").parse()?, + rule.allow_origins.join(", ").parse()?, ); h.insert( ACCESS_CONTROL_ALLOW_METHODS, - rule.allowed_methods.join(", ").parse()?, + rule.allow_methods.join(", ").parse()?, ); h.insert( ACCESS_CONTROL_ALLOW_HEADERS, - rule.allowed_headers.join(", ").parse()?, + rule.allow_headers.join(", ").parse()?, ); h.insert( ACCESS_CONTROL_EXPOSE_HEADERS, diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index 799de595..d03215b1 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -57,9 +57,9 @@ pub struct WebsiteConfig { pub struct CorsRule { pub id: Option, pub max_age_seconds: Option, - pub allowed_origins: Vec, - pub allowed_methods: Vec, - pub allowed_headers: Vec, + pub allow_origins: Vec, + pub allow_methods: Vec, + pub allow_headers: Vec, pub expose_headers: Vec, } diff --git a/src/web/web_server.rs b/src/web/web_server.rs index aefee7d1..bf330e85 100644 --- a/src/web/web_server.rs +++ b/src/web/web_server.rs @@ -210,19 +210,19 @@ async fn serve_file(garage: Arc, req: &Request) -> Result h.to_str()?.split(",").map(|h| h.trim()).collect::>(), + Some(h) => h.to_str()?.split(',').map(|h| h.trim()).collect::>(), None => vec![], }; let matching_rule = cors_config.iter().find(|rule| { cors_rule_matches( rule, - &origin, + origin, &req.method().to_string(), request_headers.iter(), ) }); if let Some(rule) = matching_rule { - add_cors_headers(&mut resp, &rule) + add_cors_headers(&mut resp, rule) .ok_or_internal_error("Invalid CORS configuration")?; } } @@ -244,21 +244,20 @@ fn handle_options(bucket: &Bucket, req: &Request) -> Result .ok_or_bad_request("Missing Access-Control-Request-Method header")? .to_str()?; let request_headers = match req.headers().get(ACCESS_CONTROL_REQUEST_HEADERS) { - Some(h) => h.to_str()?.split(",").map(|h| h.trim()).collect::>(), + Some(h) => h.to_str()?.split(',').map(|h| h.trim()).collect::>(), None => vec![], }; if let Some(cors_config) = bucket.params().unwrap().cors_config.get() { let matching_rule = cors_config .iter() - .find(|rule| cors_rule_matches(rule, &origin, &request_method, request_headers.iter())); + .find(|rule| cors_rule_matches(rule, origin, request_method, request_headers.iter())); if let Some(rule) = matching_rule { let mut resp = Response::builder() .status(StatusCode::OK) .body(Body::empty()) .map_err(ApiError::from)?; - add_cors_headers(&mut resp, &rule) - .ok_or_internal_error("Invalid CORS configuration")?; + add_cors_headers(&mut resp, rule).ok_or_internal_error("Invalid CORS configuration")?; return Ok(resp); } }