From da648e9f3947b038a3572dc8332aaaffd4ab0784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Weinehall?= Date: Tue, 21 Dec 2021 11:06:26 +0100 Subject: [PATCH] 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. --- src/helper.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/helper.rs b/src/helper.rs index b143db7..f8d3180 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -41,7 +41,12 @@ pub fn parse_application_secret>(secret: S) -> io::Result>(path: P) -> io::Result { 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>(key: S) -> io::Result { + serde_json::from_slice(key.as_ref()).map_err(|e| { io::Error::new( io::ErrorKind::InvalidData, format!("Bad service account key: {}", e),