refactor(svc): tidy the rust services and build tooling (#2735)

This commit is contained in:
Hampus authored and GitHub committed 2026-09-13 17:38:32 +02:00
1 parent 33737e0f79
commit 6af33c7188
41 files changed
+863 -1304

No files matched your search

+6 -6
View File
@@ -203,12 +203,12 @@ fn is_default_port(scheme: &str, port: u16) -> bool {
)
}
fn strip_trailing_dot(host: &str) -> &str {
host.strip_suffix('.').unwrap_or(host)
}
fn canonicalize_domain(value: &str) -> String {
strip_trailing_dot(value.trim().to_lowercase().as_str()).to_owned()
let mut domain = value.trim().to_lowercase();
if domain.ends_with('.') {
domain.pop();
}
domain
}
fn default_port(scheme: &str) -> u16 {
@@ -285,10 +285,10 @@ where
}
pub fn normalize_public_endpoint(url: &str, base_domain: &str, public_port: Option<u16>) -> String {
let domain = canonicalize_domain(base_domain);
let Some(port) = public_port.filter(|port| *port != 0) else {
return url.to_owned();
};
let domain = canonicalize_domain(base_domain);
if domain.is_empty() {
return url.to_owned();
}
+3 -20
View File
@@ -19,7 +19,6 @@ use std::{
path::Path,
time::{Duration, SystemTime},
};
use time::OffsetDateTime;
const DEFAULT_COUNTRY_CODE: &str = "US";
const GEOIP_CACHE_TTL: Duration = Duration::from_secs(10 * 60);
@@ -242,7 +241,6 @@ fn download_s3_object(
);
};
fs::create_dir_all(parent)?;
let temp_path = temporary_download_path(destination);
let request = signed_s3_get_request(config, bucket, key)?;
let mut response = reqwest::blocking::Client::new()
.get(request.url)
@@ -253,29 +251,14 @@ fn download_s3_object(
})?;
if !response.status().is_success() {
let status = response.status();
let _ = fs::remove_file(&temp_path);
anyhow::bail!("failed to download GeoIP database from s3://{bucket}/{key}: HTTP {status}");
}
{
let mut file = File::create(&temp_path)?;
io::copy(&mut response, &mut file)?;
}
fs::rename(&temp_path, destination).inspect_err(|_err| {
let _ = fs::remove_file(&temp_path);
})?;
let mut file = tempfile::Builder::new().make_in(parent, |path| File::create_new(path))?;
io::copy(&mut response, &mut file)?;
file.persist(destination).map_err(|err| err.error)?;
Ok(())
}
fn temporary_download_path(destination: &Path) -> std::path::PathBuf {
let pid = std::process::id();
let now = OffsetDateTime::now_utc().unix_timestamp_nanos();
let file_name = destination
.file_name()
.and_then(|value| value.to_str())
.unwrap_or("geoip.mmdb");
destination.with_file_name(format!("{file_name}.tmp-{pid}-{now}"))
}
struct SignedS3Request {
url: reqwest::Url,
headers: reqwest::header::HeaderMap,