change(assist-stats): removed path prefix, should use the root_path

This commit is contained in:
Shekar Siri 2023-11-07 15:39:33 +01:00
parent 23e0a97d30
commit 1d74cd95e5
2 changed files with 14 additions and 4 deletions

View file

@ -4,7 +4,11 @@ verify_ssl = true
name = "pypi"
[packages]
fastapi = "==0.103.1"
fastapi = "*"
sqlalchemy = "==2.0.21"
uvicorn = "==0.23.2"
python-decouple = "==3.8"
psycopg2-binary = "==2.9.7"
[dev-packages]

View file

@ -10,14 +10,21 @@ class AuthHandler:
"""
Authorization method using an API key.
"""
self.__api_keys = [config("ACCESS_TOKEN")]
# Attempt to get the ACCESS_TOKEN, if not set, default to an empty list
api_key = config("ACCESS_TOKEN", default=None)
self.__api_keys = [api_key] if api_key else []
def __contains__(self, api_key):
# Skip the check if no API keys are configured
if not self.__api_keys:
return True
return api_key in self.__api_keys
def add_key(self, key):
"""Adds new key for authentication."""
self.__api_keys.append(key)
if key: # Ensure we don't add empty keys
self.__api_keys.append(key)
auth_method = AuthHandler()
@ -25,7 +32,6 @@ auth_method = AuthHandler()
def api_key_auth(api_key: str = Depends(oauth2_scheme)):
"""Method to verify auth."""
global auth_method
if api_key not in auth_method:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,