How to use the keyring.backend function in keyring

To help you get started, we’ve selected a few keyring 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 blue-yonder / bonfire / tests / test_config.py View on Github external
@author = mharder
'''

from __future__ import division, print_function

from bonfire.utils import api_from_config

from bonfire.config import get_config, get_templated_option, get_password_from_keyring, store_password_in_keyring

import arrow
import keyring
import keyring.backend


class TestKeyring(keyring.backend.KeyringBackend):
    """A test keyring which always outputs same password
    """
    priority = 1

    def set_password(self, servicename, username, password):
        self.password = password

    def get_password(self, servicename, username):
        return self.password

    def delete_password(self, servicename, username, password):
        self.password = ""


keyring.set_keyring(TestKeyring())
github HenriWahl / Nagstamon / Nagstamon / Nagstamon / keyring_3_7_complete / demo / keyring_demo.py View on Github external
def set_keyring_in_runtime():
    """This function shows how to create a keyring manully and use it
    in runtime
    """

    # define a new keyring class which extends the KeyringBackend
    import keyring.backend
    class TestKeyring(keyring.backend.KeyringBackend):
        """A test keyring which always outputs same password
        """
        def supported(self): return 0
        def set_password(self, servicename, username, password): return 0
        def get_password(self, servicename, username):
            return "password from TestKeyring"

    # set the keyring for keyring lib
    import keyring
    keyring.set_keyring(TestKeyring())

    # invoke the keyring lib
    try:
        keyring.set_password("demo-service", "tarek", "passexample")
        print "password stored sucessfully"
    except keyring.backend.PasswordSetError:
github leapcode / bitmask_client / src / leap / crypto / leapkeyring.py View on Github external
# Disclaimer
#############
# This currently is not a keyring, it's more like a joke.
# No, seriously.
# We're affected by this **bug**

# https://bitbucket.org/kang/python-keyring-lib/
# issue/65/dbusexception-method-opensession-with

# so using the gnome keyring does not seem feasible right now.
# I thought this was the next best option to store secrets in plain sight.

# in the future we should move to use the gnome/kde/macosx/win keyrings.


class LeapCryptedFileKeyring(keyring.backend.CryptedFileKeyring):

    filename = ".secrets"

    @property
    def file_path(self):
        return get_config_file(self.filename)

    def __init__(self, seed=None):
        self.seed = seed

    def _get_new_password(self):
        # XXX every time this method is called,
        # $deity kills a kitten.
        return "secret%s" % self.seed

    def _init_file(self):
github openstack / python-magnumclient / magnumclient / shell.py View on Github external
from magnumclient.common import cliutils
from magnumclient import exceptions as exc
from magnumclient.i18n import _
from magnumclient.v1 import client as client_v1
from magnumclient.v1 import shell as shell_v1
from magnumclient import version

profiler = importutils.try_import("osprofiler.profiler")

HAS_KEYRING = False
all_errors = ValueError
try:
    import keyring
    HAS_KEYRING = True
    try:
        if isinstance(keyring.get_keyring(), keyring.backend.GnomeKeyring):
            import gnomekeyring
            all_errors = (ValueError,
                          gnomekeyring.IOError,
                          gnomekeyring.NoKeyringDaemonError)
    except Exception:
        pass
except ImportError:
    pass


LATEST_API_VERSION = ('1', 'latest')
DEFAULT_INTERFACE = 'public'
DEFAULT_SERVICE_TYPE = 'container-infra'

logger = logging.getLogger(__name__)
github savoirfairelinux / sflvault / client-qt / sflvault / clientqt / lib / auth.py View on Github external
def getSecret():
    wallet_setting = str(settings.value("SFLvault/wallet").toString())
    if hasattr(keyring.backend, wallet_setting):
        keyring_backend = getattr(keyring.backend, wallet_setting)()
        secret = keyring_backend.get_password("sflvault", str(settings.fileName()))
        return secret if secret else False
    else:
        return False