credence_lib/configuration/port/
acme.rs

1use super::super::error::*;
2
3use {
4    compris::resolve::*,
5    kutil::{
6        cli::depict::*,
7        http::tls::{ACME as KutilACME, *},
8        std::immutable::*,
9    },
10    std::path::*,
11};
12
13//
14// ACME
15//
16
17/// TLS ACME.
18#[derive(Clone, Debug, Depict, Resolve)]
19pub struct ACME {
20    /// ACME directory URI.
21    #[resolve]
22    #[depict(style(string))]
23    pub directory: ByteString,
24
25    /// Contacts (usually email addresses).
26    #[resolve(required)]
27    #[depict(iter(item), style(string))]
28    pub contacts: Vec<ByteString>,
29
30    /// Cache.
31    #[resolve]
32    #[depict(as(debug), style(string))]
33    pub cache: PathBuf,
34}
35
36impl ACME {
37    /// Validate.
38    pub fn validate<PathT>(&mut self, base_path: PathT) -> Result<(), ConfigurationError>
39    where
40        PathT: AsRef<Path>,
41    {
42        if !self.cache.is_absolute() {
43            self.cache = base_path.as_ref().join(&self.cache);
44        }
45
46        Ok(())
47    }
48
49    /// Create [ACME](KutilACME).
50    pub fn provider(&self, host: ByteString) -> KutilACME {
51        KutilACME {
52            hosts: vec![host],
53            directory: self.directory.clone(),
54            contacts: self.contacts.clone(),
55            cache: self.cache.clone(),
56        }
57    }
58}
59
60impl Default for ACME {
61    fn default() -> Self {
62        Self { directory: LETS_ENCRYPT_STAGING_DIRECTORY.into(), contacts: Default::default(), cache: "acme".into() }
63    }
64}