diff --git a/CHANGELOG.md b/CHANGELOG.md index 564551e..72b1265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,3 +9,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - The `kp_reuse` flag allow to reuse a key pair instead of creating a new one at each renewal. +- It is now possible to define hook groups that can reference either hooks or other hook groups. diff --git a/acmed/src/config.rs b/acmed/src/config.rs index e66a761..8b47a72 100644 --- a/acmed/src/config.rs +++ b/acmed/src/config.rs @@ -11,6 +11,7 @@ pub struct Config { pub global: Option, pub endpoint: Vec, pub hook: Vec, + pub group: Vec, pub certificate: Vec, } @@ -26,10 +27,20 @@ impl Config { account_dir.to_string() } - pub fn get_hook(&self, name: &str) -> Result { + pub fn get_hook(&self, name: &str) -> Result, Error> { for hook in self.hook.iter() { if name == hook.name { - return Ok(hook.clone()); + return Ok(vec![hook.clone()]); + } + } + for grp in self.group.iter() { + if name == grp.name { + let mut ret = vec![]; + for hook_name in grp.hooks.iter() { + let mut h = self.get_hook(&hook_name)?; + ret.append(&mut h); + } + return Ok(ret); } } Err(Error::new(&format!("{}: hook not found", name))) @@ -112,6 +123,12 @@ pub struct Hook { pub stderr: Option, } +#[derive(Deserialize)] +pub struct Group { + pub name: String, + pub hooks: Vec, +} + #[derive(Deserialize)] pub struct Certificate { pub email: String, @@ -208,8 +225,8 @@ impl Certificate { pub fn get_challenge_hooks(&self, cnf: &Config) -> Result, Error> { let mut res = vec![]; for name in self.challenge_hooks.iter() { - let h = cnf.get_hook(&name)?; - res.push(h); + let mut h = cnf.get_hook(&name)?; + res.append(&mut h); } Ok(res) } @@ -218,8 +235,8 @@ impl Certificate { let mut res = vec![]; match &self.post_operation_hook { Some(po_hooks) => for name in po_hooks.iter() { - let h = cnf.get_hook(&name)?; - res.push(h); + let mut h = cnf.get_hook(&name)?; + res.append(&mut h); }, None => {} };