Skip to content

Commit 76a1837

Browse files
committed
feat: [#605] remove deprecated env vars
You can now use the Figmenat conventions to override config values: - TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN - TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY
1 parent 69dd3d3 commit 76a1837

File tree

2 files changed

+1
-82
lines changed

2 files changed

+1
-82
lines changed

src/config/mod.rs

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use tokio::sync::RwLock;
1515
use torrust_index_located_error::LocatedError;
1616
use url::Url;
1717

18-
use self::v1::tracker::ApiToken;
1918
use crate::web::api::server::DynError;
2019

2120
pub type Settings = v1::Settings;
@@ -43,21 +42,11 @@ pub const ENV_VAR_CONFIG_TOML: &str = "TORRUST_INDEX_CONFIG_TOML";
4342
/// The `index.toml` file location.
4443
pub const ENV_VAR_CONFIG_TOML_PATH: &str = "TORRUST_INDEX_CONFIG_TOML_PATH";
4544

46-
/// Token needed to communicate with the Torrust Tracker.
47-
/// Deprecated. Use `TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN`.
48-
pub const ENV_VAR_TRACKER_API_ADMIN_TOKEN: &str = "TORRUST_INDEX_TRACKER_API_TOKEN";
49-
50-
/// Secret key used to encrypt and decrypt
51-
/// Deprecated. Use `TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY`.
52-
pub const ENV_VAR_AUTH_SECRET_KEY: &str = "TORRUST_INDEX_AUTH_SECRET_KEY";
53-
5445
/// Information required for loading config
5546
#[derive(Debug, Default, Clone)]
5647
pub struct Info {
5748
config_toml: Option<String>,
5849
config_toml_path: String,
59-
tracker_api_token: Option<ApiToken>,
60-
auth_secret_key: Option<String>,
6150
}
6251

6352
impl Info {
@@ -71,8 +60,6 @@ impl Info {
7160
pub fn new(default_config_toml_path: String) -> Result<Self, Error> {
7261
let env_var_config_toml = ENV_VAR_CONFIG_TOML.to_string();
7362
let env_var_config_toml_path = ENV_VAR_CONFIG_TOML_PATH.to_string();
74-
let env_var_tracker_api_admin_token = ENV_VAR_TRACKER_API_ADMIN_TOKEN.to_string();
75-
let env_var_auth_secret_key = ENV_VAR_AUTH_SECRET_KEY.to_string();
7663

7764
let config_toml = if let Ok(config_toml) = env::var(env_var_config_toml) {
7865
println!("Loading configuration from environment variable {config_toml} ...");
@@ -89,17 +76,9 @@ impl Info {
8976
default_config_toml_path
9077
};
9178

92-
let tracker_api_token = env::var(env_var_tracker_api_admin_token)
93-
.ok()
94-
.map(|token| ApiToken::new(&token));
95-
96-
let auth_secret_key = env::var(env_var_auth_secret_key).ok();
97-
9879
Ok(Self {
9980
config_toml,
10081
config_toml_path,
101-
tracker_api_token,
102-
auth_secret_key,
10382
})
10483
}
10584
}
@@ -278,19 +257,7 @@ impl Configuration {
278257
.merge(Env::prefixed(CONFIG_OVERRIDE_PREFIX).split(CONFIG_OVERRIDE_SEPARATOR))
279258
};
280259

281-
//println!("figment: {figment:#?}");
282-
283-
let mut settings: Settings = figment.extract()?;
284-
285-
if let Some(ref token) = info.tracker_api_token {
286-
// todo: remove when using only Figment env var name: `TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN`
287-
settings.override_tracker_api_token(token);
288-
};
289-
290-
if let Some(ref secret_key) = info.auth_secret_key {
291-
// todo: remove when using only Figment env var name: `TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY`
292-
settings.override_auth_secret_key(secret_key);
293-
};
260+
let settings: Settings = figment.extract()?;
294261

295262
Ok(settings)
296263
}
@@ -459,8 +426,6 @@ mod tests {
459426
let info = Info {
460427
config_toml: Some(default_config_toml()),
461428
config_toml_path: String::new(),
462-
tracker_api_token: None,
463-
auth_secret_key: None,
464429
};
465430

466431
let settings = Configuration::load_settings(&info).expect("Failed to load configuration from info");
@@ -471,23 +436,6 @@ mod tests {
471436
});
472437
}
473438

474-
#[tokio::test]
475-
async fn configuration_should_allow_to_override_the_tracker_api_token_provided_in_the_toml_file_deprecated() {
476-
let info = Info {
477-
config_toml: Some(default_config_toml()),
478-
config_toml_path: String::new(),
479-
tracker_api_token: Some(ApiToken::new("OVERRIDDEN API TOKEN")),
480-
auth_secret_key: None,
481-
};
482-
483-
let configuration = Configuration::load(&info).expect("Failed to load configuration from info");
484-
485-
assert_eq!(
486-
configuration.get_all().await.tracker.token,
487-
ApiToken::new("OVERRIDDEN API TOKEN")
488-
);
489-
}
490-
491439
#[tokio::test]
492440
async fn configuration_should_allow_to_override_the_tracker_api_token_provided_in_the_toml_file() {
493441
figment::Jail::expect_with(|jail| {
@@ -499,8 +447,6 @@ mod tests {
499447
let info = Info {
500448
config_toml: Some(default_config_toml()),
501449
config_toml_path: String::new(),
502-
tracker_api_token: None,
503-
auth_secret_key: None,
504450
};
505451

506452
let settings = Configuration::load_settings(&info).expect("Could not load configuration from file");
@@ -511,23 +457,6 @@ mod tests {
511457
});
512458
}
513459

514-
#[tokio::test]
515-
async fn configuration_should_allow_to_override_the_authentication_secret_key_provided_in_the_toml_file_deprecated() {
516-
let info = Info {
517-
config_toml: Some(default_config_toml()),
518-
config_toml_path: String::new(),
519-
tracker_api_token: None,
520-
auth_secret_key: Some("OVERRIDDEN AUTH SECRET KEY".to_string()),
521-
};
522-
523-
let configuration = Configuration::load(&info).expect("Failed to load configuration from info");
524-
525-
assert_eq!(
526-
configuration.get_all().await.auth.secret_key,
527-
SecretKey::new("OVERRIDDEN AUTH SECRET KEY")
528-
);
529-
}
530-
531460
#[tokio::test]
532461
async fn configuration_should_allow_to_override_the_authentication_secret_key_provided_in_the_toml_file() {
533462
figment::Jail::expect_with(|jail| {
@@ -539,8 +468,6 @@ mod tests {
539468
let info = Info {
540469
config_toml: Some(default_config_toml()),
541470
config_toml_path: String::new(),
542-
tracker_api_token: None,
543-
auth_secret_key: None,
544471
};
545472

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

src/config/v1/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ pub struct Settings {
5858
}
5959

6060
impl Settings {
61-
pub fn override_tracker_api_token(&mut self, tracker_api_token: &ApiToken) {
62-
self.tracker.override_tracker_api_token(tracker_api_token);
63-
}
64-
65-
pub fn override_auth_secret_key(&mut self, auth_secret_key: &str) {
66-
self.auth.override_secret_key(auth_secret_key);
67-
}
68-
6961
pub fn remove_secrets(&mut self) {
7062
self.tracker.token = ApiToken::new("***");
7163
if let Some(_password) = self.database.connect_url.password() {

0 commit comments

Comments
 (0)