use super::*;
pub(crate) fn default_jwt_secret() -> JwtSecret {
#[cfg(feature = "protocol-zeroize")]
{
String::new().into()
}
#[cfg(not(feature = "protocol-zeroize"))]
{
String::new()
}
}
pub(crate) fn collect_env_vars(prefix: &str) -> HashMap<String, ConfigValue> {
let mut values = HashMap::new();
for (key, value) in std::env::vars() {
if let Some(stripped) = key.strip_prefix(prefix) {
let config_key = stripped.to_lowercase().replace("__", ".");
values.insert(config_key, infer_config_value(&value));
}
}
values
}
fn infer_config_value(s: &str) -> ConfigValue {
if s.eq_ignore_ascii_case("true") {
return ConfigValue::Bool(true);
}
if s.eq_ignore_ascii_case("false") {
return ConfigValue::Bool(false);
}
if let Ok(v) = s.parse::<i64>() {
return ConfigValue::I64(v);
}
if let Ok(v) = s.parse::<u64>() {
return ConfigValue::U64(v);
}
if s.contains('.') || s.contains('e') || s.contains('E') {
if let Ok(v) = s.parse::<f64>() {
return ConfigValue::F64(v);
}
}
ConfigValue::String(s.to_string())
}