snip.token.storage.keyring_store¶
Functionalities to save and retrieve tokens from a keyring.
A token always consists of a name, a book_id and a token string. The name is a user defined string to identify the token and should be unique.
We abuse the standard keyring functionalities a bit to store key value pairs. We use a global prefix in combination with the name to store the key value pairs for each token.
kr.set_password(SNIP_KR_IDENTIFIER, f"{name.as_hex}:book_id", book_id)
kr.set_password(SNIP_KR_IDENTIFIER, f"{name.as_hex}:token", token_str)
As we also want to retrieve all tokens from the keyring we need to store an index of all tokens in the keyring.
kr.set_password(SNIP_KR_IDENTIFIER, f"index", f"{name.as_hex},{name2.as_hex},...")
Functions
|
Get all available tokens from a keyring backend. |
|
Get a token from the keyring storage. |
|
Remove a token from the keyring storage. |
|
Save a token in the keyring storage. |
|
Check if a token exists in the keyring storage. |
Module Functions
- snip.token.storage.keyring_store.get_all_tokens(kr: KeyringBackend) list[Token]¶
Get all available tokens from a keyring backend.
Abstracts the parsing of the key value pairs from the keyring backend and returns valid tokens.
- snip.token.storage.keyring_store.get_token(name: str, kr: KeyringBackend) Token | None¶
Get a token from the keyring storage.
- snip.token.storage.keyring_store.remove_token(name: str, kr: KeyringBackend)¶
Remove a token from the keyring storage.
- Parameters:
name (str) – The name of the token to remove.
kr (KeyringBackend) – The keyring backend to remove the token from.
- snip.token.storage.keyring_store.save_token(token: Token, kr: KeyringBackend, overwrite: bool = False)¶
Save a token in the keyring storage.
- Parameters:
token (Token) – The token object to save.
kr (KeyringBackend) – The keyring backend to save the token to.