feat(helpers): Add service account key helper

This commit is contained in:
Lewin Bormann
2016-09-20 13:18:13 +02:00
parent 0506ffaa44
commit d151e75454

View File

@@ -8,9 +8,11 @@
// Refer to the project root for licensing information.
use serde_json;
use std::io;
use std::io::{self, Read};
use std::fs;
use service_account::ServiceAccountKey;
use types::{ConsoleApplicationSecret, ApplicationSecret};
pub fn read_application_secret(file: &String) -> io::Result<ApplicationSecret> {
@@ -42,3 +44,14 @@ pub fn parse_application_secret(secret: &String) -> io::Result<ApplicationSecret
}
}
}
pub fn service_account_key_from_file(path: &String) -> io::Result<ServiceAccountKey> {
let mut key = String::new();
let mut file = try!(fs::OpenOptions::new().read(true).open(path));
try!(file.read_to_string(&mut key));
match serde_json::from_str(&key) {
Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, format!("{}", e))),
Ok(decoded) => Ok(decoded),
}
}