Update to Rust 1.52 and fix clippy lints

This commit is contained in:
Michael Cooper 2021-05-13 14:39:14 -07:00
Родитель a6c6ee8229
Коммит 553e06cf9a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 9424CEA6F89AB334
7 изменённых файлов: 16 добавлений и 24 удалений

Просмотреть файл

@ -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:

Просмотреть файл

@ -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 \

Просмотреть файл

@ -42,16 +42,16 @@ pub fn classify_client(req: HttpRequest) -> Result<HttpResponse, ClassifyError>
.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))
}

Просмотреть файл

@ -26,18 +26,18 @@ pub fn heartbeat(app_data: Data<EndpointState>) -> Result<HttpResponse, Classify
Some(country_info) => 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 })
})
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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(

Просмотреть файл

@ -29,8 +29,7 @@ impl RequestClientIp<EndpointState> 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)
}