use secrecy::SecretString;
use url::Url;
#[derive(Debug, Clone)]
pub enum AuthCredentials {
ApiKey(SecretString),
Credentials {
username: String,
password: SecretString,
},
Hybrid {
api_key: SecretString,
username: String,
password: SecretString,
},
Cloud {
api_key: SecretString,
host_id: String,
},
}
#[derive(Debug, Clone, Default)]
pub enum TlsVerification {
SystemDefaults,
CustomCa(std::path::PathBuf),
#[default]
DangerAcceptInvalid,
}
impl PartialEq for TlsVerification {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::CustomCa(a), Self::CustomCa(b)) => a == b,
(Self::SystemDefaults, Self::SystemDefaults)
| (Self::DangerAcceptInvalid, Self::DangerAcceptInvalid) => true,
_ => false,
}
}
}
impl Eq for TlsVerification {}
#[derive(Debug, Clone)]
pub struct ControllerConfig {
pub url: Url,
pub auth: AuthCredentials,
pub site: String,
pub tls: TlsVerification,
pub timeout: std::time::Duration,
pub refresh_interval_secs: u64,
pub websocket_enabled: bool,
pub polling_interval_secs: u64,
pub totp_token: Option<SecretString>,
pub profile_name: Option<String>,
pub no_session_cache: bool,
}
impl Default for ControllerConfig {
fn default() -> Self {
Self {
url: "https://192.168.1.1:8443"
.parse()
.expect("default controller URL is valid"),
auth: AuthCredentials::Credentials {
username: "admin".into(),
password: SecretString::from(String::new()),
},
site: "default".into(),
tls: TlsVerification::default(),
timeout: std::time::Duration::from_secs(30),
refresh_interval_secs: 300,
websocket_enabled: true,
polling_interval_secs: 10,
totp_token: None,
profile_name: None,
no_session_cache: false,
}
}
}