Skip to content

Commit 2c7f0e6

Browse files
committed
Handle missing token in isAdmin() func
Signed-off-by: Vallari Agrawal <[email protected]>
1 parent 5e4d1e4 commit 2c7f0e6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Diff for: src/teuthology_api/services/helpers.py

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ async def isAdmin(username, token):
107107
if not (GH_ORG_TEAM_URL and ADMIN_TEAM):
108108
log.error("GH_ORG_TEAM_URL or ADMIN_TEAM is not set in .env")
109109
return False
110+
if not (token and username):
111+
raise HTTPException(
112+
status_code=401,
113+
detail="You are probably not logged in (username or token missing)",
114+
headers={"WWW-Authenticate": "Bearer"},
115+
)
110116
TEAM_MEMBER_URL = f"{GH_ORG_TEAM_URL}/{ADMIN_TEAM}/memberships/{username}"
111117
async with httpx.AsyncClient() as client:
112118
headers = {

Diff for: src/teuthology_api/services/kill.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def run(args, send_logs: bool, token: dict, request: Request):
3838
if (run_owner.lower() != username.lower()) and (
3939
run_owner.lower() != f"scheduled_{username.lower()}@teuthology"
4040
):
41-
isUserAdmin = await isAdmin(username, token["access_token"])
41+
isUserAdmin = await isAdmin(username, token.get("access_token"))
4242
if not isUserAdmin:
4343
log.error(
4444
"%s doesn't have permission to kill a job scheduled by: %s",

0 commit comments

Comments
 (0)