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

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

13
main.py
View File

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