Browse Source

Use a table of table for the rate limits

ng
Rodolphe Bréard 4 weeks ago
parent
commit
7694c4f1fa
Failed to extract signature
  1. 7
      config/20_letsencrypt.toml
  2. 4
      man/en/acmed.toml.5
  3. 2
      src/config.rs
  4. 16
      src/config/rate_limit.rs

7
config/20_letsencrypt.toml

@ -1,14 +1,13 @@
[[rate-limit]]
name = "Let's Encrypt rate-limit"
[[rate-limit."letsencrypt-v2"]]
number = 20 number = 20
period = "1s" period = "1s"
[endpoint."letsencrypt-v2-production"] [endpoint."letsencrypt-v2-production"]
url = "https://acme-v02.api.letsencrypt.org/directory" url = "https://acme-v02.api.letsencrypt.org/directory"
rate_limits = ["Let's Encrypt rate-limit"]
rate_limits = ["letsencrypt-v2"]
tos_agreed = false tos_agreed = false
[endpoint."letsencrypt-v2-staging"] [endpoint."letsencrypt-v2-staging"]
url = "https://acme-staging-v02.api.letsencrypt.org/directory" url = "https://acme-staging-v02.api.letsencrypt.org/directory"
rate_limits = ["Let's Encrypt rate-limit"]
rate_limits = ["letsencrypt-v2"]
tos_agreed = false tos_agreed = false

4
man/en/acmed.toml.5

@ -381,10 +381,8 @@ post-operation
.El .El
.El .El
.It Ic rate-limit .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 .Bl -tag
.It Cm name Ar string
The name the rate limit is registered under. Must be unique.
.It Cm number Ar integer .It Cm number Ar integer
Number of requests authorized withing the time period. Number of requests authorized withing the time period.
.It Cm period Ar string .It Cm period Ar string

2
src/config.rs

@ -30,7 +30,7 @@ pub struct AcmedConfig {
#[serde(default)] #[serde(default)]
pub(in crate::config) endpoint: HashMap<String, Endpoint>, pub(in crate::config) endpoint: HashMap<String, Endpoint>,
#[serde(default, rename = "rate-limit")] #[serde(default, rename = "rate-limit")]
pub(in crate::config) rate_limit: Vec<RateLimit>,
pub(in crate::config) rate_limit: HashMap<String, RateLimit>,
#[serde(default)] #[serde(default)]
pub(in crate::config) hook: Vec<Hook>, pub(in crate::config) hook: Vec<Hook>,
#[serde(default)] #[serde(default)]

16
src/config/rate_limit.rs

@ -4,7 +4,6 @@ use serde_derive::Deserialize;
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct RateLimit { pub struct RateLimit {
pub(in crate::config) name: String,
pub(in crate::config) number: usize, pub(in crate::config) number: usize,
pub(in crate::config) period: Duration, pub(in crate::config) period: Duration,
} }
@ -23,32 +22,18 @@ mod tests {
#[test] #[test]
fn ok() { fn ok() {
let cfg = r#" let cfg = r#"
name = "test"
number = 20 number = 20
period = "20s" period = "20s"
"#; "#;
let rl: RateLimit = load_str(cfg).unwrap(); let rl: RateLimit = load_str(cfg).unwrap();
assert_eq!(rl.name, "test");
assert_eq!(rl.number, 20); assert_eq!(rl.number, 20);
assert_eq!(rl.period, Duration::from_secs(20)); assert_eq!(rl.period, Duration::from_secs(20));
} }
#[test]
fn missing_name() {
let cfg = r#"
number = 20
period = "20s"
"#;
let res = load_str::<RateLimit>(cfg);
assert!(res.is_err());
}
#[test] #[test]
fn missing_number() { fn missing_number() {
let cfg = r#" let cfg = r#"
name = "test"
period = "20s" period = "20s"
"#; "#;
@ -59,7 +44,6 @@ period = "20s"
#[test] #[test]
fn missing_period() { fn missing_period() {
let cfg = r#" let cfg = r#"
name = "test"
number = 20 number = 20
"#; "#;

Loading…
Cancel
Save