AQIT 0.1.0
Loading...
Searching...
No Matches
cloud_auth.py
Go to the documentation of this file.
1# Copyright (c) 2025-present Aquin Labs Private Limited. All Rights Reserved.
2"""Aquin cloud HTTP auth error helpers."""
3from __future__ import annotations
4
5import httpx
6
7
8def cloud_auth_error_exit(api_key: str | None = None) -> None:
9 """Print a clear login hint and exit when Aquin cloud rejects the API key."""
10 from aquin.auth_config import print_token_rejected, resolve_api_key
11
12 print_token_rejected(api_key or resolve_api_key(allow_missing=True) or None)
13
14
15def is_cloud_auth_failure(exc: BaseException) -> bool:
16 if isinstance(exc, httpx.HTTPStatusError) and exc.response is not None:
17 return exc.response.status_code in (401, 403)
18 msg = str(exc).lower()
19 return "401" in msg or "403" in msg or "unauthorized" in msg
20
21
22def exit_if_cloud_auth_error(exc: BaseException) -> None:
23 """Exit with a clear login hint when Aquin cloud rejects the API key."""
bool is_cloud_auth_failure(BaseException exc)
Definition cloud_auth.py:19
None exit_if_cloud_auth_error(BaseException exc)
Definition cloud_auth.py:26
None cloud_auth_error_exit(str|None api_key=None)
Definition cloud_auth.py:12