From 1d74cd95e51684e9c3c67b0e4d3c5aecf67da6dc Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Tue, 7 Nov 2023 15:39:33 +0100 Subject: [PATCH] change(assist-stats): removed path prefix, should use the root_path --- ee/assist-stats/Pipfile | 6 +++++- ee/assist-stats/auth.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ee/assist-stats/Pipfile b/ee/assist-stats/Pipfile index 6714c88a2..d331c4df9 100644 --- a/ee/assist-stats/Pipfile +++ b/ee/assist-stats/Pipfile @@ -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] diff --git a/ee/assist-stats/auth.py b/ee/assist-stats/auth.py index 27ec95d34..ec440be58 100644 --- a/ee/assist-stats/auth.py +++ b/ee/assist-stats/auth.py @@ -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,