1
0
Fork 0
mirror of https://github.com/dani-garcia/vaultwarden.git synced 2025-09-28 04:21:17 +00:00

Accept y/n, True/False, 1/0 as booleans in environment vars

This commit is contained in:
Daniel García 2020-01-20 22:28:54 +01:00
commit d212dfe735
No known key found for this signature in database
GPG key ID: FC8A7D14C3CD543A
2 changed files with 19 additions and 4 deletions

View file

@ -309,6 +309,17 @@ where
try_parse_string(env::var(key))
}
const TRUE_VALUES: &[&str] = &["true", "t", "yes", "y", "1"];
const FALSE_VALUES: &[&str] = &["false", "f", "no", "n", "0"];
pub fn get_env_bool(key: &str) -> Option<bool> {
match env::var(key) {
Ok(val) if TRUE_VALUES.contains(&val.to_lowercase().as_ref()) => Some(true),
Ok(val) if FALSE_VALUES.contains(&val.to_lowercase().as_ref()) => Some(false),
_ => None,
}
}
//
// Date util methods
//