Skip to content

Commit

Permalink
libsecret: skip if there is no secret service running
Browse files Browse the repository at this point in the history
In case libsecret and its Python bindings are available the
libsecret backend will get selected. This doesn't mean though
that the system service it connects to is available.

This leads to the backend being used and then failing, for example
in get_credential() with:
g-dbus-error-quark: The name org.freedesktop.secrets is unknown (2)

To avoid this ask libsecret to connect to the system service first
before considering to use it.

Fixes #600
  • Loading branch information
lazka committed Nov 4, 2022
1 parent 590d804 commit b000063
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions keyring/backends/libsecret.py
Expand Up @@ -7,7 +7,6 @@
from ..errors import (
PasswordDeleteError,
PasswordSetError,
ExceptionRaisedContext,
KeyringLocked,
)

Expand Down Expand Up @@ -50,10 +49,15 @@ def collection(self):

@properties.classproperty
def priority(cls):
with ExceptionRaisedContext() as exc:
Secret.__name__
if exc:
if not available:
raise RuntimeError("libsecret required")

# Make sure there is actually a secret service running
try:
Secret.Service.get_sync(Secret.ServiceFlags.OPEN_SESSION, None)
except GLib.Error as error:
raise RuntimeError("Can't open a session to the secret service") from error

return 4.8

def get_password(self, service, username):
Expand Down

0 comments on commit b000063

Please sign in to comment.