style(cloud): reformat modules and restore except-tuple parentheses
Tests / Test failed: 4, passed: 744

Apply consistent line-length formatting across governance, plugins, the
SDK routers (governance_api, user_api), user_auth, and migrations
0003/0005/0006.

Also restore the parentheses on two except clauses that had been dropped
into invalid Python 3 `except A, B:` syntax: plugins._coerce_to_manifest
(KeyError, ValueError) and PasswordHasher.verify (InvalidHashError,
VerificationError). Both modules now import cleanly again.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-14 13:30:13 +08:00
co-authored by Claude Opus 4.6
parent c0a653fa3f
commit 9afbdc91fa
8 changed files with 117 additions and 38 deletions
@@ -78,7 +78,10 @@ def create_governance_router(*, repository, auth_provider: AuthProvider) -> APIR
submission_enabled=payload.submission_enabled,
allowed_host_ids=_unique_strings(payload.allowed_host_ids),
allowed_device_targets=(
tuple((item.host_id, item.device_id) for item in payload.allowed_device_targets)
tuple(
(item.host_id, item.device_id)
for item in payload.allowed_device_targets
)
if payload.allowed_device_targets is not None
else None
),
+33 -11
View File
@@ -103,7 +103,9 @@ def create_user_auth_router(
)
@router.post("/auth/login", response_model=UserResponse)
def login(payload: LoginRequest, request: Request, response: Response) -> UserResponse:
def login(
payload: LoginRequest, request: Request, response: Response
) -> UserResponse:
try:
result = user_auth_service.login(
username=payload.username,
@@ -142,7 +144,9 @@ def create_user_auth_router(
user_id, _ = _require_session(principal)
user = user_auth_service.repository.get_user(user_id) # type: ignore[attr-defined]
if user is None:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="unauthorized")
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="unauthorized"
)
return _user_response(user)
@router.post("/auth/logout", status_code=status.HTTP_204_NO_CONTENT)
@@ -181,7 +185,9 @@ def create_user_auth_router(
detail="invalid username or password",
) from exc
except UserValidationError as exc:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)) from exc
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)
) from exc
_clear_cookies(response)
response.status_code = status.HTTP_204_NO_CONTENT
return response
@@ -200,7 +206,9 @@ def create_user_auth_router(
offset=offset,
)
@router.post("/users", response_model=UserResponse, status_code=status.HTTP_201_CREATED)
@router.post(
"/users", response_model=UserResponse, status_code=status.HTTP_201_CREATED
)
def create_user(payload: UserCreateRequest, request: Request) -> UserResponse:
principal = _principal(request, required_scope=USERS_ADMIN_SCOPE)
_require_csrf(request, principal)
@@ -212,7 +220,9 @@ def create_user_auth_router(
password=payload.password,
)
except (UserValidationError, UserConflictError) as exc:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)) from exc
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)
) from exc
user_auth_service.record_admin_action(
actor_principal_id=principal.id,
target_user_id=user.id,
@@ -243,11 +253,17 @@ def create_user_auth_router(
updated_at=utc_now(),
)
except KeyError as exc:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="user not found") from exc
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="user not found"
) from exc
except LastAdministratorConflictError as exc:
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=str(exc)) from exc
raise HTTPException(
status_code=status.HTTP_409_CONFLICT, detail=str(exc)
) from exc
except UserValidationError as exc:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)) from exc
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)
) from exc
user_auth_service.record_admin_action(
actor_principal_id=principal.id,
target_user_id=user.id,
@@ -273,9 +289,13 @@ def create_user_auth_router(
correlation_id=current_correlation_id(),
)
except KeyError as exc:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="user not found") from exc
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="user not found"
) from exc
except UserValidationError as exc:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)) from exc
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)
) from exc
return _user_response(user)
@router.delete("/users/{user_id}/sessions", status_code=status.HTTP_204_NO_CONTENT)
@@ -284,7 +304,9 @@ def create_user_auth_router(
_require_csrf(request, principal)
user = user_auth_service.repository.get_user(user_id) # type: ignore[attr-defined]
if user is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="user not found")
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="user not found"
)
user_auth_service.repository.revoke_user_sessions( # type: ignore[attr-defined]
user_id,
revoked_at=utc_now(),