From 7694c4f1facf3fff1e57f66c488d52f865dcc11a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Tue, 24 Dec 2024 14:42:08 +0100 Subject: [PATCH] Use a table of table for the rate limits --- config/20_letsencrypt.toml | 7 +++---- man/en/acmed.toml.5 | 4 +--- src/config.rs | 2 +- src/config/rate_limit.rs | 16 ---------------- 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/config/20_letsencrypt.toml b/config/20_letsencrypt.toml index 18c5ac8..ac3c1b5 100644 --- a/config/20_letsencrypt.toml +++ b/config/20_letsencrypt.toml @@ -1,14 +1,13 @@ -[[rate-limit]] -name = "Let's Encrypt rate-limit" +[[rate-limit."letsencrypt-v2"]] number = 20 period = "1s" [endpoint."letsencrypt-v2-production"] url = "https://acme-v02.api.letsencrypt.org/directory" -rate_limits = ["Let's Encrypt rate-limit"] +rate_limits = ["letsencrypt-v2"] tos_agreed = false [endpoint."letsencrypt-v2-staging"] url = "https://acme-staging-v02.api.letsencrypt.org/directory" -rate_limits = ["Let's Encrypt rate-limit"] +rate_limits = ["letsencrypt-v2"] tos_agreed = false diff --git a/man/en/acmed.toml.5 b/man/en/acmed.toml.5 index 8a0b569..33747ee 100644 --- a/man/en/acmed.toml.5 +++ b/man/en/acmed.toml.5 @@ -381,10 +381,8 @@ post-operation .El .El .It Ic rate-limit -Array of table where each element defines a HTTPS rate limit. +Table of table where each element defines a HTTPS rate limit. .Bl -tag -.It Cm name Ar string -The name the rate limit is registered under. Must be unique. .It Cm number Ar integer Number of requests authorized withing the time period. .It Cm period Ar string diff --git a/src/config.rs b/src/config.rs index 10b903d..5538bfc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -30,7 +30,7 @@ pub struct AcmedConfig { #[serde(default)] pub(in crate::config) endpoint: HashMap, #[serde(default, rename = "rate-limit")] - pub(in crate::config) rate_limit: Vec, + pub(in crate::config) rate_limit: HashMap, #[serde(default)] pub(in crate::config) hook: Vec, #[serde(default)] diff --git a/src/config/rate_limit.rs b/src/config/rate_limit.rs index f2557aa..ea211e8 100644 --- a/src/config/rate_limit.rs +++ b/src/config/rate_limit.rs @@ -4,7 +4,6 @@ use serde_derive::Deserialize; #[derive(Clone, Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct RateLimit { - pub(in crate::config) name: String, pub(in crate::config) number: usize, pub(in crate::config) period: Duration, } @@ -23,32 +22,18 @@ mod tests { #[test] fn ok() { let cfg = r#" -name = "test" number = 20 period = "20s" "#; let rl: RateLimit = load_str(cfg).unwrap(); - assert_eq!(rl.name, "test"); assert_eq!(rl.number, 20); assert_eq!(rl.period, Duration::from_secs(20)); } - #[test] - fn missing_name() { - let cfg = r#" -number = 20 -period = "20s" -"#; - - let res = load_str::(cfg); - assert!(res.is_err()); - } - #[test] fn missing_number() { let cfg = r#" -name = "test" period = "20s" "#; @@ -59,7 +44,6 @@ period = "20s" #[test] fn missing_period() { let cfg = r#" -name = "test" number = 20 "#;