diff --git a/src/oauth.rs b/src/oauth.rs index 39ddd25f11bd7122f30a527f1d9c849e40567c47..2e0a500cfd6c5b0df897a4c9fc87f54c3d1e41fa 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);