From 553e06cf9a1504a213d3627cccc3e7b265afbc47 Mon Sep 17 00:00:00 2001 From: Michael Cooper Date: Thu, 13 May 2021 14:39:14 -0700 Subject: [PATCH] Update to Rust 1.52 and fix clippy lints --- .circleci/config.yml | 8 ++++---- Dockerfile | 4 ++-- src/endpoints/classify.rs | 6 +++--- src/endpoints/dockerflow.rs | 8 ++++---- src/logging.rs | 2 -- src/main.rs | 9 ++------- src/utils.rs | 3 +-- 7 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a49cfd..1b586d8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ version: 2.1 jobs: test: docker: - - image: mozilla/cidockerbases:rust-2019-10-17 + - image: mozilla/cidockerbases:rust-2021-05-12 steps: - checkout - run: @@ -22,7 +22,7 @@ jobs: lint: docker: - - image: mozilla/cidockerbases:rust-2019-10-17 + - image: mozilla/cidockerbases:rust-2021-05-12 steps: - checkout - run: @@ -40,7 +40,7 @@ jobs: build: docker: - - image: mozilla/cidockerbases:docker-2019-10-17 + - image: mozilla/cidockerbases:docker-2021-05-12 working_directory: /dockerflow steps: - checkout @@ -72,7 +72,7 @@ jobs: publish: docker: - - image: mozilla/cidockerbases:docker-2019-10-17 + - image: mozilla/cidockerbases:docker-2021-05-12 steps: - setup_remote_docker - restore_cache: diff --git a/Dockerfile b/Dockerfile index bc825b2..b407412 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.40-slim-stretch as build +FROM rust:1.52-slim-buster as build RUN apt-get update && \ apt-get install -y --no-install-recommends \ pkg-config curl libssl-dev @@ -9,7 +9,7 @@ RUN cargo build --release # ----- -FROM debian:stretch-slim as production +FROM debian:buster-slim as production RUN apt-get update && \ apt-get install -y --no-install-recommends \ diff --git a/src/endpoints/classify.rs b/src/endpoints/classify.rs index 41ab245..476e4cd 100644 --- a/src/endpoints/classify.rs +++ b/src/endpoints/classify.rs @@ -42,16 +42,16 @@ pub fn classify_client(req: HttpRequest) -> Result .expect("Could not get app state") .geoip .locate(req.client_ip()?) - .and_then(move |country| { + .map(move |country| { let mut response = HttpResponse::Ok(); response.header( http::header::CACHE_CONTROL, "max-age=0, no-cache, no-store, must-revalidate", ); - Ok(response.json(ClientClassification { + response.json(ClientClassification { country, ..Default::default() - })) + }) }) .map_err(|err| ClassifyError::from_source("Future failure", err)) } diff --git a/src/endpoints/dockerflow.rs b/src/endpoints/dockerflow.rs index 09bf432..f6e1d62 100644 --- a/src/endpoints/dockerflow.rs +++ b/src/endpoints/dockerflow.rs @@ -26,18 +26,18 @@ pub fn heartbeat(app_data: Data) -> Result country_info .country .and_then(|country| country.iso_code) - .and_then(|iso_code| Some(Ok(!iso_code.is_empty()))) + .map(|iso_code| Ok(!iso_code.is_empty())) .unwrap_or(Ok(false)), None => Ok(false), }) - .or_else(|_| Ok(false)) - .and_then(|res| { + .or(Ok(false)) + .map(|res| { let mut resp = if res { HttpResponse::Ok() } else { HttpResponse::ServiceUnavailable() }; - Ok(resp.json(HeartbeatResponse { geoip: res })) + resp.json(HeartbeatResponse { geoip: res }) }) } diff --git a/src/logging.rs b/src/logging.rs index d9765e7..4c2765c 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -4,10 +4,8 @@ use actix_web::{ }; use futures::{future, Future, Poll}; use slog::{self, Drain}; -use slog_async; use slog_derive::KV; use slog_mozlog_json::MozLogJson; -use slog_term; use std::io; use crate::endpoints::EndpointState; diff --git a/src/main.rs b/src/main.rs index e8205cb..4e0a3a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ use crate::{ settings::Settings, }; use actix_web::{web, App}; -use slog; use std::sync::Arc; const APP_NAME: &str = "classify-client"; @@ -37,12 +36,8 @@ fn main() -> Result<(), ClassifyError> { let app_log = logging::get_logger("app", human_logs); - let metrics = metrics::get_client(metrics_target, app_log.clone()).unwrap_or_else(|err| { - panic!(format!( - "Critical failure setting up metrics logging: {}", - err - )) - }); + let metrics = metrics::get_client(metrics_target, app_log.clone()) + .unwrap_or_else(|err| panic!("Critical failure setting up metrics logging: {}", err)); let state = EndpointState { geoip: Arc::new( diff --git a/src/utils.rs b/src/utils.rs index db8f2e6..7c0c8ee 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -29,8 +29,7 @@ impl RequestClientIp for HttpRequest { self.trace_ips() .iter() - .skip_while(is_trusted_ip) - .next() + .find(|ip| !is_trusted_ip(ip)) .ok_or_else(|| ClassifyError::new("Could not determine IP")) .map(|ip| *ip) }