diff --git a/src/config.rs b/src/config.rs index ca3b3be28f4c81dbc6860f0483f86730c062c860..9a8137de513ecdd470e7bdb6e0d0fcc40689942e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -58,12 +58,16 @@ pub fn argv_to_config(argv: &Vec<String>) -> config::Config { } pub fn get_optional<'de, T: Deserialize<'de>>(conf: &config::Config, key: &str) -> Option<T> { + debug!("Looking up key {} in config", key); match conf.get(key) { Ok(v) => Some(v), Err(_) => { // Try falling back to parent block match key.find('.') { - Some(i) => get_optional(conf, &key[i+1..]), + Some(i) => { + debug!("Key {} not found in config, trying parent block", key); + get_optional(conf, &key[i+1..]) + }, None => None, } }, diff --git a/src/oauth.rs b/src/oauth.rs index c5d140b15483d8c991a2e1c858921b073c7063a1..ebdd5f3efe4c6b8f52f39cd44098fca46f656c94 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -71,7 +71,10 @@ fn get_client<E: Copy>(conf: Config, prefix: &str, error_value: E) -> Result<Bas } pub fn get_access_token<E: Copy>(conf: Config, prefix: &str, error_value: E, unauth_value: E) -> Result<BasicTokenResponse, E> { - let scopes: Vec<&str> = get_or_error(&conf, &full_key(prefix, "scopes"), error_value)?; + let scopes: Vec<String> = match get_optional(&conf, &full_key(prefix, "scopes")) { + Some(v) => v, + None => vec![] + }; let client = get_client(conf, prefix, error_value)?; let mut request = client.exchange_client_credentials(); @@ -96,7 +99,10 @@ pub fn get_access_token<E: Copy>(conf: Config, prefix: &str, error_value: E, una } pub fn get_access_token_password<E: Copy>(conf: Config, prefix: &str, username: String, password: String, error_value: E, unauth_value: E) -> Result<BasicTokenResponse, E> { - let scopes: Vec<&str> = get_or_error(&conf, &full_key(prefix, "scopes"), error_value)?; + let scopes: Vec<String> = match get_optional(&conf, &full_key(prefix, "scopes")) { + Some(v) => v, + None => vec![] + }; let res_username = ResourceOwnerUsername::new(username); let res_password = ResourceOwnerPassword::new(password);