mirror of
https://github.com/lldap/lldap.git
synced 2026-07-25 17:58:44 +00:00
server: clean up the expected keys
This commit is contained in:
committed by
nitnelave
parent
f14aa2284c
commit
01f97f5ed4
@@ -517,34 +517,23 @@ impl ConfigOverrider for SmtpOpts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_keys() -> HashSet<String> {
|
fn expected_keys(dict: &figment::value::Dict) -> HashSet<String> {
|
||||||
fn process_value(
|
use figment::value::{Dict, Value};
|
||||||
value: &serde_json::Value,
|
fn process_value(value: &Dict, keys: &mut HashSet<String>, path: &mut Vec<String>) {
|
||||||
keys: &mut HashSet<String>,
|
for (key, value) in value {
|
||||||
path: &mut Vec<String>,
|
match value {
|
||||||
parent: Option<&str>,
|
Value::Dict(_, dict) => {
|
||||||
) {
|
path.push(format!("{}__", key.to_ascii_uppercase()));
|
||||||
match value {
|
process_value(dict, keys, path);
|
||||||
serde_json::Value::Object(map) => {
|
|
||||||
if let Some(parent) = parent {
|
|
||||||
path.push(format!("{}__", parent.to_ascii_uppercase()));
|
|
||||||
}
|
|
||||||
for (key, value) in map {
|
|
||||||
process_value(value, keys, path, Some(key));
|
|
||||||
}
|
|
||||||
if parent.is_some() {
|
|
||||||
path.pop();
|
path.pop();
|
||||||
}
|
}
|
||||||
}
|
_ => {
|
||||||
_ => {
|
keys.insert(format!(
|
||||||
let mut key = path.join("");
|
"LLDAP_{}{}",
|
||||||
key.push_str(
|
path.join(""),
|
||||||
parent
|
key.to_ascii_uppercase()
|
||||||
.expect("non-object at root")
|
));
|
||||||
.to_ascii_uppercase()
|
}
|
||||||
.as_str(),
|
|
||||||
);
|
|
||||||
keys.insert(key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -560,9 +549,7 @@ fn expected_keys() -> HashSet<String> {
|
|||||||
keys.insert("LLDAP_SMTP_OPTIONS__TLS_REQUIRED".to_string());
|
keys.insert("LLDAP_SMTP_OPTIONS__TLS_REQUIRED".to_string());
|
||||||
// From the config keys.
|
// From the config keys.
|
||||||
let mut path = Vec::new();
|
let mut path = Vec::new();
|
||||||
let json_value =
|
process_value(dict, &mut keys, &mut path);
|
||||||
serde_json::to_value(ConfigurationBuilder::default().private_build().unwrap()).unwrap();
|
|
||||||
process_value(&json_value, &mut keys, &mut path, None);
|
|
||||||
keys
|
keys
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,8 +579,8 @@ where
|
|||||||
println!("Configuration: {:#?}", &config);
|
println!("Configuration: {:#?}", &config);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let expected_keys = expected_keys();
|
|
||||||
use figment::{Profile, Provider};
|
use figment::{Profile, Provider};
|
||||||
|
let expected_keys = expected_keys(&figment_config.data()?[&Profile::Default]);
|
||||||
env_variable_provider().data().unwrap()[&Profile::default()]
|
env_variable_provider().data().unwrap()[&Profile::default()]
|
||||||
.keys()
|
.keys()
|
||||||
.map(|k| k.to_ascii_uppercase())
|
.map(|k| k.to_ascii_uppercase())
|
||||||
|
|||||||
Reference in New Issue
Block a user