Change keyring label to improve UX on Gnome. By @real-yfprojects (#1181)

This commit is contained in:
yfprojects 2022-03-06 10:14:28 +01:00 committed by GitHub
parent c4cd054033
commit 8126f4e696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -1,11 +1,14 @@
import asyncio
import sys
import os
import sys
import secretstorage
from vorta.keyring.abc import VortaKeyring
from vorta.log import logger
LABEL_TEMPLATE = "Vorta Backup Repo {repo_url}"
class VortaSecretStorageKeyring(VortaKeyring):
"""A wrapper for the secretstorage package to support the custom keyring backend"""
@ -19,6 +22,9 @@ class VortaSecretStorageKeyring(VortaKeyring):
secretstorage.get_default_collection(self.connection)
def set_password(self, service, repo_url, password):
"""
Writes a password to the underlying store.
"""
try:
asyncio.set_event_loop(asyncio.new_event_loop())
collection = secretstorage.get_default_collection(self.connection)
@ -27,11 +33,17 @@ class VortaSecretStorageKeyring(VortaKeyring):
'service': service,
'repo_url': repo_url,
'xdg:schema': 'org.freedesktop.Secret.Generic'}
collection.create_item(repo_url, attributes, password, replace=True)
collection.create_item(LABEL_TEMPLATE.format(repo_url=repo_url),
attributes,
password,
replace=True)
except secretstorage.exceptions.ItemNotFoundException:
logger.error("SecretStorage writing failed", exc_info=sys.exc_info())
def get_password(self, service, repo_url):
"""
Retrieve a password from the underlying store. Return None if not found.
"""
if self.is_unlocked:
asyncio.set_event_loop(asyncio.new_event_loop())
collection = secretstorage.get_default_collection(self.connection)