Skip to content

Commit

Permalink
dev: Disable GitHub auth and set default deployment to development
Browse files Browse the repository at this point in the history
Signed-off-by: AyishikD <[email protected]>

Disabled GitHub authentication for the development setup. This change affects the following files:

- `main.py`: Modified to skip the `access_token` check during development.
- `services`: Updated logic to bypass auth checks when in development mode.
  • Loading branch information
AyishikD committed Sep 16, 2024
1 parent 4660f3c commit 84d28e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/teuthology_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions src/teuthology_api/routes/suite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging

from fastapi import APIRouter, HTTPException, Depends, Request

from teuthology_api.services.suite import run
Expand All @@ -15,13 +14,21 @@
)



@router.post("/", status_code=200)
def create_run(
request: Request,
args: SuiteArgs,
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.")
9 changes: 7 additions & 2 deletions src/teuthology_api/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
PADDLES_URL = os.getenv("PADDLES_URL")
ARCHIVE_DIR = os.getenv("ARCHIVE_DIR")

DEPLOYMENT = os.getenv("DEPLOYMENT")
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())
Expand Down Expand Up @@ -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
Expand All @@ -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"}
Expand All @@ -95,4 +100,4 @@ def get_token(request: Request):
status_code=401,
detail="You need to be logged in",
headers={"WWW-Authenticate": "Bearer"},
)
)

0 comments on commit 84d28e2

Please sign in to comment.