diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs index 23ef765..efb1b5f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,10 +8,14 @@ pub struct Config { pub email: Option<String>, pub base_url: Option<String>, pub identity_url: Option<String>, + pub notifications_url: Option<String>, #[serde(default = "default_lock_timeout")] pub lock_timeout: u64, + #[serde(default = "default_sync_interval")] + pub sync_interval: u64, #[serde(default = "default_pinentry")] pub pinentry: String, + pub client_cert_path: Option<std::path::PathBuf>, // backcompat, no longer generated in new configs #[serde(skip_serializing)] pub device_id: Option<String>, @@ -23,8 +27,11 @@ impl Default for Config { email: None, base_url: None, identity_url: None, + notifications_url: None, lock_timeout: default_lock_timeout(), + sync_interval: default_sync_interval(), pinentry: default_pinentry(), + client_cert_path: None, device_id: None, } } @@ -36,6 +43,11 @@ pub fn default_lock_timeout() -> u64 { } #[must_use] +pub fn default_sync_interval() -> u64 { + 3600 +} + +#[must_use] pub fn default_pinentry() -> String { "pinentry".to_string() } @@ -134,7 +146,14 @@ impl Config { pub fn base_url(&self) -> String { self.base_url.clone().map_or_else( || "https://api.bitwarden.com".to_string(), - |url| format!("{}/api", url.trim_end_matches('/')), + |url| { + let clean_url = url.trim_end_matches('/').to_string(); + if clean_url == "https://api.bitwarden.eu" { + clean_url + } else { + format!("{clean_url}/api") + } + }, ) } @@ -143,12 +162,41 @@ impl Config { self.identity_url.clone().unwrap_or_else(|| { self.base_url.clone().map_or_else( || "https://identity.bitwarden.com".to_string(), - |url| format!("{}/identity", url.trim_end_matches('/')), + |url| { + let clean_url = url.trim_end_matches('/').to_string(); + if clean_url == "https://identity.bitwarden.eu" { + clean_url + } else { + format!("{clean_url}/identity") + } + }, ) }) } #[must_use] + pub fn notifications_url(&self) -> String { + self.notifications_url.clone().unwrap_or_else(|| { + self.base_url.clone().map_or_else( + || "https://notifications.bitwarden.com".to_string(), + |url| { + let clean_url = url.trim_end_matches('/').to_string(); + if clean_url == "https://notifications.bitwarden.eu" { + clean_url + } else { + format!("{clean_url}/notifications") + } + }, + ) + }) + } + + #[must_use] + pub fn client_cert_path(&self) -> Option<&std::path::Path> { + self.client_cert_path.as_deref() + } + + #[must_use] pub fn server_name(&self) -> String { self.base_url .clone() @@ -169,7 +217,7 @@ pub async fn device_id(config: &Config) -> Result<String> { Ok(s.trim().to_string()) } else { let id = config.device_id.as_ref().map_or_else( - || uuid::Uuid::new_v4().to_hyphenated().to_string(), + || uuid::Uuid::new_v4().hyphenated().to_string(), String::to_string, ); let mut fh = tokio::fs::File::create(&file).await.map_err(|e| { |