psychoinformatics-de / knowledge-base

Sources for the psyinf knowledge base
https://knowledge-base.psychoinformatics.de
Other
0 stars 3 forks source link

Change in keyring configuration handling #85

Closed loj closed 1 year ago

loj commented 1 year ago

Origin: INM-7 Data Matrix chat

TODO (not necessarily to be performed in this order)

OP reported problems with credential handling on Juseless. Failed to create the collection: Prompt dismissed..

This same problem was noticed by others prior to this report. Specifically @mslw discovered that it's a change in the way keyring configuration is handled (post upgrade of Juseless).

The solution is to set PYTHON_KEYRING_BACKEND=keyrings.alt.file.PlaintextKeyring. This can be set to the default in the keyring config file:

❱ cat ~/.config/python_keyring/keyringrc.cfg
[backend]
default-keyring=keyrings.alt.file.PlaintextKeyring

This is a good candidate for a KBI write-up.

mih commented 1 year ago

Here is how to trigger it:

>>> import keyring
>>> k=keyring.get_keyring()
>>> k.get_credential('some', 'name')
KeyringLocked                             Traceback (most recent call last)
Cell In [9], line 1
----> 1 k.get_credential('some', 'name')

File /usr/lib/python3/dist-packages/keyring/backends/chainer.py:69, in ChainerBackend.get_credential(self, service, username)
     67 def get_credential(self, service, username):
     68     for keyring in self.backends:
---> 69         credential = keyring.get_credential(service, username)
     70         if credential is not None:
     71             return credential

File /usr/lib/python3/dist-packages/keyring/backends/SecretService.py:112, in Keyring.get_credential(self, service, username)
    110 scheme = self.schemes[self.scheme]
    111 query = self._query(service, username)
--> 112 collection = self.get_preferred_collection()
    114 with closing(collection.connection):
    115     items = collection.search_items(query)

File /usr/lib/python3/dist-packages/keyring/backends/SecretService.py:67, in Keyring.get_preferred_collection(self)
     65     collection.unlock()
     66     if collection.is_locked():  # User dismissed the prompt
---> 67         raise KeyringLocked("Failed to unlock the collection!")
     68 return collection

KeyringLocked: Failed to unlock the collection!

This means that CredentialManager can catch that specific exception and render an appropriate hint.