From 21fa1e3f55c48f8dcd821e0941f071289ee6d9a5 Mon Sep 17 00:00:00 2001 From: iskanred Date: Tue, 30 Apr 2024 13:41:49 +0300 Subject: [PATCH] change config to be OS env everywhere --- bin/main.py | 30 +++++++++++++++--------------- internal/data/auth.py | 22 +++++++++++++++++----- ui/auth.py | 21 +++++++++++++++++---- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/bin/main.py b/bin/main.py index b3fdfd9..d7a33a6 100644 --- a/bin/main.py +++ b/bin/main.py @@ -10,6 +10,21 @@ from internal.item.router import router as item_router from internal.user.router import router as user_router +fb_config = { + "type": os.environ.get("TYPE"), + "project_id": os.environ.get("PROJECTID"), + "private_key_id": os.environ.get("PRIVATEKEYID"), + "private_key": os.environ.get("PRIVATEKEY"), + "client_email": os.environ.get("CLIENTEMAIL"), + "client_id": os.environ.get("CLIENTID"), + "token_uri": os.environ.get("TOKENURI"), + "apiKey": os.environ.get("APIKEY"), + "authDomain": os.environ.get("AUTHDOMAIN"), + "projectId": os.environ.get("PROJECTID"), + "databaseURL": "", + "storageBucket": "" +} + def create_app() -> FastAPI: app = FastAPI() @@ -18,21 +33,6 @@ def create_app() -> FastAPI: Base.metadata.create_all(bind=engine) - fb_config = { - "type": os.environ.get("TYPE"), - "project_id": os.environ.get("PROJECTID"), - "private_key_id": os.environ.get("PRIVATEKEYID"), - "private_key": os.environ.get("PRIVATEKEY"), - "client_email": os.environ.get("CLIENTEMAIL"), - "client_id": os.environ.get("CLIENTID"), - "token_uri": os.environ.get("TOKENURI"), - "apiKey": os.environ.get("APIKEY"), - "authDomain": os.environ.get("AUTHDOMAIN"), - "projectId": os.environ.get("PROJECTID"), - "databaseURL": "", - "storageBucket": "" - } - if not firebase_admin._apps: firebase_admin.initialize_app(credentials.Certificate(fb_config)) pyrebase.initialize_app(fb_config).auth() diff --git a/internal/data/auth.py b/internal/data/auth.py index 1b523c9..92869fa 100644 --- a/internal/data/auth.py +++ b/internal/data/auth.py @@ -1,10 +1,22 @@ -import json +import os from pyrebase import pyrebase +fb_config = { + "type": os.environ.get("TYPE"), + "project_id": os.environ.get("PROJECTID"), + "private_key_id": os.environ.get("PRIVATEKEYID"), + "private_key": os.environ.get("PRIVATEKEY"), + "client_email": os.environ.get("CLIENTEMAIL"), + "client_id": os.environ.get("CLIENTID"), + "token_uri": os.environ.get("TOKENURI"), + "apiKey": os.environ.get("APIKEY"), + "authDomain": os.environ.get("AUTHDOMAIN"), + "projectId": os.environ.get("PROJECTID"), + "databaseURL": "", + "storageBucket": "" +} + def pb_auth(): - auth = pyrebase.initialize_app( - json.load(open("./configs/firebase-pyrebase.json")) - ).auth() - return auth + return pyrebase.initialize_app(fb_config).auth() diff --git a/ui/auth.py b/ui/auth.py index 3916f05..a79a964 100644 --- a/ui/auth.py +++ b/ui/auth.py @@ -1,4 +1,4 @@ -import json +import os import pyrebase import requests @@ -6,9 +6,22 @@ import ui.utils as utils -pb_auth = pyrebase.initialize_app( - json.load(open("./configs/firebase-pyrebase.json")) -).auth() +fb_config = { + "type": os.environ.get("TYPE"), + "project_id": os.environ.get("PROJECTID"), + "private_key_id": os.environ.get("PRIVATEKEYID"), + "private_key": os.environ.get("PRIVATEKEY"), + "client_email": os.environ.get("CLIENTEMAIL"), + "client_id": os.environ.get("CLIENTID"), + "token_uri": os.environ.get("TOKENURI"), + "apiKey": os.environ.get("APIKEY"), + "authDomain": os.environ.get("AUTHDOMAIN"), + "projectId": os.environ.get("PROJECTID"), + "databaseURL": "", + "storageBucket": "" +} + +pb_auth = pyrebase.initialize_app(fb_config).auth() def create_user_with_email_and_password(email, username, password):