Cura/cura/OAuth2/SecretStorage.py
Jelle Spijker 47df060bee
Added fundaments of SecretStorage vault
This class will handle the storing and processing
of secrets. Such as tokens. It will try to use the system
keyring by default. Falling back to less secure methods,
if the user doesn't allow access to the keyring or if
the back-end is unsupported.

CURA-7180 keyring storage
2021-03-11 14:21:51 +01:00

20 lines
536 B
Python

import keyring
class SecretStorage:
def __init__(self):
self._stored_secrets = []
def __delitem__(self, key):
if key in self._stored_secrets:
del self._stored_secrets[key]
keyring.delete_password("cura", key)
def __setitem__(self, key, value):
self._stored_secrets.append(key)
keyring.set_password("cura", key, value)
def __getitem__(self, key):
if key in self._stored_secrets:
return keyring.get_password("cura", key)
return None