diff --git a/Cargo.lock b/Cargo.lock index 5a736260b816b7a70dc680c36aa6d20678abfd77..2af0f7e70ef29ab57907b85081c558336ac0f201 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -788,6 +788,7 @@ dependencies = [ "dubp", "envy", "futures-util", + "log", "serde", "serde_json", ] diff --git a/conf/Cargo.toml b/conf/Cargo.toml index 35501c00b8b189ce77907c5330d192a1907de9c7..9843943e285a5fa3df044c0d3ffcf7402aca9f49 100644 --- a/conf/Cargo.toml +++ b/conf/Cargo.toml @@ -10,5 +10,6 @@ anyhow = "1.0.34" dubp = { version = "0.53.1", features = ["duniter"] } envy = "0.4.2" futures-util = "0.3" +log = "0.4" serde = { version = "1.0.105", features = ["derive"] } serde_json = "1.0.53" diff --git a/conf/src/lib.rs b/conf/src/lib.rs index 24e9d20adb0aca0052174154416c135024141d65..77de2fa324237b933951e2c8844f35e6058d4b1c 100644 --- a/conf/src/lib.rs +++ b/conf/src/lib.rs @@ -57,20 +57,26 @@ pub fn load_module_conf<C: Default + DeserializeOwned>( profile_path_opt: &Option<PathBuf>, ) -> anyhow::Result<C> { if let Some(ref profile_path) = profile_path_opt { - if let Ok(conf) = envy::prefixed(format!("DUNITER_{}_", module_name)).from_env::<C>() { - Ok(conf) - } else { - let conf_file_path = find_module_conf_file_path(module_name, profile_path)?; - if conf_file_path.exists() { - let mut file = std::fs::File::open(conf_file_path)?; - let mut contents = String::new(); - use std::io::Read as _; - file.read_to_string(&mut contents)?; - Ok(serde_json::from_str::<C>(&contents).with_context(|| { - format!("Invalid configuration for module '{}'", module_name) - })?) - } else { - Ok(C::default()) + match envy::prefixed(format!("DUNITER_{}_", module_name.to_uppercase())).from_env::<C>() { + Ok(conf) => Ok(conf), + Err(e) => { + log::debug!( + "load_module_conf(module_name: {}): envy error={}", + module_name, + e + ); + let conf_file_path = find_module_conf_file_path(module_name, profile_path)?; + if conf_file_path.exists() { + let mut file = std::fs::File::open(conf_file_path)?; + let mut contents = String::new(); + use std::io::Read as _; + file.read_to_string(&mut contents)?; + Ok(serde_json::from_str::<C>(&contents).with_context(|| { + format!("Invalid configuration for module '{}'", module_name) + })?) + } else { + Ok(C::default()) + } } } } else {