1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 05:19:21 +00:00

Accept environment variables in configuration

This commit is contained in:
Pierre HUBERT 2021-10-16 17:34:27 +02:00
parent 30f427b61c
commit 43c76fa120

View File

@ -60,7 +60,7 @@ static mut CONF: Option<Config> = None;
impl Config {
fn yaml_str(parsed: &Yaml, name: &str) -> String {
match &parsed[name] {
let val = match &parsed[name] {
Yaml::Real(r) | Yaml::String(r) => r.to_string(),
Yaml::Integer(i) => i.to_string(),
Yaml::Boolean(true) => "true".to_string(),
@ -71,7 +71,14 @@ impl Config {
Yaml::BadValue => {
panic!("{} is missing", name);
}
}.to_string()
}.to_string();
// Check if we have to get an environment variable
if val.starts_with("$") {
std::env::var(&val[1..]).unwrap()
} else {
val
}
}
fn yaml_u64(parsed: &Yaml, name: &str) -> u64 {