From 60f2368e04c9862b17a03b5df1f732758f89e61c Mon Sep 17 00:00:00 2001 From: AyishikD <99983449+AyishikD@users.noreply.github.com> Date: Thu, 12 Sep 2024 22:21:38 +0530 Subject: [PATCH] dev: Disable GitHub auth and set default deployment to development Signed-off-by: AyishikD <99983449+AyishikD@users.noreply.github.com> Disabled GitHub authentication for the development setup and set the default deployment mode as "development" if not explicitly specified. This change affects the following files: - `suite.py` route: Removed GitHub auth requirement during development. - `main.py`: Modified to skip the `access_token` check during development. - `services`: Updated logic to bypass auth checks when in development mode. Signed-off-by: Ayishik Das Removed github auth requirements in development mode Signed-off-by: AyishikD <99983449+AyishikD@users.noreply.github.com> --- src/teuthology_api/main.py | 7 +++++-- src/teuthology_api/routes/suite.py | 16 ++++++++++++---- src/teuthology_api/services/helpers.py | 9 +++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/teuthology_api/main.py b/src/teuthology_api/main.py index c1d8afb..5e81474 100644 --- a/src/teuthology_api/main.py +++ b/src/teuthology_api/main.py @@ -9,7 +9,7 @@ load_dotenv() -DEPLOYMENT = os.getenv("DEPLOYMENT") +DEPLOYMENT = os.getenv("DEPLOYMENT", "development") SESSION_SECRET_KEY = os.getenv("SESSION_SECRET_KEY") PULPITO_URL = os.getenv("PULPITO_URL") PADDLES_URL = os.getenv("PADDLES_URL") @@ -35,7 +35,10 @@ def read_root(request: Request): allow_headers=["*"], ) -app.add_middleware(SessionMiddleware, secret_key=SESSION_SECRET_KEY) +if SESSION_SECRET_KEY: + app.add_middleware(SessionMiddleware, secret_key=SESSION_SECRET_KEY) +else: + log.warning("SESSION_SECRET_KEY is not set. Sessions are disabled.") app.include_router(suite.router) app.include_router(kill.router) app.include_router(login.router) diff --git a/src/teuthology_api/routes/suite.py b/src/teuthology_api/routes/suite.py index 13f1905..b9f06c2 100644 --- a/src/teuthology_api/routes/suite.py +++ b/src/teuthology_api/routes/suite.py @@ -1,5 +1,5 @@ import logging - +import os from fastapi import APIRouter, HTTPException, Depends, Request from teuthology_api.services.suite import run @@ -15,6 +15,7 @@ ) +DEPLOYMENT = os.getenv("DEPLOYMENT","development") @router.post("/", status_code=200) def create_run( request: Request, @@ -22,6 +23,13 @@ def create_run( access_token: str = Depends(get_token), logs: bool = False, ): - args = args.model_dump(by_alias=True) - args["--user"] = get_username(request) - return run(args, logs, access_token) + try: + args = args.model_dump(by_alias=True) + args["--user"] = get_username(request) + return run(args, logs, access_token) + except HTTPException as exc: + log.error(f"HTTP exception occurred: {exc.detail}") + raise + except Exception as exc: + log.error(f"Unexpected error occurred: {repr(exc)}") + raise HTTPException(status_code=500, detail="An unexpected error occurred.") \ No newline at end of file diff --git a/src/teuthology_api/services/helpers.py b/src/teuthology_api/services/helpers.py index a86d22c..52bda0a 100644 --- a/src/teuthology_api/services/helpers.py +++ b/src/teuthology_api/services/helpers.py @@ -16,12 +16,13 @@ PADDLES_URL = os.getenv("PADDLES_URL") ARCHIVE_DIR = os.getenv("ARCHIVE_DIR") +DEPLOYMENT = os.getenv("DEPLOYMENT", "development") log = logging.getLogger(__name__) def logs_run(func, args): """ - Run the command function in a seperate process (to isolate logs), + Run the command function in a separate process (to isolate logs), and return logs printed during the execution of the function. """ _id = str(uuid.uuid4()) @@ -72,6 +73,8 @@ def get_username(request: Request): """ Get username from request.session """ + if DEPLOYMENT == "development": + return "dev_user" username = request.session.get("user", {}).get("username") if username: return username @@ -87,6 +90,8 @@ def get_token(request: Request): """ Get access token from request.session """ + if DEPLOYMENT == "development": + return {"access_token": "dev_token", "token_type": "bearer"} token = request.session.get("user", {}).get("access_token") if token: return {"access_token": token, "token_type": "bearer"} @@ -95,4 +100,4 @@ def get_token(request: Request): status_code=401, detail="You need to be logged in", headers={"WWW-Authenticate": "Bearer"}, - ) + ) \ No newline at end of file