ids_daps_client/
config.rs1use std::borrow::Cow;
2
3#[derive(Debug, derive_builder::Builder)]
5#[builder(setter(into), build_fn(validate = "Self::validate"))]
6#[allow(clippy::module_name_repetitions)]
7pub struct DapsConfig<'a> {
8 pub(super) token_url: Cow<'a, str>,
10 pub(super) certs_url: Cow<'a, str>,
12 pub(super) private_key: Cow<'a, std::path::Path>,
14 pub(super) private_key_password: Option<Cow<'a, str>>,
16 pub(super) scope: Cow<'a, str>,
18 pub(super) certs_cache_ttl: u64,
20}
21
22impl DapsConfigBuilder<'_> {
23 pub fn validate(&self) -> Result<(), String> {
25 if self.token_url.is_none() {
26 return Err("Token URL is empty".to_string());
27 } else if let Some(token_url) = self.token_url.clone() {
28 token_url
29 .parse::<url::Url>()
30 .map_err(|e| format!("Token URL is invalid: {e}"))?;
31 }
32 if self.certs_url.is_none() {
33 return Err("Certs URL is empty".to_string());
34 } else if let Some(certs_url) = self.certs_url.clone() {
35 certs_url
36 .parse::<url::Url>()
37 .map_err(|e| format!("Certs URL is invalid: {e}"))?;
38 }
39 if self.private_key.is_none() {
40 return Err("Private key path is empty".to_string());
41 }
42 if self.private_key_password.is_none() {
43 return Err("Private key password is empty".to_string());
44 }
45 if self.scope.is_none() {
46 return Err("Scope is empty".to_string());
47 }
48 Ok(())
49 }
50}