From 5672823680c99b5bef8ea1b4e89753479940f94d Mon Sep 17 00:00:00 2001 From: Dominik George <dominik.george@teckids.org> Date: Tue, 11 May 2021 21:00:57 +0200 Subject: [PATCH] [NSS] Allow JQ maps to be configured for endpoint subtypes and complete endpoints --- src/oauth.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/oauth.rs b/src/oauth.rs index 39ddd25..2e0a500 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -151,8 +151,24 @@ fn get_data(conf: &Config, prefix: &str, endpoint: &str, param: String, token: & .text()?) } +fn get_jq_prog(conf: &Config, prefix: &str, endpoint: &str) -> Option<String> { + match get_optional(&conf, &full_key(vec![prefix, "maps", endpoint])) { + Some(v) => Some (v), + None => { + // Try falling back to more generic program + match endpoint.find('.') { + Some(i) => { + debug!("JQ mapping program for {} not found; trying more generic definition", endpoint); + get_jq_prog(conf, prefix, &endpoint[..i]) + }, + None => None + } + } + } +} + pub fn get_data_jq<T: for<'de> Deserialize<'de>>(conf: &Config, prefix: &str, endpoint: &str, param: String, token: &BasicTokenResponse, multi: bool) -> Result<T, Box<dyn error::Error>> { - let res: Option<String> = get_optional(&conf, &full_key(vec![prefix, "maps", endpoint])); + let res: Option<String> = get_jq_prog(&conf, prefix, endpoint); let jq_code = match res { Some(s) => { debug!("Found jq mapping program for endpoint {}", endpoint); -- GitLab