def function_out(*args, **kwargs): try: return function_in(*args, **kwargs) except dbus.exceptions.DBusException as e: if e.get_dbus_name() == DBUS_UNKNOWN_METHOD: raise ItemNotFoundException('Item does not exist!') if e.get_dbus_name() == DBUS_NO_SUCH_OBJECT: raise ItemNotFoundException(e.get_dbus_message()) if e.get_dbus_name() in (DBUS_NO_REPLY, DBUS_NOT_SUPPORTED): raise SecretServiceNotAvailableException( e.get_dbus_message()) raise
def get_collection_by_alias(bus, alias): """Returns the collection with the given `alias`. If there is no such collection, raises :exc:`~secretstorage.exceptions.ItemNotFoundException`.""" service_obj = bus_get_object(bus, SECRETS, SS_PATH) service_iface = dbus.Interface(service_obj, SERVICE_IFACE) collection_path = service_iface.ReadAlias(alias, signature='s') if len(collection_path) <= 1: raise ItemNotFoundException('No collection with such alias.') return Collection(bus, collection_path)
def get_collection_by_alias(connection: DBusConnection, alias: str) -> Collection: """Returns the collection with the given `alias`. If there is no such collection, raises :exc:`~secretstorage.exceptions.ItemNotFoundException`.""" service = DBusAddressWrapper(SS_PATH, SERVICE_IFACE, connection) collection_path, = service.call('ReadAlias', 's', alias) if len(collection_path) <= 1: raise ItemNotFoundException('No collection with such alias.') return Collection(connection, collection_path)
def send_and_get_reply(self, msg: Message) -> Any: try: return self._connection.send_and_get_reply(msg, unwrap=True) except DBusErrorResponse as resp: if resp.name in (DBUS_UNKNOWN_METHOD, DBUS_NO_SUCH_OBJECT): raise ItemNotFoundException('Item does not exist!') from resp elif resp.name in (DBUS_SERVICE_UNKNOWN, DBUS_EXEC_FAILED, DBUS_NO_REPLY): data = resp.data if isinstance(data, tuple): data = data[0] raise SecretServiceNotAvailableException(data) from resp raise
def create_collection(bus, label, alias='', session=None): """Creates a new :class:`Collection` with the given `label` and `alias` and returns it. This action requires prompting. If prompt is dismissed, raises :exc:`~secretstorage.exceptions.ItemNotFoundException`. This is synchronous function, uses loop from GLib API.""" if not session: session = open_session(bus) properties = {SS_PREFIX+'Collection.Label': label} service_obj = bus_get_object(bus, SECRETS, SS_PATH) service_iface = dbus.Interface(service_obj, SERVICE_IFACE) collection_path, prompt = service_iface.CreateCollection(properties, alias, signature='a{sv}s') if len(collection_path) > 1: return Collection(bus, collection_path, session=session) dismissed, unlocked = exec_prompt_glib(bus, prompt) if dismissed: raise ItemNotFoundException('Prompt dismissed.') return Collection(bus, unlocked, session=session)
def get_any_collection(bus): """Returns any collection, in the following order of preference: - The default collection; - The "session" collection (usually temporary); - The first collection in the collections list.""" try: return Collection(bus) except ItemNotFoundException: pass try: return Collection(bus, SESSION_COLLECTION) except ItemNotFoundException: pass collections = list(get_all_collections(bus)) if collections: return collections[0] else: raise ItemNotFoundException('No collections found.')
def get_any_collection(connection: DBusConnection) -> Collection: """Returns any collection, in the following order of preference: - The default collection; - The "session" collection (usually temporary); - The first collection in the collections list.""" try: return Collection(connection) except ItemNotFoundException: pass try: # GNOME Keyring provides session collection where items # are stored in process memory. return Collection(connection, SESSION_COLLECTION) except ItemNotFoundException: pass collections = list(get_all_collections(connection)) if collections: return collections[0] else: raise ItemNotFoundException('No collections found.')