Skip to main content

sova_acme/
handle.rs

1//! Shared ACME runtime handle (status + force renew).
2
3use crate::storage::CertMeta;
4use std::sync::{Arc, Mutex};
5use tokio::sync::Notify;
6
7#[derive(Debug, Clone)]
8pub struct AcmeStatus {
9    pub domains: Vec<String>,
10    pub staging: bool,
11    pub not_after_unix: Option<u64>,
12    pub last_error: Option<String>,
13    pub last_success_unix: Option<u64>,
14    pub using_placeholder: bool,
15}
16
17impl AcmeStatus {
18    pub fn from_meta(domains: &[String], staging: bool, meta: Option<&CertMeta>, placeholder: bool) -> Self {
19        Self {
20            domains: domains.to_vec(),
21            staging,
22            not_after_unix: meta.map(|m| m.not_after_unix),
23            last_error: None,
24            last_success_unix: None,
25            using_placeholder: placeholder,
26        }
27    }
28}
29
30#[derive(Clone)]
31pub struct AcmeHandle {
32    pub(crate) status: Arc<Mutex<AcmeStatus>>,
33    pub(crate) force: Arc<Notify>,
34}
35
36impl AcmeHandle {
37    pub fn status(&self) -> AcmeStatus {
38        self.status.lock().expect("acme status").clone()
39    }
40
41    /// Wake the renewer to attempt issue/renew immediately.
42    pub fn force_renew(&self) {
43        self.force.notify_one();
44    }
45}