mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-16 02:26:13 +01:00
Cache password from SecretService to avoid spamming user with an accept dialog
This commit is contained in:
parent
f7f9506f96
commit
948bbc659b
@ -189,6 +189,10 @@ class TransientDescriptor(AbstractCredentialsManagerDescriptor):
|
|||||||
|
|
||||||
|
|
||||||
class KeyringCredentialsManager(AbstractCredentialsManager):
|
class KeyringCredentialsManager(AbstractCredentialsManager):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self._password = None
|
||||||
|
|
||||||
def _process_options(self, options):
|
def _process_options(self, options):
|
||||||
if options is None:
|
if options is None:
|
||||||
raise RuntimeError('options may not be None')
|
raise RuntimeError('options may not be None')
|
||||||
@ -209,14 +213,19 @@ class KeyringCredentialsManager(AbstractCredentialsManager):
|
|||||||
return super().create(cp, options)
|
return super().create(cp, options)
|
||||||
|
|
||||||
def _get_password(self, url, user, apiurl=None):
|
def _get_password(self, url, user, apiurl=None):
|
||||||
self._load_backend()
|
if self._password is None:
|
||||||
return keyring.get_password(urlsplit(url)[1], user)
|
self._load_backend()
|
||||||
|
self._password = keyring.get_password(urlsplit(url)[1], user)
|
||||||
|
# TODO: this works fine on the command-line but a long-running process using osc library would start failing after changing the password in the keyring
|
||||||
|
# TODO: implement retrieving the password again after basic auth fails; sufficiently inform user about what's being done
|
||||||
|
return self._password
|
||||||
|
|
||||||
def set_password(self, url, user, password):
|
def set_password(self, url, user, password):
|
||||||
self._load_backend()
|
self._load_backend()
|
||||||
keyring.set_password(urlsplit(url)[1], user, password)
|
keyring.set_password(urlsplit(url)[1], user, password)
|
||||||
config_value = f"{self._qualified_name()}:{self._backend_cls_name}"
|
config_value = f"{self._qualified_name()}:{self._backend_cls_name}"
|
||||||
self._cp.set(url, self.config_entry, config_value)
|
self._cp.set(url, self.config_entry, config_value)
|
||||||
|
self._password = password
|
||||||
|
|
||||||
def delete_password(self, url, user):
|
def delete_password(self, url, user):
|
||||||
self._load_backend()
|
self._load_backend()
|
||||||
|
Loading…
Reference in New Issue
Block a user