Add CLIENT_ID env var for compiling with a client id, remove unnecessary serde_derive

This commit is contained in:
Sasha Hilton 2018-02-07 18:56:25 +01:00
parent 7ead896ae7
commit 9784d98847
2 changed files with 15 additions and 3 deletions

View file

@ -13,9 +13,22 @@ pub struct Token {
pub scope: Vec<String>, pub scope: Vec<String>,
} }
pub fn get_token(session: &Session, client_id: &str, scopes: &str) -> Box<Future<Item = Token, Error = MercuryError>> { pub fn get_token(session: &Session, client_id: Option<&str>, scopes: &str) -> Box<Future<Item = Token, Error = MercuryError>> {
let client_id_env: Option<&'static str> = option_env!("CLIENT_ID");
let client_key: &str;
match client_id_env {
None => {
match client_id {
None => { panic!("No Client ID available.") },
Some(ref cid) => { client_key = cid },
}
},
Some(ref cid_env) => { client_key = cid_env }
}
let url = format!("hm://keymaster/token/authenticated?client_id={}&scope={}", let url = format!("hm://keymaster/token/authenticated?client_id={}&scope={}",
client_id, scopes); client_key, scopes);
Box::new(session.mercury().get(url).map(move |response| { Box::new(session.mercury().get(url).map(move |response| {
let data = response.payload.first().expect("Empty payload"); let data = response.payload.first().expect("Empty payload");
let data = String::from_utf8(data.clone()).unwrap(); let data = String::from_utf8(data.clone()).unwrap();

View file

@ -4,7 +4,6 @@
#[macro_use] extern crate log; #[macro_use] extern crate log;
#[macro_use] extern crate serde_json; #[macro_use] extern crate serde_json;
#[macro_use] extern crate serde_derive;
extern crate base64; extern crate base64;
extern crate crypto; extern crate crypto;