From: Ian Jackson Date: Sat, 7 Aug 2021 18:08:41 +0000 (+0100) Subject: config: Provide end in Aggregate and pass to contains() X-Git-Tag: hippotat/1.0.0~271 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=443715c2943575abde4fbab3e8d598169367590c;p=hippotat.git config: Provide end in Aggregate and pass to contains() Nothing uses this yet. Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index 1dab223..b99d065 100644 --- a/src/config.rs +++ b/src/config.rs @@ -163,6 +163,7 @@ static SPECIAL_SERVER_SECTION: &str = "SERVER"; #[derive(Debug)] struct Aggregate { + end: LinkEnd, keys_allowed: HashMap<&'static str, SectionKindList>, sections: HashMap, } @@ -222,9 +223,10 @@ impl Display for SectionName { impl Aggregate { fn new( + end: LinkEnd, keys_allowed: HashMap<&'static str, SectionKindList> ) -> Self { Aggregate { - keys_allowed, + end, keys_allowed, sections: default(), } } @@ -267,7 +269,7 @@ impl Aggregate { || anyhow!("unknown configuration key {:?}", key) )? }; - if ! skl.contains(&sn) { + if ! skl.contains(&sn, self.end) { throw!(anyhow!("configuration key {:?} not applicable \ in this kind of section: {}", key, &sn)) } @@ -536,26 +538,26 @@ impl SectionName { } impl SectionKindList { - fn contains(self, s: &SectionName) -> bool { - match self { - SKL::PerClient => matches!(s, SN::Link(_) + fn contains(self, s: &SectionName, end: LinkEnd) -> bool { + match (self, end) { + (SKL::PerClient,_) => matches!(s, SN::Link(_) | SN::Client(_) | SN::Server(_) | SN::Common), - SKL::Limits => matches!(s, SN::ServerLimit(_) + (SKL::Limits,_) => matches!(s, SN::ServerLimit(_) | SN::GlobalLimit), - SKL::Global => matches!(s, SN::Common - | SN::Server(_)), + (SKL::Global,_) => matches!(s, SN::Common + | SN::Server(_)), - SKL::Limited => SKL::PerClient.contains(s) - | SKL::Limits .contains(s), + (SKL::Limited,_) => SKL::PerClient.contains(s, end) + | SKL::Limits .contains(s, end), - SKL::ServerName => matches!(s, SN::Common) + (SKL::ServerName,_) => matches!(s, SN::Common) | matches!(s, SN::Server(ServerName(name)) if name == SPECIAL_SERVER_SECTION), - SKL::None => false, + (SKL::None,_) => false, } } } @@ -600,7 +602,7 @@ impl<'c> ResolveContext<'c> { self.agg.lookup_raw( key, self.all_sections.iter() - .filter(|s| sections.contains(s)) + .filter(|s| sections.contains(s, self.end)) ) } @@ -822,6 +824,7 @@ impl InstanceConfig { pub fn read(opts: &Opts, end: LinkEnd) -> Vec { let agg = (||{ let mut agg = Aggregate::new( + end, InstanceConfig::FIELDS.iter().cloned().collect(), );