Добавил возможность указывать токен через переменную среды

This commit is contained in:
2024-12-16 12:59:11 +03:00
parent e655e876d8
commit 89ce537d17

11
main.py
View File

@@ -32,11 +32,12 @@ def get_db():
security = HTTPBearer() security = HTTPBearer()
TOKEN: str = None TOKEN: str = os.environ.get("BUILD_INC_TOKEN", None)
THIS_SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) if TOKEN is None:
with open(os.path.join(THIS_SCRIPT_PATH, "token.json"), 'r') as f: THIS_SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
t = json.load(f) with open(os.path.join(THIS_SCRIPT_PATH, "token.json"), 'r') as f:
TOKEN = t["auth.token"] t = json.load(f)
TOKEN = t["auth.token"]
def get_current_user(credentials: HTTPAuthorizationCredentials = Security(security)): def get_current_user(credentials: HTTPAuthorizationCredentials = Security(security)):