mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-26 13:38:51 +00:00
Parse environment variables in all banner configuration fields
This commit is contained in:
parent
bbe8252f9d
commit
1d21ba0ecc
@ -89,6 +89,14 @@ pub struct Config {
|
||||
static mut CONF: Option<Config> = None;
|
||||
|
||||
impl Config {
|
||||
fn parse_string_val(val: String) -> String {
|
||||
if val.starts_with("$") {
|
||||
std::env::var(&val[1..]).unwrap()
|
||||
} else {
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
fn yaml_str(parsed: &Yaml, name: &str) -> String {
|
||||
let val = match &parsed[name] {
|
||||
Yaml::Real(r) | Yaml::String(r) => r.to_string(),
|
||||
@ -104,11 +112,7 @@ impl Config {
|
||||
}.to_string();
|
||||
|
||||
// Check if we have to get an environment variable
|
||||
if val.starts_with("$") {
|
||||
std::env::var(&val[1..]).unwrap()
|
||||
} else {
|
||||
val
|
||||
}
|
||||
Self::parse_string_val(val)
|
||||
}
|
||||
|
||||
fn yaml_u64(parsed: &Yaml, name: &str) -> u64 {
|
||||
@ -184,9 +188,14 @@ impl Config {
|
||||
v => panic!("Invalid banner nature: {} !", v)
|
||||
},
|
||||
message: parsed_banner["message"].as_hash().unwrap().iter()
|
||||
.map(|(k, v)| (k.as_str().unwrap().to_string(), v.as_str().unwrap().to_string()))
|
||||
.map(|(k, v)| (
|
||||
k.as_str().unwrap().to_string(),
|
||||
Self::parse_string_val(v.as_str().unwrap().to_string()))
|
||||
)
|
||||
.collect(),
|
||||
link: parsed_banner["link"].as_str().map(|s| s.to_string()),
|
||||
link: parsed_banner["link"].as_str()
|
||||
.map(str::to_string)
|
||||
.map(Self::parse_string_val),
|
||||
})
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user