Skip to content
Snippets Groups Projects
Verified Commit a698ac16 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

[Config] Make scopes optional

parent 3944d356
No related branches found
No related tags found
No related merge requests found
...@@ -58,12 +58,16 @@ pub fn argv_to_config(argv: &Vec<String>) -> config::Config { ...@@ -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> { 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) { match conf.get(key) {
Ok(v) => Some(v), Ok(v) => Some(v),
Err(_) => { Err(_) => {
// Try falling back to parent block // Try falling back to parent block
match key.find('.') { 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, None => None,
} }
}, },
......
...@@ -71,7 +71,10 @@ fn get_client<E: Copy>(conf: Config, prefix: &str, error_value: E) -> Result<Bas ...@@ -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> { 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 client = get_client(conf, prefix, error_value)?;
let mut request = client.exchange_client_credentials(); 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 ...@@ -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> { 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_username = ResourceOwnerUsername::new(username);
let res_password = ResourceOwnerPassword::new(password); let res_password = ResourceOwnerPassword::new(password);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment