mirror of
https://github.com/borgbase/vorta
synced 2025-02-23 14:50:42 +00:00
Change keyring label to improve UX on Gnome. By @real-yfprojects (#1181)
This commit is contained in:
parent
c4cd054033
commit
8126f4e696
1 changed files with 14 additions and 2 deletions
|
@ -1,11 +1,14 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import secretstorage
|
import secretstorage
|
||||||
|
|
||||||
from vorta.keyring.abc import VortaKeyring
|
from vorta.keyring.abc import VortaKeyring
|
||||||
from vorta.log import logger
|
from vorta.log import logger
|
||||||
|
|
||||||
|
LABEL_TEMPLATE = "Vorta Backup Repo {repo_url}"
|
||||||
|
|
||||||
|
|
||||||
class VortaSecretStorageKeyring(VortaKeyring):
|
class VortaSecretStorageKeyring(VortaKeyring):
|
||||||
"""A wrapper for the secretstorage package to support the custom keyring backend"""
|
"""A wrapper for the secretstorage package to support the custom keyring backend"""
|
||||||
|
@ -19,6 +22,9 @@ def __init__(self):
|
||||||
secretstorage.get_default_collection(self.connection)
|
secretstorage.get_default_collection(self.connection)
|
||||||
|
|
||||||
def set_password(self, service, repo_url, password):
|
def set_password(self, service, repo_url, password):
|
||||||
|
"""
|
||||||
|
Writes a password to the underlying store.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
asyncio.set_event_loop(asyncio.new_event_loop())
|
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||||
collection = secretstorage.get_default_collection(self.connection)
|
collection = secretstorage.get_default_collection(self.connection)
|
||||||
|
@ -27,11 +33,17 @@ def set_password(self, service, repo_url, password):
|
||||||
'service': service,
|
'service': service,
|
||||||
'repo_url': repo_url,
|
'repo_url': repo_url,
|
||||||
'xdg:schema': 'org.freedesktop.Secret.Generic'}
|
'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:
|
except secretstorage.exceptions.ItemNotFoundException:
|
||||||
logger.error("SecretStorage writing failed", exc_info=sys.exc_info())
|
logger.error("SecretStorage writing failed", exc_info=sys.exc_info())
|
||||||
|
|
||||||
def get_password(self, service, repo_url):
|
def get_password(self, service, repo_url):
|
||||||
|
"""
|
||||||
|
Retrieve a password from the underlying store. Return None if not found.
|
||||||
|
"""
|
||||||
if self.is_unlocked:
|
if self.is_unlocked:
|
||||||
asyncio.set_event_loop(asyncio.new_event_loop())
|
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||||
collection = secretstorage.get_default_collection(self.connection)
|
collection = secretstorage.get_default_collection(self.connection)
|
||||||
|
|
Loading…
Reference in a new issue