From 7de85788bb6c57c60e8cd744edf85e81b8fade32 Mon Sep 17 00:00:00 2001 From: yevkim Date: Wed, 27 Nov 2024 21:05:47 +0800 Subject: [PATCH] Use creds json instead of env for firebase --- .../functions/fb_manager/firebaseManager.py | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/backend/functions/fb_manager/firebaseManager.py b/backend/functions/fb_manager/firebaseManager.py index 536d191..4a9e84b 100644 --- a/backend/functions/fb_manager/firebaseManager.py +++ b/backend/functions/fb_manager/firebaseManager.py @@ -28,23 +28,25 @@ def _initialize_app(self): if not firebase_admin._apps: # Replace newlines in private key - private_key = os.getenv("FB_PRIVATE_KEY").replace("\\n", "\n") - - cred = credentials.Certificate( - { - "type": os.getenv("FB_TYPE"), - "project_id": os.getenv("FB_PROJECT_ID"), - "private_key_id": os.getenv("FB_PRIVATE_KEY_ID"), - "private_key": private_key, # Use the processed private key - "client_email": os.getenv("FB_CLIENT_EMAIL"), - "client_id": os.getenv("FB_CLIENT_ID"), - "auth_uri": os.getenv("FB_AUTH_URI"), - "token_uri": os.getenv("FB_TOKEN_URI"), - "auth_provider_x509_cert_url": os.getenv("FB_AUTH_PROVIDER_X509_CERT_URL"), - "client_x509_cert_url": os.getenv("FB_CLIENT_X509_CERT_URL"), - "universe_domain": os.getenv("FB_UNIVERSE_DOMAIN"), - } - ) + # private_key = os.getenv("FB_PRIVATE_KEY").replace("\\n", "\n") + path_to_creds = os.getenv("GOOGLE_APPLICATION_CREDENTIALS") + cred = credentials.Certificate(path_to_creds) # Adjust path as needed + + # cred = credentials.Certificate( + # { + # "type": os.getenv("FB_TYPE"), + # "project_id": os.getenv("FB_PROJECT_ID"), + # "private_key_id": os.getenv("FB_PRIVATE_KEY_ID"), + # "private_key": private_key, # Use the processed private key + # "client_email": os.getenv("FB_CLIENT_EMAIL"), + # "client_id": os.getenv("FB_CLIENT_ID"), + # "auth_uri": os.getenv("FB_AUTH_URI"), + # "token_uri": os.getenv("FB_TOKEN_URI"), + # "auth_provider_x509_cert_url": os.getenv("FB_AUTH_PROVIDER_X509_CERT_URL"), + # "client_x509_cert_url": os.getenv("FB_CLIENT_X509_CERT_URL"), + # "universe_domain": os.getenv("FB_UNIVERSE_DOMAIN"), + # } + # ) initialize_app(cred) self.firestore_client = firestore.client()