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
This commit is contained in:
Jelle Spijker 2021-03-11 14:21:51 +01:00
parent 720b356221
commit 47df060bee
No known key found for this signature in database
GPG key ID: 6662DC033BE6B99A
2 changed files with 27 additions and 4 deletions

View file

@ -0,0 +1,20 @@
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