Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from pydantic import BaseModel
from jose import jwt
from jose.exceptions import JWTError
from kernelci.api.models import (

Check failure on line 49 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
Node,
Hierarchy,
PublishEvent,
Expand Down Expand Up @@ -895,7 +895,13 @@

if from_ts:
if isinstance(from_ts, str):
from_ts = datetime.fromisoformat(from_ts)
try:
from_ts = datetime.fromisoformat(from_ts)
except ValueError as exc:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Invalid 'from' parameter, must be an ISO 8601 datetime"
) from exc
query_params['timestamp'] = {'$gt': from_ts}
if path:
query_params['data.path'] = {'$regex': path}
Expand Down
9 changes: 2 additions & 7 deletions scripts/usermanager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3

Check warning on line 1 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Missing module docstring
import argparse
import getpass
import json
Expand Down Expand Up @@ -133,7 +133,7 @@
raise SystemExit(1)
try:
payload = json.loads(body) if body else []
except json.JSONDecodeError as exc:

Check warning on line 136 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Redefining name 'exc' from outer scope (line 14)
raise SystemExit("Failed to parse users response") from exc
items = _parse_paginated_items(payload)
matches = []
Expand Down Expand Up @@ -174,7 +174,7 @@
raise SystemExit(1)
try:
payload = json.loads(body) if body else {}
except json.JSONDecodeError as exc:

Check warning on line 177 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Redefining name 'exc' from outer scope (line 14)
raise SystemExit("Failed to parse user-groups response") from exc
items = _parse_paginated_items(payload)
matches = [
Expand Down Expand Up @@ -203,7 +203,7 @@
raise SystemExit(1)
try:
payload = json.loads(body) if body else {}
except json.JSONDecodeError as exc:

Check warning on line 206 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Redefining name 'exc' from outer scope (line 14)
raise SystemExit("Failed to parse user-group response") from exc
resolved_name = payload.get("name")
if not resolved_name:
Expand All @@ -222,7 +222,7 @@
raise SystemExit(1)
try:
payload = json.loads(body) if body else {}
except json.JSONDecodeError as exc:

Check warning on line 225 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Redefining name 'exc' from outer scope (line 14)
raise SystemExit("Failed to parse user response") from exc
current_groups = _extract_group_names(payload)
data = {
Expand All @@ -248,7 +248,7 @@
with urllib.request.urlopen(req) as response:
payload = response.read().decode("utf-8")
return response.status, payload
except urllib.error.HTTPError as exc:

Check warning on line 251 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Redefining name 'exc' from outer scope (line 14)
payload = exc.read().decode("utf-8")
return exc.code, payload

Expand All @@ -274,7 +274,7 @@
)


def main():

Check warning on line 277 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Too many branches (47/12)

Check warning on line 277 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Too many local variables (41/15)

Check warning on line 277 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Missing function or method docstring
command_help = [
("accept-invite", "Accept an invite"),
("assign-group", "Assign group(s) to a user"),
Expand All @@ -298,14 +298,9 @@
default_paths = "\n".join(f" - {path}" for path in DEFAULT_CONFIG_PATHS)
parser = argparse.ArgumentParser(
description="KernelCI API user management helper",
usage=(
"usermanager.py [-h] [--config CONFIG] [--api-url API_URL] "
"[--token TOKEN] [--instance INSTANCE] [--token-label TOKEN_LABEL]\n"
" <command> [<args>]\n\n"
"Commands:\n"
f"{command_list}"
),
epilog=(
"Commands:\n"
f"{command_list}\n\n"
"Examples:\n"
" ./scripts/usermanager.py invite --username alice --email "
"alice@example.org --return-token\n"
Expand Down Expand Up @@ -575,7 +570,7 @@
if status < 400:
try:
payload = json.loads(body) if body else {}
except json.JSONDecodeError as exc:

Check warning on line 573 in scripts/usermanager.py

View workflow job for this annotation

GitHub Actions / Lint

Redefining name 'exc' from outer scope (line 14)
raise SystemExit("Failed to parse login response") from exc
token = payload.get("access_token")
if not token:
Expand Down
Loading