How to use the secretstorage.collection.Collection function in SecretStorage

To help you get started, we’ve selected a few SecretStorage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mitya57 / secretstorage / secretstorage / collection.py View on Github external
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.')
github mitya57 / secretstorage / secretstorage / collection.py View on Github external
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)
github mitya57 / secretstorage / secretstorage / collection.py View on Github external
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)
github mitya57 / secretstorage / secretstorage / collection.py View on Github external
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)
github mitya57 / secretstorage / secretstorage / collection.py View on Github external
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.')
github mitya57 / secretstorage / secretstorage / collection.py View on Github external
def get_default_collection(connection: DBusConnection,
                           session: Optional[Session] = None) -> Collection:
	"""Returns the default collection. If it doesn't exist,
	creates it."""
	try:
		return Collection(connection)
	except ItemNotFoundException:
		return create_collection(connection, 'Default',
		'default', session)