Skip to content

Commit

Permalink
Disable SecretService backend if org.freedesktop.secrets name is not …
Browse files Browse the repository at this point in the history
…available

Fixes jaraco#162, jaraco#434.
  • Loading branch information
mitya57 authored and jaraco committed Nov 6, 2020
1 parent 3836e15 commit c6af045
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions keyring/backends/SecretService.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Keyring(KeyringBackend):
@properties.ClassProperty
@classmethod
def priority(cls):
try:
from jeepney.bus_messages import message_bus
from jeepney.integrate.blocking import Proxy
except ImportError:
raise RuntimeError("jeepney required")
with ExceptionRaisedContext() as exc:
secretstorage.__name__
if exc:
Expand All @@ -39,6 +44,14 @@ def priority(cls):
raise RuntimeError("SecretStorage 3.0 or newer required")
try:
with closing(secretstorage.dbus_init()) as connection:
proxy = Proxy(message_bus, connection)
has_owner, = proxy.NameHasOwner("org.freedesktop.secrets")
if not has_owner:
activatable_names, = proxy.ListActivatableNames()
if "org.freedesktop.secrets" not in activatable_names:
raise RuntimeError(
"The Secret Service daemon is neither running nor "
"activatable through D-Bus")
list(secretstorage.get_all_collections(connection))
except exceptions.SecretStorageException as e:
raise RuntimeError("Unable to initialize SecretService: %s" % e)
Expand Down

0 comments on commit c6af045

Please sign in to comment.