How to use the keyring.set_keyring 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 easybuilders / easybuild-framework / test / framework / suite.py View on Github external
import test.framework.variables as v
import test.framework.yeb as y

# set plain text key ring to be used,
# so a GitHub token stored in it can be obtained without having to provide a password
try:
    # with recent versions of keyring, PlaintextKeyring comes from keyrings.alt
    import keyring
    from keyrings.alt.file import PlaintextKeyring
    keyring.set_keyring(PlaintextKeyring())
except ImportError as err:
    try:
        # with old versions of keyring, PlaintextKeyring comes from keyring.backends
        import keyring
        from keyring.backends.file import PlaintextKeyring
        keyring.set_keyring(PlaintextKeyring())
    except ImportError as err:
        pass

# disable all logging to significantly speed up tests
fancylogger.disableDefaultHandlers()
fancylogger.setLogLevelError()


# make sure temporary files can be created/used
try:
    set_tmpdir(raise_error=True)
except EasyBuildError, err:
    sys.stderr.write("No execution rights on temporary files, specify another location via $TMPDIR: %s\n" % err)
    sys.exit(1)

# initialize logger for all the unit tests
github major / supernova / tests / test_credentials.py View on Github external
def test_reject_confirmation(self, monkeypatch):
        def mockreturn(path):
            return False
        monkeypatch.setattr(utils, "confirm_credential_display", mockreturn)
        keyring.set_keyring(TestKeyring())
        result = credentials.get_user_password('prod', 'prodpass')
        assert result is None
github major / supernova / tests / test_credentials.py View on Github external
def test_pull_env_credential_global(self):
        keyring.set_keyring(TestKeyring())
        result = credentials.pull_env_credential('prod',
                                                 'OS_PASSWORD',
                                                 'USE_KEYRING["prodpass"]'
                                                 )
        assert isinstance(result, tuple)
        assert result[0] == 'global:prodpass'
        if six.PY3:
            assert result[1] == b'password from TestKeyring'
        else:
            assert result[1] == 'password from TestKeyring'
github saltstack / salt / tests / unit / utils / test_cloud.py View on Github external
def supported(self):
            return 0

        def set_password(self, servicename, username, password):
            self.__storage.setdefault(servicename, {}).update({username: password})
            return 0

        def get_password(self, servicename, username):
            return self.__storage.setdefault(servicename, {}).get(username, None)

        def delete_password(self, servicename, username):
            self.__storage.setdefault(servicename, {}).pop(username, None)
            return 0

    # set the keyring for keyring lib
    keyring.set_keyring(TestKeyring())
    HAS_KEYRING = True
except ImportError:
    HAS_KEYRING = False

os.chdir(CODE_DIR)


class CloudUtilsTestCase(TestCase):

    def test_ssh_password_regex(self):
        '''Test matching ssh password patterns'''
        for pattern in ('Password for root@127.0.0.1:',
                        'root@127.0.0.1 Password:',
                        ' Password:'):
            self.assertNotEqual(
                cloud.SSH_PASSWORD_PROMP_RE.match(pattern), None
github major / supernova / tests / test_credentials.py View on Github external
def test_set_user_password(self):
        keyring.set_keyring(TestKeyring())
        environment = "prod"
        parameter = "prodpass"
        password = "supersecurepassword"
        result = credentials.set_user_password(environment, parameter,
                                               password)
        assert result
github major / supernova / tests / test_credentials.py View on Github external
def test_get_user_password(self):
        keyring.set_keyring(TestKeyring())
        result = credentials.get_user_password('prod', 'prodpass', force=True)
        assert result[0] == 'prod:prodpass'
        if six.PY3:
            assert result[1] == b'password from TestKeyring'
        else:
            assert result[1] == 'password from TestKeyring'
github jrnl-org / jrnl / features / steps / core.py View on Github external
priority = 1
    keys = defaultdict(dict)

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

    def get_password(self, servicename, username):
        return self.keys[servicename].get(username)

    def delete_password(self, servicename, username):
        self.keys[servicename][username] = None


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


def ushlex(command):
    if sys.version_info[0] == 3:
        return shlex.split(command)
    return map(lambda s: s.decode("UTF8"), shlex.split(command.encode("utf8")))


def read_journal(journal_name="default"):
    config = util.load_config(install.CONFIG_FILE_PATH)
    with open(config["journals"][journal_name]) as journal_file:
        journal = journal_file.read()
    return journal


def open_journal(journal_name="default"):
github HenriWahl / Nagstamon / Nagstamon / Nagstamon / keyring_3_7_complete / demo / keyring_demo.py View on Github external
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:
        print "failed to store password"
    print "password", keyring.get_password("demo-service", "tarek")