fix(login): tolerate malformed selection containers and remove unreadable credential files on logout

This commit is contained in:
Alex Schapiro 2026-08-26 21:32:52 +00:00
parent baf0ff41fd
commit 5c61a2aee4

View file

@ -279,8 +279,8 @@ def _complete_selection(
scopes: list[str] | None,
workspace: str | None,
) -> dict[str, Any]:
organizations = [org for org in selection.get("organizations") or [] if isinstance(org, dict)]
catalog = [item for item in selection.get("scopes") or [] if isinstance(item, dict)]
organizations = _dict_items(selection.get("organizations"))
catalog = _dict_items(selection.get("scopes"))
selection_token = str(selection.get("selection_token") or "")
if not selection_token or not organizations:
raise PlatformAuthError("the server returned an incomplete selection response")
@ -310,6 +310,12 @@ def _complete_selection(
return _signed_in_record(response)
def _dict_items(value: Any) -> list[dict[str, Any]]:
if not isinstance(value, list):
return []
return [item for item in value if isinstance(item, dict)]
def _choose_workspace(
console: Console, organizations: list[dict[str, Any]], workspace: str | None
) -> dict[str, Any]:
@ -465,7 +471,7 @@ def _status(console: Console) -> int:
def _logout(console: Console) -> int:
if read_record() is None:
if read_record() is None and not AUTH_PATH.exists():
console.print("[yellow]Not signed in.[/]")
return 0
if not logout():