Skip to content

Commit a4d2adf

Browse files
committed
feat!: remove deprecated env var
The env var `TORRUST_TRACKER_API_ADMIN_TOKEN` was replaced with `TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN`. After the migration to Figment all configuration options can be overwritten.
1 parent ef15e0b commit a4d2adf

File tree

2 files changed

+1
-39
lines changed

2 files changed

+1
-39
lines changed

packages/configuration/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ const ENV_VAR_CONFIG_TOML: &str = "TORRUST_TRACKER_CONFIG_TOML";
2929
/// The `tracker.toml` file location.
3030
pub const ENV_VAR_CONFIG_TOML_PATH: &str = "TORRUST_TRACKER_CONFIG_TOML_PATH";
3131

32-
/// Env var to overwrite API admin token.
33-
const ENV_VAR_HTTP_API_ACCESS_TOKENS_ADMIN: &str = "TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN";
34-
3532
pub type Configuration = v1::Configuration;
3633
pub type UdpTracker = v1::udp_tracker::UdpTracker;
3734
pub type HttpTracker = v1::http_tracker::HttpTracker;
@@ -52,7 +49,6 @@ pub struct TrackerPolicy {
5249
pub struct Info {
5350
config_toml: Option<String>,
5451
config_toml_path: String,
55-
api_admin_token: Option<String>,
5652
}
5753

5854
impl Info {
@@ -66,7 +62,6 @@ impl Info {
6662
pub fn new(default_config_toml_path: String) -> Result<Self, Error> {
6763
let env_var_config_toml = ENV_VAR_CONFIG_TOML.to_string();
6864
let env_var_config_toml_path = ENV_VAR_CONFIG_TOML_PATH.to_string();
69-
let env_var_api_admin_token = ENV_VAR_HTTP_API_ACCESS_TOKENS_ADMIN.to_string();
7065

7166
let config_toml = if let Ok(config_toml) = env::var(env_var_config_toml) {
7267
println!("Loading configuration from environment variable {config_toml} ...");
@@ -86,7 +81,6 @@ impl Info {
8681
Ok(Self {
8782
config_toml,
8883
config_toml_path,
89-
api_admin_token: env::var(env_var_api_admin_token).ok(),
9084
})
9185
}
9286
}

packages/configuration/src/v1/mod.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,6 @@ impl Default for Configuration {
288288
}
289289

290290
impl Configuration {
291-
fn override_api_admin_token(&mut self, api_admin_token: &str) {
292-
self.http_api.override_admin_token(api_admin_token);
293-
}
294-
295291
/// Returns the tracker public IP address id defined in the configuration,
296292
/// and `None` otherwise.
297293
#[must_use]
@@ -331,11 +327,7 @@ impl Configuration {
331327
.merge(Env::prefixed(CONFIG_OVERRIDE_PREFIX).split(CONFIG_OVERRIDE_SEPARATOR))
332328
};
333329

334-
let mut config: Configuration = figment.extract()?;
335-
336-
if let Some(ref token) = info.api_admin_token {
337-
config.override_api_admin_token(token);
338-
};
330+
let config: Configuration = figment.extract()?;
339331

340332
Ok(config)
341333
}
@@ -469,7 +461,6 @@ mod tests {
469461
let info = Info {
470462
config_toml: Some(empty_configuration),
471463
config_toml_path: "tracker.toml".to_string(),
472-
api_admin_token: None,
473464
};
474465

475466
let configuration = Configuration::load(&info).expect("Could not load configuration from file");
@@ -491,7 +482,6 @@ mod tests {
491482
let info = Info {
492483
config_toml: Some(config_toml),
493484
config_toml_path: String::new(),
494-
api_admin_token: None,
495485
};
496486

497487
let configuration = Configuration::load(&info).expect("Could not load configuration from file");
@@ -515,7 +505,6 @@ mod tests {
515505
let info = Info {
516506
config_toml: None,
517507
config_toml_path: "tracker.toml".to_string(),
518-
api_admin_token: None,
519508
};
520509

521510
let configuration = Configuration::load(&info).expect("Could not load configuration from file");
@@ -534,27 +523,6 @@ mod tests {
534523
let info = Info {
535524
config_toml: Some(default_config_toml()),
536525
config_toml_path: String::new(),
537-
api_admin_token: None,
538-
};
539-
540-
let configuration = Configuration::load(&info).expect("Could not load configuration from file");
541-
542-
assert_eq!(
543-
configuration.http_api.access_tokens.get("admin"),
544-
Some("NewToken".to_owned()).as_ref()
545-
);
546-
547-
Ok(())
548-
});
549-
}
550-
551-
#[test]
552-
fn configuration_should_allow_to_overwrite_the_default_tracker_api_token_for_admin_with_the_deprecated_env_var_name() {
553-
figment::Jail::expect_with(|_jail| {
554-
let info = Info {
555-
config_toml: Some(default_config_toml()),
556-
config_toml_path: String::new(),
557-
api_admin_token: Some("NewToken".to_owned()),
558526
};
559527

560528
let configuration = Configuration::load(&info).expect("Could not load configuration from file");

0 commit comments

Comments
 (0)