Browse Source

Add the is_success variable to post-operation hooks

pull/5/head
Rodolphe Breard 6 years ago
parent
commit
2d5e3969e1
  1. 1
      CHANGELOG.md
  2. 3
      acmed/src/certificate.rs
  3. 1
      acmed/src/hooks.rs
  4. 9
      acmed/src/main_event_loop.rs
  5. 10
      man/en/acmed.toml.5

1
CHANGELOG.md

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Man pages.
- The project can now be built and installed using `make`.
- The post-operation hooks now have access to the `is_success` template variable.
### Changed
- Unknown configuration fields are no longer tolerated.

3
acmed/src/certificate.rs

@ -164,7 +164,7 @@ impl Certificate {
hooks::call(data, &self.hooks, hook_type)
}
pub fn call_post_operation_hooks(&self, status: &str) -> Result<(), Error> {
pub fn call_post_operation_hooks(&self, status: &str, is_success: bool) -> Result<(), Error> {
let domains = self
.domains
.iter()
@ -174,6 +174,7 @@ impl Certificate {
domains,
algorithm: self.algo.to_string(),
status: status.to_string(),
is_success,
};
hooks::call(&hook_data, &self.hooks, HookType::PostOperation)?;
Ok(())

1
acmed/src/hooks.rs

@ -14,6 +14,7 @@ pub struct PostOperationHookData {
pub domains: Vec<String>,
pub algorithm: String,
pub status: String,
pub is_success: bool,
}
#[derive(Serialize)]

9
acmed/src/main_event_loop.rs

@ -57,8 +57,9 @@ impl MainEventLoop {
match crt.should_renew() {
Ok(sr) => {
if sr {
let status = match request_certificate(crt, &self.root_certs) {
Ok(_) => "Success.".to_string(),
let (status, is_success) =
match request_certificate(crt, &self.root_certs) {
Ok(_) => ("Success.".to_string(), true),
Err(e) => {
let msg = format!(
"Unable to renew the {} certificate for {}: {}",
@ -67,10 +68,10 @@ impl MainEventLoop {
e
);
warn!("{}", msg);
format!("Failed: {}", msg)
(format!("Failed: {}", msg), false)
}
};
match crt.call_post_operation_hooks(&status) {
match crt.call_post_operation_hooks(&status, is_success) {
Ok(_) => {}
Err(e) => {
let msg = format!(

10
man/en/acmed.toml.5

@ -317,9 +317,9 @@ Array containing the domain names included in the requested certificate.
.It Cm algorithm Ar string
Name of the algorithm used in the certificate.
.It Cm status Ar string
Status of request. Is set to
.Dq Success.
in case the operation succeeded, in an error description otherwise.
Human-readable status. If the certificate request failed, it contains the error description.
.It Cm is_success Ar boolean
True if the certificate request is successful.
.El
.El
.Sh FILES
@ -432,9 +432,9 @@ args = [
"-f", "noreply.certs@example.net",
"contact@example.net"
]
stdin = """Subject: Certificate renewal alert for {{domains.[0]}}
stdin = """Subject: Certificate renewal {{#if is_success}}succeeded{{else}}failed{{/if}} for {{domains.[0]}}
The following certificate has been renewed.
The following certificate has {{#unless is_success}}*not* {{/if}}been renewed.
domains: {{#each domains}}{{#if @index}}, {{/if}}{{this}}{{/each}}
algorithm: {{algorithm}}
status: {{status}}"""

Loading…
Cancel
Save