use crate::config::schema::Config;
const DEFAULT_CADDY_HTTPS_PORT: u16 = 8443;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WellKnownService {
Caddy,
Authelia,
Inbucket,
}
impl WellKnownService {
pub fn as_str(self) -> &'static str {
match self {
Self::Caddy => "caddy",
Self::Authelia => "authelia",
Self::Inbucket => "inbucket",
}
}
pub fn from_name(name: &str) -> Option<Self> {
match name {
"caddy" => Some(Self::Caddy),
"authelia" => Some(Self::Authelia),
"inbucket" => Some(Self::Inbucket),
_ => None,
}
}
pub fn matches(&self, name: &str) -> bool {
self.as_str() == name
}
}
impl std::fmt::Display for WellKnownService {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
pub(crate) fn caddy_https_port(_config: &Config) -> u16 {
crate::list_installed()
.unwrap_or_default()
.into_iter()
.find(|s| WellKnownService::Caddy.matches(&s.name))
.and_then(|s| s.ports.get("https").copied())
.unwrap_or(DEFAULT_CADDY_HTTPS_PORT)
}