feat(helper): add parse_service_account_key() function

Add parse_service_account_key() in line with parse_application_secret().
Can be used to e.g. pass the service account key through an env variable.
This commit is contained in:
Björn Weinehall
2021-12-21 11:06:26 +01:00
parent 2c5205ce32
commit da648e9f39

View File

@@ -41,7 +41,12 @@ pub fn parse_application_secret<S: AsRef<[u8]>>(secret: S) -> io::Result<Applica
/// Cloud Console or the respective console of your service provider.
pub async fn read_service_account_key<P: AsRef<Path>>(path: P) -> io::Result<ServiceAccountKey> {
let key = tokio::fs::read(path).await?;
serde_json::from_slice(&key).map_err(|e| {
parse_service_account_key(key)
}
/// Read a service account key from a JSON string.
pub fn parse_service_account_key<S: AsRef<[u8]>>(key: S) -> io::Result<ServiceAccountKey> {
serde_json::from_slice(key.as_ref()).map_err(|e| {
io::Error::new(
io::ErrorKind::InvalidData,
format!("Bad service account key: {}", e),