AQIT 0.1.0
Loading...
Searching...
No Matches
aquin.auth_config Namespace Reference

Functions

Path config_path ()
str _base_url ()
None safe_print (str msg, *, file=None)
str normalize_cli_token (str raw)
str|None validate_cli_token_format (str raw)
dict[str, Any] load_config ()
None save_config (dict[str, Any] cfg)
dict[str, Any] _migrate_legacy (dict[str, Any] cfg)
str _account_id (str|None email, str|None name, str|None user_id)
str active_account_id (dict[str, Any]|None cfg=None)
list[dict[str, str]] list_accounts (dict[str, Any]|None cfg=None)
str resolve_api_key (*, bool allow_missing=False, str|None explicit=None)
dict[str, Any] fetch_whoami (str api_key, str|None base_url=None)
str format_account_label (dict[str, Any] whoami)
str cached_account_label (dict[str, Any]|None cfg=None)
str format_revoked_ago (str revoked_at)
None _cache_whoami_ok (str api_key, dict[str, Any] whoami)
bool _cached_whoami_fresh (str api_key, *, float ttl_s=_WHOAMI_CACHE_TTL_S)
str require_valid_login (*, bool force_refresh=False)
None print_token_rejected (str|None api_key=None)
str save_login (str api_key, *, dict[str, Any]|None whoami=None)
dict[str, str] switch_account (str account_id)
None logout_local (*, str|None account_id=None)

Variables

str _CONFIG_PATH = Path.home() / ".aquin" / "config.json"
str _BASE_URL_DEFAULT = "https://api.aquin.app"
int _WHOAMI_CACHE_TTL_S = 15 * 60
int _MIN_TOKEN_LEN = 20

Function Documentation

◆ _account_id()

str _account_id ( str | None email,
str | None name,
str | None user_id )
protected

Definition at line 114 of file auth_config.py.

Referenced by save_login().

◆ _base_url()

str _base_url ( )
protected

Definition at line 28 of file auth_config.py.

Referenced by fetch_whoami().

◆ _cache_whoami_ok()

None _cache_whoami_ok ( str api_key,
dict[str, Any] whoami )
protected
Remember a successful whoami so we do not hit the network every command.

Definition at line 301 of file auth_config.py.

References active_account_id(), load_config(), normalize_cli_token(), and save_config().

Referenced by require_valid_login().

◆ _cached_whoami_fresh()

bool _cached_whoami_fresh ( str api_key,
* ,
float ttl_s = _WHOAMI_CACHE_TTL_S )
protected

Definition at line 326 of file auth_config.py.

References active_account_id(), load_config(), and normalize_cli_token().

Referenced by require_valid_login().

◆ _migrate_legacy()

dict[str, Any] _migrate_legacy ( dict[str, Any] cfg)
protected

Definition at line 94 of file auth_config.py.

Referenced by load_config().

◆ active_account_id()

str active_account_id ( dict[str, Any] | None cfg = None)

◆ cached_account_label()

str cached_account_label ( dict[str, Any] | None cfg = None)
Account label from saved login metadata - no network.

Definition at line 262 of file auth_config.py.

References active_account_id(), and load_config().

◆ config_path()

Path config_path ( )

Definition at line 24 of file auth_config.py.

◆ fetch_whoami()

dict[str, Any] fetch_whoami ( str api_key,
str | None base_url = None )

◆ format_account_label()

str format_account_label ( dict[str, Any] whoami)

Definition at line 254 of file auth_config.py.

Referenced by switch_account().

◆ format_revoked_ago()

str format_revoked_ago ( str revoked_at)

Definition at line 279 of file auth_config.py.

Referenced by print_token_rejected(), require_valid_login(), and save_login().

◆ list_accounts()

list[dict[str, str]] list_accounts ( dict[str, Any] | None cfg = None)

Definition at line 129 of file auth_config.py.

References active_account_id(), and load_config().

◆ load_config()

◆ logout_local()

None logout_local ( * ,
str | None account_id = None )

Definition at line 466 of file auth_config.py.

References active_account_id(), load_config(), and save_config().

◆ normalize_cli_token()

str normalize_cli_token ( str raw)
Strip whitespace / accidental 'Bearer ' prefix.

Definition at line 49 of file auth_config.py.

Referenced by _cache_whoami_ok(), _cached_whoami_fresh(), fetch_whoami(), resolve_api_key(), save_login(), and validate_cli_token_format().

◆ print_token_rejected()

None print_token_rejected ( str | None api_key = None)
User-facing auth failure with revoked-at hint when available.

Definition at line 384 of file auth_config.py.

References fetch_whoami(), format_revoked_ago(), and safe_print().

Referenced by require_valid_login().

◆ require_valid_login()

str require_valid_login ( * ,
bool force_refresh = False )
Ensure a CLI token is present AND valid with Aquin cloud.
Exits the process on failure. Returns the verified api key.

Definition at line 342 of file auth_config.py.

References _cache_whoami_ok(), _cached_whoami_fresh(), fetch_whoami(), format_revoked_ago(), print_token_rejected(), resolve_api_key(), safe_print(), and validate_cli_token_format().

◆ resolve_api_key()

str resolve_api_key ( * ,
bool allow_missing = False,
str | None explicit = None )

Definition at line 147 of file auth_config.py.

References active_account_id(), load_config(), normalize_cli_token(), and safe_print().

Referenced by require_valid_login().

◆ safe_print()

None safe_print ( str msg,
* ,
file = None )
Print without crashing on Windows cp1252 consoles (no fancy unicode).

Definition at line 32 of file auth_config.py.

Referenced by print_token_rejected(), require_valid_login(), and resolve_api_key().

◆ save_config()

None save_config ( dict[str, Any] cfg)

Definition at line 89 of file auth_config.py.

Referenced by _cache_whoami_ok(), logout_local(), save_login(), and switch_account().

◆ save_login()

str save_login ( str api_key,
* ,
dict[str, Any] | None whoami = None )

◆ switch_account()

dict[str, str] switch_account ( str account_id)

Definition at line 437 of file auth_config.py.

References format_account_label(), load_config(), and save_config().

◆ validate_cli_token_format()

str | None validate_cli_token_format ( str raw)
Return an error message if the token is obviously not an Aquin CLI token.
Returns None when the shape looks acceptable (still must pass whoami).

Definition at line 57 of file auth_config.py.

References normalize_cli_token().

Referenced by fetch_whoami(), require_valid_login(), and save_login().

Variable Documentation

◆ _BASE_URL_DEFAULT

str aquin.auth_config._BASE_URL_DEFAULT = "https://api.aquin.app"
protected

Definition at line 18 of file auth_config.py.

◆ _CONFIG_PATH

str aquin.auth_config._CONFIG_PATH = Path.home() / ".aquin" / "config.json"
protected

Definition at line 17 of file auth_config.py.

◆ _MIN_TOKEN_LEN

int aquin.auth_config._MIN_TOKEN_LEN = 20
protected

Definition at line 21 of file auth_config.py.

◆ _WHOAMI_CACHE_TTL_S

int aquin.auth_config._WHOAMI_CACHE_TTL_S = 15 * 60
protected

Definition at line 20 of file auth_config.py.