zabgrab.adapters.secrets

API token storage in the operating system’s keyring.

Module Attributes

PREFIX

Tokens are stored one per keyring entry, named token1, token2, .

RESET_SCAN

How many consecutive missing entries KeyringSecrets.delete_all() checks past the last entry it finds, to catch anything left beyond a gap.

Classes

KeyringSecrets()

Stores tokens in the system keyring, keyed by server URL.

zabgrab.adapters.secrets.PREFIX = 'token'

Tokens are stored one per keyring entry, named token1, token2, … with no gaps (keyring backends can’t be listed, so zabgrab reads entries in order until it finds a missing one). Each entry holds {"url": ..., "token": ...} as JSON.

zabgrab.adapters.secrets.RESET_SCAN = 256

How many consecutive missing entries KeyringSecrets.delete_all() checks past the last entry it finds, to catch anything left beyond a gap.

class zabgrab.adapters.secrets.KeyringSecrets[source]

Bases: object

Stores tokens in the system keyring, keyed by server URL.

A missing or broken keyring backend is treated as “no tokens stored” when reading, and as an error when changing anything.

service

The keyring service the entries are stored under.

Type:

str

get_token(url)[source]

Get the token stored for a server URL, if any.

Parameters:

url (str)

Return type:

str | None

set_token(url, token)[source]

Store a token for a server URL, replacing any stored before.

Raises:

ZabgrabError – If the keyring can’t be written.

Parameters:
Return type:

None

delete_token(url)[source]

Delete the token stored for a server URL.

Returns:

bool – Whether a token was stored.

Raises:

ZabgrabError – If the keyring can’t be changed.

Parameters:

url (str)

Return type:

bool

urls()[source]

Get the server URLs with stored tokens, sorted.

Return type:

list[str]

delete_all()[source]

Delete every zabgrab entry, including unreadable ones and any past a gap.

Returns:

int – How many tokens were stored.

Raises:

ZabgrabError – If the keyring can’t be changed.

Return type:

int