From b000063df1b94031b4d2457640b813237622ab79 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Mon, 31 Oct 2022 20:08:40 +0100 Subject: [PATCH] libsecret: skip if there is no secret service running 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 --- keyring/backends/libsecret.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/keyring/backends/libsecret.py b/keyring/backends/libsecret.py index c97e0d33..cf16dbec 100644 --- a/keyring/backends/libsecret.py +++ b/keyring/backends/libsecret.py @@ -7,7 +7,6 @@ from ..errors import ( PasswordDeleteError, PasswordSetError, - ExceptionRaisedContext, KeyringLocked, ) @@ -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):