From eab146b12167744b300838067cc84647d7bc8729 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 20 Oct 2023 01:38:22 +0530 Subject: [PATCH] gc: get public hostname as config parameter --- config/default.toml | 3 ++- src/settings.rs | 50 +++++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/config/default.toml b/config/default.toml index 0812afa6..1f69a48b 100644 --- a/config/default.toml +++ b/config/default.toml @@ -69,4 +69,5 @@ password = "password" [survey] nodes = ["http://localhost:7001"] -rate_limit = 3600 # upload every hour +rate_limit = 10 # upload every hour +instance_root_url = "http://localhost:7000" diff --git a/src/settings.rs b/src/settings.rs index d7194d8a..f5107def 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -95,6 +95,7 @@ pub struct Redis { pub struct Survey { pub nodes: Vec, pub rate_limit: u64, + pub instance_root_url: Url, } #[derive(Debug, Clone, Deserialize, Eq, PartialEq)] @@ -105,7 +106,7 @@ pub struct Settings { pub allow_registration: bool, pub allow_demo: bool, pub database: Database, - pub survey: Survey, + pub survey: Option, pub redis: Option, pub server: Server, pub captcha: Captcha, @@ -163,10 +164,9 @@ const ENV_VAR_CONFIG: [(&str, &str); 29] = [ ]; - const DEPRECATED_ENV_VARS: [(&str, &str); 23] = [ - ("debug","MCAPTCHA_DEBUG"), - ("commercial","MCAPTCHA_COMMERCIAL"), + ("debug", "MCAPTCHA_DEBUG"), + ("commercial", "MCAPTCHA_COMMERCIAL"), ("source_code", "MCAPTCHA_SOURCE_CODE"), ("allow_registration", "MCAPTCHA_ALLOW_REGISTRATION"), ("allow_demo", "MCAPTCHA_ALLOW_DEMO"), @@ -179,9 +179,18 @@ const DEPRECATED_ENV_VARS: [(&str, &str); 23] = [ ("server.proxy_has_tls", "MCAPTCHA_SERVER_PROXY_HAS_TLS"), ("captcha.salt", "MCAPTCHA_CAPTCHA_SALT"), ("captcha.gc", "MCAPTCHA_CAPTCHA_GC"), - ("captcha.default_difficulty_strategy.avg_traffic_difficulty", "MCAPTCHA_CAPTCHA_AVG_TRAFFIC_DIFFICULTY"), - ("captcha.default_difficulty_strategy.peak_sustainable_traffic_difficulty", "MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY"), - ("captcha.default_difficulty_strategy.broke_my_site_traffic_difficulty", "MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC"), + ( + "captcha.default_difficulty_strategy.avg_traffic_difficulty", + "MCAPTCHA_CAPTCHA_AVG_TRAFFIC_DIFFICULTY", + ), + ( + "captcha.default_difficulty_strategy.peak_sustainable_traffic_difficulty", + "MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY", + ), + ( + "captcha.default_difficulty_strategy.broke_my_site_traffic_difficulty", + "MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC", + ), ("smtp.from", "MCAPTCHA_SMTP_FROM"), ("smtp.reply", "MCAPTCHA_SMTP_REPLY_TO"), ("smtp.url", "MCAPTCHA_SMTP_URL"), @@ -244,7 +253,6 @@ impl Settings { } fn env_override(mut s: ConfigBuilder) -> ConfigBuilder { - for (parameter, env_var_name) in DEPRECATED_ENV_VARS.iter() { if let Ok(val) = env::var(env_var_name) { log::warn!( @@ -254,7 +262,6 @@ impl Settings { } } - for (parameter, env_var_name) in ENV_VAR_CONFIG.iter() { if let Ok(val) = env::var(env_var_name) { log::debug!( @@ -284,8 +291,6 @@ mod tests { use super::*; - - #[test] fn deprecated_env_override_works() { use crate::tests::get_settings; @@ -314,7 +319,11 @@ mod tests { /* top level */ helper!("MCAPTCHA_DEBUG", !init_settings.debug, debug); helper!("MCAPTCHA_COMMERCIAL", !init_settings.commercial, commercial); - helper!("MCAPTCHA_ALLOW_REGISTRATION", !init_settings.allow_registration, allow_registration); + helper!( + "MCAPTCHA_ALLOW_REGISTRATION", + !init_settings.allow_registration, + allow_registration + ); helper!("MCAPTCHA_ALLOW_DEMO", !init_settings.allow_demo, allow_demo); /* database_type */ @@ -371,8 +380,20 @@ mod tests { 999, captcha.default_difficulty_strategy.avg_traffic_difficulty ); - helper!("MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY", 999 , captcha.default_difficulty_strategy.peak_sustainable_traffic_difficulty); - helper!("MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC", 999 , captcha.default_difficulty_strategy.broke_my_site_traffic_difficulty); + helper!( + "MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY", + 999, + captcha + .default_difficulty_strategy + .peak_sustainable_traffic_difficulty + ); + helper!( + "MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC", + 999, + captcha + .default_difficulty_strategy + .broke_my_site_traffic_difficulty + ); /* SMTP */ @@ -407,7 +428,6 @@ mod tests { } } - #[test] fn env_override_works() { use crate::tests::get_settings;