Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/unreleased/bug-fixes/3971-fix-config-from-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Fix the prefix separator for config key-vals set from env var to a
single underscore between the "NAMADA" prefix and the rest of the path.
([\#3971](https://github.com/anoma/namada/pull/3971))
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ clap_complete_nushell = "4.5"
clru = {git = "https://github.com/marmeladema/clru-rs.git", rev = "71ca566"}
color-eyre = "0.6.2"
concat-idents = "1.1.2"
config = { git = "https://github.com/mehcode/config-rs.git", rev = "e3c1d0b452639478662a44f15ef6d5b6d969bf9b" }
config = "0.14.1"
data-encoding = "2.3.2"
derivation-path = "0.2.0"
derivative = "2.2.0"
Expand Down
33 changes: 31 additions & 2 deletions crates/apps_lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ impl Config {
.add_source(defaults)
.add_source(config::File::with_name(file_name))
.add_source(
config::Environment::with_prefix("NAMADA").separator("__"),
config::Environment::with_prefix("NAMADA")
.prefix_separator("_")
.separator("__"),
);

let config = builder.build().map_err(Error::ReadError)?;
Expand Down Expand Up @@ -854,11 +856,38 @@ namespace = "cometbft"

#[cfg(test)]
mod tests {
use super::DEFAULT_COMETBFT_CONFIG;
use std::env;

use namada_sdk::chain::ChainId;
use tempfile::tempdir;

use super::{Config, DEFAULT_COMETBFT_CONFIG};
use crate::config::TendermintMode;
use crate::tendermint_config::TendermintConfig;

#[test]
fn test_default_cometbft_config() {
assert!(TendermintConfig::parse_toml(DEFAULT_COMETBFT_CONFIG).is_ok());
}

/// Check that a key-val set from an env var gets applied to a loaded config
#[test]
fn test_config_env_var() {
let base_dir = tempdir().unwrap();
let chain_id = ChainId("ChainyMcChainFace".to_owned());

Config::generate(
base_dir.path(),
&chain_id,
TendermintMode::Full,
true,
)
.unwrap();

let moniker = "moniker_from_env";
env::set_var("NAMADA_LEDGER__COMETBFT__MONIKER", moniker);
let config = Config::load(&base_dir, &chain_id, None);

assert_eq!(config.ledger.cometbft.moniker.as_ref(), moniker);
}
}