Browse Source

Add hook groups

Some configurations may require to run the same bunch of hooks for
several domains. In order to limit repetition, it is now possible to
create a group that will reference to hooks or hook groups.
pull/5/head
Rodolphe Breard 6 years ago
parent
commit
d0bf5bfc01
  1. 1
      CHANGELOG.md
  2. 29
      acmed/src/config.rs

1
CHANGELOG.md

@ -9,3 +9,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- The `kp_reuse` flag allow to reuse a key pair instead of creating a new one at each renewal. - 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.

29
acmed/src/config.rs

@ -11,6 +11,7 @@ pub struct Config {
pub global: Option<GlobalOptions>, pub global: Option<GlobalOptions>,
pub endpoint: Vec<Endpoint>, pub endpoint: Vec<Endpoint>,
pub hook: Vec<Hook>, pub hook: Vec<Hook>,
pub group: Vec<Group>,
pub certificate: Vec<Certificate>, pub certificate: Vec<Certificate>,
} }
@ -26,10 +27,20 @@ impl Config {
account_dir.to_string() account_dir.to_string()
} }
pub fn get_hook(&self, name: &str) -> Result<Hook, Error> {
pub fn get_hook(&self, name: &str) -> Result<Vec<Hook>, Error> {
for hook in self.hook.iter() { for hook in self.hook.iter() {
if name == hook.name { 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))) Err(Error::new(&format!("{}: hook not found", name)))
@ -112,6 +123,12 @@ pub struct Hook {
pub stderr: Option<String>, pub stderr: Option<String>,
} }
#[derive(Deserialize)]
pub struct Group {
pub name: String,
pub hooks: Vec<String>,
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Certificate { pub struct Certificate {
pub email: String, pub email: String,
@ -208,8 +225,8 @@ impl Certificate {
pub fn get_challenge_hooks(&self, cnf: &Config) -> Result<Vec<Hook>, Error> { pub fn get_challenge_hooks(&self, cnf: &Config) -> Result<Vec<Hook>, Error> {
let mut res = vec![]; let mut res = vec![];
for name in self.challenge_hooks.iter() { 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) Ok(res)
} }
@ -218,8 +235,8 @@ impl Certificate {
let mut res = vec![]; let mut res = vec![];
match &self.post_operation_hook { match &self.post_operation_hook {
Some(po_hooks) => for name in po_hooks.iter() { 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 => {} None => {}
}; };

Loading…
Cancel
Save