CredentialManager#

class astropathdb.db_io.credentials.CredentialManager(store=None)#

Bases: PathUtils

Select one credential source and complete only its own account via keyring.

Parameters:

store (CredentialStore | None)

CredentialManager Properties#

stores_keyring

Whether a successful login saves the resolved pair to keyring.

CredentialManager Methods#

resolve([username, password, token, ...])

Resolve the first selected source; never fall through after selecting an account.

check_store(credentials)

Preflight keyring storage before authentication changes process state.

save(credentials, token)

Store an authenticated session; a failed keyring write prevents token export.

login([username, password, token, credential_filename])

Select, activate, and store one SciScript session, returning its token.

CredentialManager References#

Property Reference#

property stores_keyring#
Type:

bool

Return type:

bool

Whether a successful login saves the resolved pair to keyring.

Method Reference#

method resolve(username=None, password=None, *, token=None, credential_filename=None, existing_token=None)#

Resolve the first selected source; never fall through after selecting an account.

Parameters:
  • username (str | None)

  • password (str | None)

  • token (str | None)

  • credential_filename (str | Path | None)

  • existing_token (str | None)

Return type:

Credentials

method check_store(credentials)#

Preflight keyring storage before authentication changes process state.

Parameters:

credentials (Credentials)

Return type:

None

method save(credentials, token)#

Store an authenticated session; a failed keyring write prevents token export.

Parameters:
Return type:

None

method login(username=None, password=None, *, token=None, credential_filename=None)#

Select, activate, and store one SciScript session, returning its token.

Compute reuses its managed session. Elsewhere, explicit inputs are resolved without the existing session, which only a bare call may reuse; token registers an explicit token without a login request. The manager’s store is checked before activation changes process state and written after it.

Raises:

CasJobsLoginError – No active token was obtained.

Parameters:
  • username (str | None)

  • password (str | None)

  • token (str | None)

  • credential_filename (str | Path | None)

Return type:

str

Private Attribute Reference#

attribute _store = None#
attribute _backend: KeyringBackend | None = None#
attribute _backend_error: type[Exception]#

Private Method Reference#

static _environment_value(name)#

Treat empty environment values as absent while preserving nonempty values.

Parameters:

name (str)

Return type:

str | None

static _read_dotenv(contents)#

Parse dotenv fields in one pass, rejecting a partially parsed file.

Parameters:

contents (str)

Return type:

dict[str, str | None]

static _read_json(contents)#

Parse a JSON object whose credential fields are strings or null.

Parameters:

contents (str)

Return type:

dict[str, str | None]

static _read_text(contents)#

Parse the legacy username and password lines, stripping each.

Parameters:

contents (str)

Return type:

dict[str, str | None]

static _activate(credentials)#

Register the selected credentials with SciScript, returning its active token.

A reused token is returned without a request. Raw SciScript errors are replaced because they can carry the password or response body.

Parameters:

credentials (Credentials)

Return type:

str | None

method _keyring(*, required)#

Select an available backend once, so a later save uses the checked backend.

Parameters:

required (bool)

Return type:

KeyringBackend | None

method _stored_password(username)#

Return this account’s keyring password; an inaccessible keyring has none.

Parameters:

username (str)

Return type:

str | None

method _credentials(username=None, password=None, token=None)#

Prefer the source’s token, otherwise complete its own account’s password.

Parameters:
  • username (str | None)

  • password (str | None)

  • token (str | None)

Return type:

Credentials

method _read_file(path)#

Parse an existing credential file by its suffix without logging its contents.

Parameters:

path (str | Path)

Return type:

Credentials