Change keyring priority (#779)

This commit is contained in:
samuel-w 2021-02-01 19:10:39 -06:00 committed by GitHub
parent 1c27d377cf
commit c99ac04b36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 15 deletions

View File

@ -20,23 +20,27 @@ class VortaKeyring:
if sys.platform == 'darwin': # Use Keychain on macOS
from .darwin import VortaDarwinKeyring
cls._keyring = VortaDarwinKeyring()
else: # Try to use DBus and Gnome-Keyring (available on Linux and *BSD)
import secretstorage
from .secretstorage import VortaSecretStorageKeyring
# secretstorage has two different libraries based on version
if parse_version(secretstorage.__version__) >= parse_version("3.0.0"):
from jeepney.wrappers import DBusErrorResponse as DBusException
else:
from dbus.exceptions import DBusException
else:
# Try to use KWallet (KDE)
from .kwallet import VortaKWallet5Keyring, KWalletNotAvailableException
try:
cls._keyring = VortaSecretStorageKeyring()
except (secretstorage.exceptions.SecretStorageException, DBusException): # Try to use KWallet (KDE)
from .kwallet import VortaKWallet5Keyring, KWalletNotAvailableException
cls._keyring = VortaKWallet5Keyring()
except KWalletNotAvailableException:
# Try to use DBus and Gnome-Keyring (available on Linux and *BSD)
# Put this last as gnome keyring is included by default on many distros
import secretstorage
from .secretstorage import VortaSecretStorageKeyring
# secretstorage has two different libraries based on version
if parse_version(secretstorage.__version__) >= parse_version("3.0.0"):
from jeepney.wrappers import DBusErrorResponse as DBusException
else:
from dbus.exceptions import DBusException
try:
cls._keyring = VortaKWallet5Keyring()
except KWalletNotAvailableException: # Save passwords in DB, if all else fails.
cls._keyring = VortaSecretStorageKeyring()
except (secretstorage.exceptions.SecretStorageException, DBusException):
# Save passwords in DB, if all else fails.
from .db import VortaDBKeyring
cls._keyring = VortaDBKeyring()
return cls._keyring