Parse config values with humanize-rs

This commit is contained in:
Joscha 2023-08-17 00:40:29 +02:00
parent a54e842478
commit ca6a6be638
3 changed files with 27 additions and 16 deletions

28
Cargo.lock generated
View file

@ -1732,6 +1732,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humanize-rs"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "016b02deb8b0c415d8d56a6f0ab265e50c22df61194e37f9be75ed3a722de8a6"
[[package]] [[package]]
name = "humansize" name = "humansize"
version = "2.1.3" version = "2.1.3"
@ -1747,16 +1753,6 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "humantime-serde"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57a3db5ea5923d99402c94e9feb261dc5ee9b4efa158b0315f788cf549cc200c"
dependencies = [
"humantime",
"serde",
]
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.27" version = "0.14.27"
@ -2692,6 +2688,16 @@ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]]
name = "serde-humanize-rs"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32dda2253dd72722af02a6c2140dc32d247a54c8ac9b792708b8f9a0303c2cd"
dependencies = [
"humanize-rs",
"serde",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.181" version = "1.0.181"
@ -3177,7 +3183,6 @@ dependencies = [
"gethostname", "gethostname",
"gix", "gix",
"humantime", "humantime",
"humantime-serde",
"mime_guess", "mime_guess",
"open", "open",
"rand", "rand",
@ -3185,6 +3190,7 @@ dependencies = [
"reqwest", "reqwest",
"rust-embed", "rust-embed",
"serde", "serde",
"serde-humanize-rs",
"serde_repr", "serde_repr",
"sqlx", "sqlx",
"tar", "tar",

View file

@ -16,13 +16,13 @@ flate2 = "1.0.26"
futures = "0.3.28" futures = "0.3.28"
gethostname = "0.4.3" gethostname = "0.4.3"
humantime = "2.1.0" humantime = "2.1.0"
humantime-serde = "1.1.1"
mime_guess = "2.0.4" mime_guess = "2.0.4"
open = "5.0.0" open = "5.0.0"
rand = "0.8.5" rand = "0.8.5"
regex = "1.9.3" regex = "1.9.3"
rust-embed = { version = "6.8.1", features = ["interpolate-folder-path"] } rust-embed = { version = "6.8.1", features = ["interpolate-folder-path"] }
serde = { version = "1.0.181", features = ["derive"] } serde = { version = "1.0.181", features = ["derive"] }
serde-humanize-rs = "0.1.1"
serde_repr = "0.1.16" serde_repr = "0.1.16"
sqlx = { version = "0.7.1", features = ["runtime-tokio", "sqlite", "time"] } sqlx = { version = "0.7.1", features = ["runtime-tokio", "sqlite", "time"] }
tar = { version = "0.4.40", default-features = false } tar = { version = "0.4.40", default-features = false }

View file

@ -15,9 +15,10 @@ use crate::{
#[serde(default)] #[serde(default)]
struct RawServerRepo { struct RawServerRepo {
name: Option<String>, name: Option<String>,
#[serde(with = "serde_humanize_rs")]
update: Duration, update: Duration,
fetch_refs: Vec<String>,
fetch_url: Option<String>, fetch_url: Option<String>,
fetch_refspecs: Vec<String>,
} }
impl Default for RawServerRepo { impl Default for RawServerRepo {
@ -25,8 +26,8 @@ impl Default for RawServerRepo {
Self { Self {
name: None, name: None,
update: Duration::from_secs(60), update: Duration::from_secs(60),
fetch_refs: vec!["+refs/*:refs/*".to_string()],
fetch_url: None, fetch_url: None,
fetch_refspecs: vec!["+refs/*:refs/*".to_string()],
} }
} }
} }
@ -51,7 +52,9 @@ impl Default for RawServerWeb {
#[serde(default)] #[serde(default)]
struct RawServerWorker { struct RawServerWorker {
token: Option<String>, token: Option<String>,
#[serde(with = "serde_humanize_rs")]
timeout: Duration, timeout: Duration,
#[serde(with = "serde_humanize_rs")]
upload: usize, upload: usize,
} }
@ -83,7 +86,9 @@ struct RawWorkerServer {
#[serde(default)] #[serde(default)]
struct RawWorker { struct RawWorker {
name: Option<String>, name: Option<String>,
#[serde(with = "serde_humanize_rs")]
ping: Duration, ping: Duration,
#[serde(with = "serde_humanize_rs")]
batch: Duration, batch: Duration,
servers: HashMap<String, RawWorkerServer>, servers: HashMap<String, RawWorkerServer>,
} }
@ -110,7 +115,7 @@ struct RawConfig {
pub struct ServerConfig { pub struct ServerConfig {
pub repo_name: String, pub repo_name: String,
pub repo_update: Duration, pub repo_update: Duration,
pub repo_fetch_refs: Vec<String>, pub repo_fetch_refspecs: Vec<String>,
pub repo_fetch_url: Option<String>, pub repo_fetch_url: Option<String>,
pub web_address: SocketAddr, pub web_address: SocketAddr,
/// Always ends without a `/`. /// Always ends without a `/`.
@ -162,8 +167,8 @@ impl ServerConfig {
Self { Self {
repo_name, repo_name,
repo_update: raw.repo.update, repo_update: raw.repo.update,
repo_fetch_refs: raw.repo.fetch_refs,
repo_fetch_url: raw.repo.fetch_url, repo_fetch_url: raw.repo.fetch_url,
repo_fetch_refspecs: raw.repo.fetch_refspecs,
web_address: raw.web.address, web_address: raw.web.address,
web_base, web_base,
worker_token, worker_token,