Skip to content

Commit

Permalink
feat: use double underscore to split config env var names
Browse files Browse the repository at this point in the history
For example, the env var `TORRUST_TRACKER__HTTP_API__ACCESS_TOKENS__ADMIN` would be the config option:

```
[http_api.access_tokens]
admin = "MyAccessToken"
```

It uses `__` double underscore becuase dots are not allowed in Bash
names.

See: https://www.gnu.org/software/bash/manual/bash.html#Definitions

```
name
  A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.
```
  • Loading branch information
josecelano committed May 9, 2024
1 parent b3a1442 commit caae725
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/configuration/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl Configuration {
pub fn load(info: &Info) -> Result<Configuration, Error> {
let figment = Figment::new()
.merge(Toml::string(&info.tracker_toml))
.merge(Env::prefixed("TORRUST_TRACKER_"));
.merge(Env::prefixed("TORRUST_TRACKER__").split("__"));

let mut config: Configuration = figment.extract()?;

Expand Down Expand Up @@ -553,7 +553,7 @@ mod tests {
#[test]
fn configuration_should_allow_to_overwrite_the_default_tracker_api_token_for_admin() {
figment::Jail::expect_with(|jail| {
jail.set_env("TORRUST_TRACKER_HTTP_API.ACCESS_TOKENS.ADMIN", "NewToken");
jail.set_env("TORRUST_TRACKER__HTTP_API__ACCESS_TOKENS__ADMIN", "NewToken");

let info = Info {
tracker_toml: default_config_toml(),
Expand Down

0 comments on commit caae725

Please sign in to comment.