Skip to content

Commit

Permalink
Handle missing token in isAdmin() func
Browse files Browse the repository at this point in the history
Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Nov 23, 2024
1 parent 20a8fc9 commit 8f8ea00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/teuthology_api/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ async def isAdmin(username, token):
if not (GH_ORG_TEAM_URL and ADMIN_TEAM):
log.error("GH_ORG_TEAM_URL or ADMIN_TEAM is not set in .env")
return False
if not (token and username):
raise HTTPException(
status_code=401,
detail="You are probably not logged in (username or token missing)",
headers={"WWW-Authenticate": "Bearer"},
)
TEAM_MEMBER_URL = f"{GH_ORG_TEAM_URL}/{ADMIN_TEAM}/memberships/{username}"
async with httpx.AsyncClient() as client:
headers = {
Expand Down
2 changes: 1 addition & 1 deletion src/teuthology_api/services/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def run(args, send_logs: bool, token: dict, request: Request):
if (run_owner.lower() != username.lower()) and (
run_owner.lower() != f"scheduled_{username.lower()}@teuthology"
):
isUserAdmin = await isAdmin(username, token["access_token"])
isUserAdmin = await isAdmin(username, token.get("access_token"))
if not isUserAdmin:
log.error(
"%s doesn't have permission to kill a job scheduled by: %s",
Expand Down

0 comments on commit 8f8ea00

Please sign in to comment.