Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 107 additions & 138 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ authors = [
"Michael Cooper <mcooper@mozilla.com>",
"Mathieu Leplatre <mleplatre@mozilla.com>"
]
edition = "2021"
rust-version = "1.87"
edition = "2024"
rust-version = "1.89"
name = "classify-client"
version = "0.3.0"

Expand All @@ -22,7 +22,7 @@ regex = "^1.11.2"
sentry = "^0.42.0"
sentry-actix = "^0.42.0"
serde = "^1.0.219"
serde_derive = "^1.0.202"
serde_derive = "^1.0.219"
serde_json = "^1.0.143"
slog = "^2.7"
slog-async = "2.8.0"
Expand All @@ -31,7 +31,7 @@ slog-mozlog-json = "0.1.0"
slog-term = "2.9.2"
slog_derive = "0.2"
once_cell = "1.21.3"
url = "2.5.4"
url = "2.5.7"

[dependencies.chrono]
features = ["serde"]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.87-slim-bookworm as build
FROM rust:1.89-slim-bookworm as build

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build and Publish Image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
RUN apt-get update && \
apt-get install -y --no-install-recommends \
pkg-config curl libssl-dev
Expand All @@ -9,7 +9,7 @@

# -----

FROM debian:bookworm-slim as production

Check warning on line 12 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build and Publish Image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand Down
7 changes: 3 additions & 4 deletions src/endpoints/classify.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{endpoints::EndpointState, errors::ClassifyError, utils::RequestClientIp};
use actix_web::{http, web::Data, HttpRequest, HttpResponse};
use actix_web::{HttpRequest, HttpResponse, http, web::Data};
use chrono::{DateTime, Utc};
use maxminddb::{self, geoip2};
use serde::Serializer;
Expand Down Expand Up @@ -62,14 +62,13 @@ pub async fn classify_client(
mod tests {
use crate::{endpoints::EndpointState, geoip::GeoIp};
use actix_web::{
http,
App, http,
test::{self, TestRequest},
web::{self, Data},
App,
};
use chrono::DateTime;
use maxminddb::geoip2;
use serde_json::{json, Value};
use serde_json::{Value, json};
use std::{collections::HashSet, sync::Arc};

#[actix_rt::test]
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/country.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{endpoints::EndpointState, errors::ClassifyError, utils::RequestClientIp};
use actix_web::{http, web::Data, web::Query, HttpRequest, HttpResponse};
use actix_web::{HttpRequest, HttpResponse, http, web::Data, web::Query};
use cadence::prelude::*;
use once_cell::sync::Lazy;
use regex::Regex;
Expand Down Expand Up @@ -114,9 +114,9 @@ pub async fn get_country(
mod tests {
use crate::{endpoints::EndpointState, geoip::GeoIp, metrics::tests::TestMetricSink};
use actix_web::{
App,
test::{self, TestRequest},
web::{self, Data},
App,
};
use cadence::StatsdClient;
use serde_json::{self, json};
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/debug.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{endpoints::EndpointState, utils::RequestClientIp};
use actix_web::{web::Data, HttpRequest, HttpResponse};
use actix_web::{HttpRequest, HttpResponse, web::Data};

/// Show debugging information about the server comprising:
///
Expand Down
5 changes: 2 additions & 3 deletions src/endpoints/dockerflow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{endpoints::EndpointState, errors::ClassifyError};
use actix_web::{web::Data, HttpResponse};
use actix_web::{HttpResponse, web::Data};
use serde_derive::Serialize;
use std::{
fs::File,
Expand Down Expand Up @@ -55,10 +55,9 @@ pub async fn version(app_data: Data<EndpointState>) -> HttpResponse {
mod tests {
use crate::endpoints::EndpointState;
use actix_web::{
http,
App, http,
test::{self, TestRequest},
web::{self, Data},
App,
};

#[actix_rt::test]
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod classify;
pub mod country;
pub mod debug;
pub mod dockerflow;
use crate::{geoip::GeoIp, APP_NAME};
use crate::{APP_NAME, geoip::GeoIp};
use std::{collections::HashSet, default::Default, path::PathBuf, sync::Arc};

#[derive(Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/geoip.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::errors::ClassifyError;
use cadence::{prelude::*, StatsdClient};
use maxminddb::{self, geoip2, MaxMindDbError};
use cadence::{StatsdClient, prelude::*};
use maxminddb::{self, MaxMindDbError, geoip2};
use std::{fmt, net::IpAddr, path::PathBuf, sync::Arc};

pub struct GeoIp {
Expand Down
28 changes: 15 additions & 13 deletions src/keys.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde_json::{from_str, Value};
use serde_json::{Value, from_str};
use slog::Logger;
use std::collections::HashSet;
use std::fs::read_to_string;
Expand Down Expand Up @@ -75,21 +75,23 @@ mod tests {
// tests
let missing_set = load(missing_file.clone(), logger.clone());
assert!(missing_set.is_empty());
assert!(logs
.lock()
.unwrap()
.pop()
.unwrap()
.starts_with("ERRO / Error reading api keys file"));
assert!(
logs.lock()
.unwrap()
.pop()
.unwrap()
.starts_with("ERRO / Error reading api keys file")
);

let corrupt_set = load(corrupt_file.clone(), logger.clone());
assert!(corrupt_set.is_empty());
assert!(logs
.lock()
.unwrap()
.pop()
.unwrap()
.starts_with("ERRO / Error parsing api keys file"));
assert!(
logs.lock()
.unwrap()
.pop()
.unwrap()
.starts_with("ERRO / Error parsing api keys file")
);

let good_set = load(good_file.clone(), logger.clone());
assert!(good_set.len() == 1);
Expand Down
6 changes: 3 additions & 3 deletions src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use actix_web::{
Error, HttpRequest, HttpResponse,
dev::{Service, ServiceRequest, ServiceResponse, Transform},
web::Data,
Error, HttpRequest, HttpResponse,
};
use futures::{future, Future, FutureExt};
use futures::{Future, FutureExt, future};
use slog::{self, Drain};
use slog_derive::KV;
use slog_mozlog_json::MozLogJson;
Expand Down Expand Up @@ -132,7 +132,7 @@ where
#[cfg(test)]
mod tests {
use crate::logging::MozLogFields;
use actix_web::{http, test, HttpResponse};
use actix_web::{HttpResponse, http, test};

#[test]
async fn test_request_fields() {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub mod settings;
pub mod utils;

use crate::{
endpoints::{canned, classify, country, debug, dockerflow, EndpointState},
endpoints::{EndpointState, canned, classify, country, debug, dockerflow},
errors::ClassifyError,
geoip::GeoIp,
settings::Settings,
};
use actix_web::{
web::{self, Data},
App,
web::{self, Data},
};
use std::sync::Arc;

Expand Down
10 changes: 5 additions & 5 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{endpoints::EndpointState, errors::ClassifyError, APP_NAME};
use crate::{APP_NAME, endpoints::EndpointState, errors::ClassifyError};
use actix_web::{
Error,
dev::{Service, ServiceRequest, ServiceResponse, Transform},
web::Data,
Error,
};
use cadence::{prelude::*, BufferedUdpMetricSink, StatsdClient};
use futures::{future, Future, FutureExt};
use cadence::{BufferedUdpMetricSink, StatsdClient, prelude::*};
use futures::{Future, FutureExt, future};
use std::{
fmt::Display,
net::{ToSocketAddrs, UdpSocket},
Expand Down Expand Up @@ -118,9 +118,9 @@ pub mod tests {
use super::*;
use crate::endpoints::EndpointState;
use actix_web::{
App, HttpResponse,
test::{self, TestRequest},
web::{self, Data},
App, HttpResponse,
};
use cadence::StatsdClient;
use regex::Regex;
Expand Down
8 changes: 5 additions & 3 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ mod tests {

#[test]
fn test_override_via_env_vars() {
env::set_var("DEBUG", "true");
env::set_var("PORT", "8888");
env::set_var("TRUSTED_PROXY_LIST", "2001:db8::/48,192.168.100.14/24");
unsafe {
env::set_var("DEBUG", "true");
env::set_var("PORT", "8888");
env::set_var("TRUSTED_PROXY_LIST", "2001:db8::/48,192.168.100.14/24");
}

let settings = Settings::load().unwrap();

Expand Down
16 changes: 8 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{endpoints::EndpointState, errors::ClassifyError};
use actix_web::{web::Data, HttpRequest};
use actix_web::{HttpRequest, web::Data};
use std::net::IpAddr;

pub trait RequestClientIp<S> {
Expand Down Expand Up @@ -43,13 +43,13 @@ impl<'a> RequestTraceIps<'a> for HttpRequest {
trace.push(peer_addr.ip());
}

if let Some(x_forwarded_for) = self.headers().get("X-Forwarded-For") {
if let Ok(header) = x_forwarded_for.to_str() {
let mut header_ips: Vec<IpAddr> =
header.split(',').flat_map(|ip| ip.trim().parse()).collect();
header_ips.reverse();
trace.append(&mut header_ips);
}
if let Some(x_forwarded_for) = self.headers().get("X-Forwarded-For")
&& let Ok(header) = x_forwarded_for.to_str()
{
let mut header_ips: Vec<IpAddr> =
header.split(',').flat_map(|ip| ip.trim().parse()).collect();
header_ips.reverse();
trace.append(&mut header_ips);
}

trace
Expand Down