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