zabgrab.services.tokens¶
Managing stored API tokens (zabgrab token).
Functions
|
Store a token for a server in the keyring. |
|
Check the token zabgrab would use for a server against the server. |
|
Ask which server's stored token to act on. |
|
Delete the stored token for a server, confirming first unless |
|
Delete every stored token, confirming first unless |
|
List where each server's token comes from. |
Classes
|
The result of checking a token. |
|
The outcome of checking a token against its server. |
|
Whether a server has a token, and where from. |
- class zabgrab.services.tokens.TokenStatus(server, stored, env_var, env_set)[source]¶
Bases:
objectWhether a server has a token, and where from.
- class zabgrab.services.tokens.CheckState(*values)[source]¶
Bases:
StrEnumThe outcome of checking a token against its server.
- VALID¶
The server accepted it.
- REJECTED¶
The server rejected it.
- MISSING¶
There’s no token for the server.
- ERROR¶
The server couldn’t be asked (e.g. it’s unreachable).
- class zabgrab.services.tokens.CheckResult(state, detail='')[source]¶
Bases:
objectThe result of checking a token.
- Parameters:
state (CheckState)
detail (str)
- state¶
The outcome.
- Type:
- zabgrab.services.tokens.token_statuses(config, secrets, env)[source]¶
List where each server’s token comes from.
- Parameters:
config (Config) – The configured servers.
secrets (SecretStore) – The stored tokens.
env (mapping of str to str) – Environment variables.
- Returns:
list of TokenStatus – Every configured server, then any other server with a stored token.
- Return type:
- async zabgrab.services.tokens.check_token(server, *, factory, secrets, env)[source]¶
Check the token zabgrab would use for a server against the server.
- Parameters:
server (Server) – The server.
factory (ClientFactory) – Creates the client.
secrets (SecretStore) – The stored tokens.
env (mapping of str to str) – Environment variables (for
token_env).
- Returns:
CheckResult – Whether the token is valid, rejected, missing or couldn’t be checked.
- Return type:
- async zabgrab.services.tokens.add_token(server, token, *, factory, ui, secrets, env, check=True, update_url=None)[source]¶
Store a token for a server in the keyring.
- Parameters:
server (Server) – The server.
token (str or None) – The token, or
Noneto ask for it.factory (ClientFactory) – Creates the client, to check the token.
ui (UI) – Asks for the token, and reports the outcome.
secrets (SecretStore) – Where to store it.
env (mapping of str to str) – Environment variables (to warn if
token_envoverrides the keyring).check (bool, optional) – Make sure the server accepts the token first. If the server redirects, the token is stored for the URL it redirects to (see
zabgrab.services.session.open_client()).update_url (callable, optional) – Offered to update a configured server’s URL after a redirect.
- Raises:
AuthenticationFailed – If checking and the server rejects the token.
InputRequired – If the token is needed and the session isn’t interactive.
- Return type:
None
- zabgrab.services.tokens.choose_stored(statuses, ui)[source]¶
Ask which server’s stored token to act on.
- Raises:
ZabgrabError – If no tokens are stored.
- Parameters:
statuses (list[TokenStatus])
ui (UI)
- Return type:
- zabgrab.services.tokens.delete_token(server, *, ui, secrets, yes)[source]¶
Delete the stored token for a server, confirming first unless
yes.- Raises:
ZabgrabError – If no token is stored for it.
Cancelled – If the user says no.
- Parameters:
server (Server)
ui (UI)
secrets (SecretStore)
yes (bool)
- Return type:
None