Beispiel #1
0
def get_all_collections(bus):
	"""Returns a generator of all available collections."""
	service_obj = bus_get_object(bus, SECRETS, SS_PATH)
	service_props_iface = dbus.Interface(service_obj,
		dbus.PROPERTIES_IFACE)
	for collection_path in service_props_iface.Get(SERVICE_IFACE,
	'Collections', signature='ss'):
		yield Collection(bus, collection_path)
Beispiel #2
0
 def __init__(self, bus, item_path, session=None):
     self.item_path = item_path
     item_obj = bus_get_object(bus, item_path)
     self.session = session
     self.bus = bus
     self.item_iface = InterfaceWrapper(item_obj, ITEM_IFACE)
     self.item_props_iface = InterfaceWrapper(item_obj, dbus.PROPERTIES_IFACE)
     self.item_props_iface.Get(ITEM_IFACE, "Label", signature="ss")
def search_items(bus, attributes):
    """Returns a generator of items in all collections with the given
    attributes. `attributes` should be a dictionary."""
    service_obj = bus_get_object(bus, SS_PATH)
    service_iface = dbus.Interface(service_obj, SERVICE_IFACE)
    locked, unlocked = service_iface.SearchItems(attributes, signature='a{ss}')
    for item_path in locked + unlocked:
        yield Item(bus, item_path)
Beispiel #4
0
 def __init__(self, bus, item_path, session=None):
     self.item_path = item_path
     item_obj = bus_get_object(bus, item_path)
     self.session = session
     self.bus = bus
     self.item_iface = InterfaceWrapper(item_obj, ITEM_IFACE)
     self.item_props_iface = InterfaceWrapper(item_obj,
                                              dbus.PROPERTIES_IFACE)
     self.item_props_iface.Get(ITEM_IFACE, 'Label', signature='ss')
def search_items(bus, attributes):
	"""Returns a generator of items in all collections with the given
	attributes. `attributes` should be a dictionary."""
	service_obj = bus_get_object(bus, SECRETS, SS_PATH)
	service_iface = dbus.Interface(service_obj, SERVICE_IFACE)
	locked, unlocked = service_iface.SearchItems(attributes,
		signature='a{ss}')
	for item_path in locked + unlocked:
		yield Item(bus, item_path)
Beispiel #6
0
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)
Beispiel #7
0
	def __init__(self, bus, collection_path=DEFAULT_COLLECTION, session=None):
		collection_obj = bus_get_object(bus, SECRETS, collection_path)
		self.bus = bus
		self.session = session
		self.collection_path = collection_path
		self.collection_iface = InterfaceWrapper(collection_obj,
			COLLECTION_IFACE)
		self.collection_props_iface = InterfaceWrapper(collection_obj,
			dbus.PROPERTIES_IFACE)
		self.collection_props_iface.Get(COLLECTION_IFACE, 'Label',
			signature='ss')
Beispiel #8
0
 def __init__(self, bus, item_path, session=None):
     if isinstance(item_path, int):
         # An item id was specified instead of the path
         item_path = '%s/%d' % (DEFAULT_COLLECTION, item_path)
     self.item_path = item_path
     item_obj = bus_get_object(bus, SECRETS, item_path)
     self.session = session
     self.bus = bus
     self.item_iface = InterfaceWrapper(item_obj, ITEM_IFACE)
     self.item_props_iface = InterfaceWrapper(item_obj,
                                              dbus.PROPERTIES_IFACE)
     self.item_props_iface.Get(ITEM_IFACE, 'Label', signature='ss')
Beispiel #9
0
	def __init__(self, bus, item_path, session=None):
		if isinstance(item_path, int):
			# An item id was specified instead of the path
			item_path = '%s/%d' % (DEFAULT_COLLECTION, item_path)
		self.item_path = item_path
		item_obj = bus_get_object(bus, SECRETS, item_path)
		self.session = session
		self.bus = bus
		self.item_iface = InterfaceWrapper(item_obj, ITEM_IFACE)
		self.item_props_iface = InterfaceWrapper(item_obj,
			dbus.PROPERTIES_IFACE)
		self.item_props_iface.Get(ITEM_IFACE, 'Label', signature='ss')
Beispiel #10
0
	def unlock(self, callback=None):
		"""Requests unlocking the collection. If `callback` is specified,
		calls it when unlocking is complete (see
		:func:`~secretstorage.util.exec_prompt` description for
		details) and returns a boolean representing whether the operation was
		dismissed. Otherwise, uses loop from GLib API."""
		service_obj = bus_get_object(self.bus, SECRETS, SS_PATH)
		service_iface = InterfaceWrapper(service_obj, SERVICE_IFACE)
		prompt = service_iface.Unlock([self.collection_path], signature='ao')[1]
		if len(prompt) > 1:
			if callback:
				exec_prompt(self.bus, prompt, callback)
			else:
				return exec_prompt_glib(self.bus, prompt)[0]
		elif callback:
			# We still need to call it.
			callback(False, [])
Beispiel #11
0
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)
Beispiel #12
0
	def lock(self):
		"""Locks the collection."""
		service_obj = bus_get_object(self.bus, SECRETS, SS_PATH)
		service_iface = InterfaceWrapper(service_obj, SERVICE_IFACE)
		service_iface.Lock([self.collection_path], signature='ao')