示例#1
0
def search_items(connection: DBusConnection,
                 attributes: Dict[str, str]) -> Iterator[Item]:
    """Returns a generator of items in all collections with the given
	attributes. `attributes` should be a dictionary."""
    service = DBusAddressWrapper(SS_PATH, SERVICE_IFACE, connection)
    locked, unlocked = service.call('SearchItems', 'a{ss}', attributes)
    for item_path in locked + unlocked:
        yield Item(connection, item_path)
示例#2
0
 def __init__(self,
              connection: DBusConnection,
              item_path: str,
              session: Optional[Session] = None) -> None:
     self.item_path = item_path
     self._item = DBusAddressWrapper(item_path, ITEM_IFACE, connection)
     self._item.get_property('Label')
     self.session = session
     self.connection = connection
示例#3
0
 def __init__(self,
              connection: DBusConnection,
              collection_path: str = DEFAULT_COLLECTION,
              session: Optional[Session] = None) -> None:
     self.connection = connection
     self.session = session
     self.collection_path = collection_path
     self._collection = DBusAddressWrapper(collection_path,
                                           COLLECTION_IFACE, connection)
     self._collection.get_property('Label')
示例#4
0
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)
示例#5
0
def create_collection(connection: DBusConnection,
                      label: str,
                      alias: str = '',
                      session: Optional[Session] = None) -> Collection:
    """Creates a new :class:`Collection` with the given `label` and `alias`
	and returns it. This action requires prompting.

	:raises: :exc:`~secretstorage.exceptions.PromptDismissedException`
	         if the prompt is dismissed.
	"""
    if not session:
        session = open_session(connection)
    properties = {SS_PREFIX + 'Collection.Label': ('s', label)}
    service = DBusAddressWrapper(SS_PATH, SERVICE_IFACE, connection)
    collection_path, prompt = service.call('CreateCollection', 'a{sv}s',
                                           properties, alias)
    if len(collection_path) > 1:
        return Collection(connection, collection_path, session=session)
    dismissed, result = exec_prompt(connection, prompt)
    if dismissed:
        raise PromptDismissedException('Prompt dismissed.')
    signature, collection_path = result
    assert signature == 'o'
    return Collection(connection, collection_path, session=session)
示例#6
0
 def lock(self) -> None:
     """Locks the collection."""
     service = DBusAddressWrapper(SS_PATH, SERVICE_IFACE, self.connection)
     service.call('Lock', 'ao', [self.collection_path])
示例#7
0
def get_all_collections(connection: DBusConnection) -> Iterator[Collection]:
    """Returns a generator of all available collections."""
    service = DBusAddressWrapper(SS_PATH, SERVICE_IFACE, connection)
    for collection_path in service.get_property('Collections'):
        yield Collection(connection, collection_path)