credence_lib/configuration/port/
host.rs1use super::{super::error::*, acme::*, key::*};
2
3use {
4 compris::resolve::*,
5 kutil::{cli::depict::*, std::immutable::*},
6 std::path::*,
7};
8
9#[derive(Clone, Debug, Default, Depict, Resolve)]
15pub struct Host {
16 #[resolve(single)]
18 #[depict(style(string))]
19 pub name: ByteString,
20
21 #[resolve(key = "redirect-to")]
23 #[depict(option, style(number))]
24 pub redirect_to: Option<u16>,
25
26 #[resolve]
28 #[depict(option, as(depict))]
29 pub key: Option<Key>,
30
31 #[resolve]
33 #[depict(option, as(depict))]
34 pub acme: Option<ACME>,
35}
36
37impl Host {
38 pub fn validate<PathT>(&mut self, base_path: PathT) -> Result<(), ConfigurationError>
40 where
41 PathT: AsRef<Path>,
42 {
43 if self.key.is_some() && self.acme.is_some() {
44 return Err("host cannot have both `key` and `acme`".into());
45 }
46
47 let base_path = base_path.as_ref();
48
49 if let Some(key) = &mut self.key {
50 key.validate(base_path)?;
51 }
52
53 if let Some(acme) = &mut self.acme {
54 acme.validate(base_path)?;
55 }
56
57 Ok(())
58 }
59
60 pub fn has_tls(&self) -> bool {
62 self.key.is_some() || self.acme.is_some()
63 }
64}