From: Ian Jackson Date: Sat, 24 Jul 2021 18:55:55 +0000 (+0100) Subject: config: check key sections X-Git-Tag: hippotat/1.0.0~457 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=d84625a0ecda4d999ed7ee22f21a356cec5a5e23;p=hippotat.git config: check key sections Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index 28b2754..34b9a0c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -153,6 +153,7 @@ static SPECIAL_SERVER_SECTION: &str = "SERVER"; #[derive(Default,Debug)] struct Aggregate { + keys_allowed: HashMap<&'static str, SectionKindList>, sections: HashMap, } @@ -234,9 +235,18 @@ impl Aggregate { let loc = Arc::new(path_for_loc.to_owned()); for (sn, vars) in map { - //dbg!( InstanceConfig::FIELDS );// check xxx vars are in fields - let sn = sn.parse().dcontext(&sn)?; + + for key in vars.keys() { + let skl = self.keys_allowed.get(key.as_str()).ok_or_else( + || anyhow!("unknown configuration key {:?}", key) + )?; + if ! skl.contains(&sn) { + throw!(anyhow!("configuration key {:?} not applicable \ + in this kind of section {:?}", key, &sn)) + } + } + let ent = self.sections.entry(sn).or_default(); for (key, raw) in vars { let raw = match raw { @@ -678,6 +688,9 @@ pub fn read(end: LinkEnd) -> Vec { let agg = (||{ let mut agg = Aggregate::default(); + agg.keys_allowed.extend( + InstanceConfig::FIELDS.iter().cloned() + ); agg.read_string(DEFAULT_CONFIG.into(), "".as_ref()).unwrap();