From e26acd8413ad617c0c7c5387f72921c35ea804ef Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 22 Jul 2021 19:40:14 -0400 Subject: [PATCH] Fixing some defaults --- crates/utils/src/settings/mod.rs | 47 +++++++++++++++++++--------- crates/utils/src/settings/structs.rs | 2 -- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index 1e528d93e..b247bae93 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -132,35 +132,52 @@ impl Settings { Ok(Self::read_config_file()?) } - pub(crate) fn actor_name_max_length(&self) -> usize { - self - .actor_name_max_length - .unwrap_or_else(|| Settings::default().actor_name_max_length.unwrap()) - } - - pub fn database(&self) -> DatabaseConfig { - self.database.to_owned().unwrap_or_default() - } pub fn hostname(&self) -> String { - self.hostname.to_owned().unwrap_or_default() + self.hostname.to_owned().expect("No hostname given") } pub fn bind(&self) -> IpAddr { self.bind.expect("return bind address") } pub fn port(&self) -> u16 { - self.port.unwrap_or_default() + self + .port + .unwrap_or_else(|| Settings::default().port.expect("missing port")) } pub fn tls_enabled(&self) -> bool { - self.tls_enabled.unwrap_or_default() + self.tls_enabled.unwrap_or_else(|| { + Settings::default() + .tls_enabled + .expect("missing tls_enabled") + }) } pub fn jwt_secret(&self) -> String { - self.jwt_secret.to_owned().unwrap_or_default() + self + .jwt_secret + .to_owned() + .unwrap_or_else(|| Settings::default().jwt_secret.expect("missing jwt_secret")) } pub fn pictrs_url(&self) -> String { - self.pictrs_url.to_owned().unwrap_or_default() + self + .pictrs_url + .to_owned() + .unwrap_or_else(|| Settings::default().pictrs_url.expect("missing pictrs_url")) } pub fn iframely_url(&self) -> String { - self.iframely_url.to_owned().unwrap_or_default() + self.iframely_url.to_owned().unwrap_or_else(|| { + Settings::default() + .iframely_url + .expect("missing iframely_url") + }) + } + pub fn actor_name_max_length(&self) -> usize { + self.actor_name_max_length.unwrap_or_else(|| { + Settings::default() + .actor_name_max_length + .expect("missing actor name length") + }) + } + pub fn database(&self) -> DatabaseConfig { + self.database.to_owned().unwrap_or_default() } pub fn rate_limit(&self) -> RateLimitConfig { self.rate_limit.to_owned().unwrap_or_default() diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index fd621066c..1046bd147 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -21,8 +21,6 @@ pub struct Settings { pub(crate) actor_name_max_length: Option, } -impl Settings {} - #[derive(Debug, Deserialize, Clone)] pub struct CaptchaConfig { pub enabled: bool,