ids_daps_client/
config.rsuse std::borrow::Cow;
#[derive(Debug, derive_builder::Builder)]
#[builder(setter(into), build_fn(validate = "Self::validate"))]
pub struct DapsConfig<'a> {
pub(super) token_url: Cow<'a, str>,
pub(super) certs_url: Cow<'a, str>,
pub(super) private_key: Cow<'a, std::path::Path>,
pub(super) private_key_password: Option<Cow<'a, str>>,
pub(super) scope: Cow<'a, str>,
pub(super) certs_cache_ttl: u64,
}
impl DapsConfigBuilder<'_> {
pub fn validate(&self) -> Result<(), String> {
if self.token_url.is_none() {
return Err("Token URL is empty".to_string());
} else if let Some(token_url) = self.token_url.clone() {
token_url
.parse::<url::Url>()
.map_err(|e| format!("Token URL is invalid: {e}"))?;
}
if self.certs_url.is_none() {
return Err("Certs URL is empty".to_string());
} else if let Some(certs_url) = self.certs_url.clone() {
certs_url
.parse::<url::Url>()
.map_err(|e| format!("Certs URL is invalid: {e}"))?;
}
if self.private_key.is_none() {
return Err("Private key path is empty".to_string());
}
if self.private_key_password.is_none() {
return Err("Private key password is empty".to_string());
}
if self.scope.is_none() {
return Err("Scope is empty".to_string());
}
Ok(())
}
}