Fixes authentication to be configuration driven
diff --git a/.github/workflows/hamilton-ui-backend.yml b/.github/workflows/hamilton-ui-backend.yml index 66232e3..0249f68 100644 --- a/.github/workflows/hamilton-ui-backend.yml +++ b/.github/workflows/hamilton-ui-backend.yml
@@ -59,6 +59,7 @@ PGUSER: postgres HAMILTON_BLOB_STORE: local HAMILTON_LOCAL_BLOB_DIR: ./blob_data + HAMILTON_AUTH_MODE: integration_tests run: | cd ui/backend/server python manage.py sqlcreate @@ -78,6 +79,7 @@ PGUSER: postgres HAMILTON_BLOB_STORE: local HAMILTON_LOCAL_BLOB_DIR: ./blob_data + HAMILTON_AUTH_MODE: integration_tests run: | cd ui/backend/server python -m pytest tests/${{ matrix.testdir }} -vvvvv
diff --git a/ui/backend/server/server/api.py b/ui/backend/server/server/api.py index 7056b57..8cb7906 100644 --- a/ui/backend/server/server/api.py +++ b/ui/backend/server/server/api.py
@@ -9,13 +9,13 @@ from trackingserver_run_tracking import api as run_tracking_api from trackingserver_template import api as template_api -env = settings.HAMILTON_ENV +auth_mode = settings.HAMILTON_AUTH_MODE -if env == "local": +if auth_mode == "permissive": api = NinjaAPI(auth=[LocalAPIAuthenticator()]) -elif env == "integration_tests": +elif auth_mode == "integration_tests": api = NinjaAPI(auth=[TestAPIAuthenticator()]) -else: +elif auth_mode == "propelauth": propel_auth_instance = propelauth.init() api = NinjaAPI( auth=[
diff --git a/ui/backend/server/server/settings.py b/ui/backend/server/server/settings.py index 6e85c4e..697c443 100644 --- a/ui/backend/server/server/settings.py +++ b/ui/backend/server/server/settings.py
@@ -30,6 +30,10 @@ HAMILTON_ENV = get_from_env("HAMILTON_ENV", ["integration_tests", "local", "dev", "prod"]) +HAMILTON_AUTH_MODE = get_from_env( + "HAMILTON_AUTH_MODE", ["permissive", "integration_tests", "propelauth"] +) + PROPEL_AUTH_API_KEY = get_from_env("PROPEL_AUTH_API_KEY", allow_missing=True) PROPEL_AUTH_URL = get_from_env("PROPEL_AUTH_URL", allow_missing=True)