diff --git a/packages/configuration/src/lib.rs b/packages/configuration/src/lib.rs index b79081a1..62792c27 100644 --- a/packages/configuration/src/lib.rs +++ b/packages/configuration/src/lib.rs @@ -29,9 +29,6 @@ const ENV_VAR_CONFIG_TOML: &str = "TORRUST_TRACKER_CONFIG_TOML"; /// The `tracker.toml` file location. pub const ENV_VAR_CONFIG_TOML_PATH: &str = "TORRUST_TRACKER_CONFIG_TOML_PATH"; -/// Env var to overwrite API admin token. -const ENV_VAR_HTTP_API_ACCESS_TOKENS_ADMIN: &str = "TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN"; - pub type Configuration = v1::Configuration; pub type UdpTracker = v1::udp_tracker::UdpTracker; pub type HttpTracker = v1::http_tracker::HttpTracker; @@ -52,7 +49,6 @@ pub struct TrackerPolicy { pub struct Info { config_toml: Option, config_toml_path: String, - api_admin_token: Option, } impl Info { @@ -66,7 +62,6 @@ impl Info { pub fn new(default_config_toml_path: String) -> Result { let env_var_config_toml = ENV_VAR_CONFIG_TOML.to_string(); let env_var_config_toml_path = ENV_VAR_CONFIG_TOML_PATH.to_string(); - let env_var_api_admin_token = ENV_VAR_HTTP_API_ACCESS_TOKENS_ADMIN.to_string(); let config_toml = if let Ok(config_toml) = env::var(env_var_config_toml) { println!("Loading configuration from environment variable {config_toml} ..."); @@ -86,7 +81,6 @@ impl Info { Ok(Self { config_toml, config_toml_path, - api_admin_token: env::var(env_var_api_admin_token).ok(), }) } } diff --git a/packages/configuration/src/v1/mod.rs b/packages/configuration/src/v1/mod.rs index b9d75c71..8d45270b 100644 --- a/packages/configuration/src/v1/mod.rs +++ b/packages/configuration/src/v1/mod.rs @@ -288,10 +288,6 @@ impl Default for Configuration { } impl Configuration { - fn override_api_admin_token(&mut self, api_admin_token: &str) { - self.http_api.override_admin_token(api_admin_token); - } - /// Returns the tracker public IP address id defined in the configuration, /// and `None` otherwise. #[must_use] @@ -331,11 +327,7 @@ impl Configuration { .merge(Env::prefixed(CONFIG_OVERRIDE_PREFIX).split(CONFIG_OVERRIDE_SEPARATOR)) }; - let mut config: Configuration = figment.extract()?; - - if let Some(ref token) = info.api_admin_token { - config.override_api_admin_token(token); - }; + let config: Configuration = figment.extract()?; Ok(config) } @@ -469,7 +461,6 @@ mod tests { let info = Info { config_toml: Some(empty_configuration), config_toml_path: "tracker.toml".to_string(), - api_admin_token: None, }; let configuration = Configuration::load(&info).expect("Could not load configuration from file"); @@ -491,7 +482,6 @@ mod tests { let info = Info { config_toml: Some(config_toml), config_toml_path: String::new(), - api_admin_token: None, }; let configuration = Configuration::load(&info).expect("Could not load configuration from file"); @@ -515,7 +505,6 @@ mod tests { let info = Info { config_toml: None, config_toml_path: "tracker.toml".to_string(), - api_admin_token: None, }; let configuration = Configuration::load(&info).expect("Could not load configuration from file"); @@ -534,27 +523,6 @@ mod tests { let info = Info { config_toml: Some(default_config_toml()), config_toml_path: String::new(), - api_admin_token: None, - }; - - let configuration = Configuration::load(&info).expect("Could not load configuration from file"); - - assert_eq!( - configuration.http_api.access_tokens.get("admin"), - Some("NewToken".to_owned()).as_ref() - ); - - Ok(()) - }); - } - - #[test] - fn configuration_should_allow_to_overwrite_the_default_tracker_api_token_for_admin_with_the_deprecated_env_var_name() { - figment::Jail::expect_with(|_jail| { - let info = Info { - config_toml: Some(default_config_toml()), - config_toml_path: String::new(), - api_admin_token: Some("NewToken".to_owned()), }; let configuration = Configuration::load(&info).expect("Could not load configuration from file");