Python keyring.get_password() Examples

The following are 30 code examples of keyring.get_password(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module keyring , or try the search function .
Example #1
Source File: keyring_storage.py    From luci-py with Apache License 2.0 7 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #2
Source File: runtime.py    From CumulusCI with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_keychain_key(self):
        key_from_env = os.environ.get("CUMULUSCI_KEY")
        try:
            key_from_keyring = keyring.get_password("cumulusci", "CUMULUSCI_KEY")
            has_functioning_keychain = True
        except Exception as e:
            keychain_exception = e
            key_from_keyring = None
            has_functioning_keychain = False
        # If no key in environment or file, generate one
        key = key_from_env or key_from_keyring
        if key is None:
            if has_functioning_keychain:
                key = random_alphanumeric_underscore(length=16)
            else:
                raise KeychainKeyNotFound(
                    "Unable to store CumulusCI encryption key. "
                    "You can configure it manually by setting the CUMULUSCI_KEY "
                    "environment variable to a random 16-character string. "
                    f"ERROR: {keychain_exception}"
                )
        if has_functioning_keychain and not key_from_keyring:
            keyring.set_password("cumulusci", "CUMULUSCI_KEY", key)
        return key 
Example #3
Source File: keyring_storage.py    From earthengine with MIT License 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #4
Source File: password_manager.py    From poetry with MIT License 6 votes vote down vote up
def get_http_auth(self, name):
        auth = self._config.get("http-basic.{}".format(name))
        if not auth:
            username = self._config.get("http-basic.{}.username".format(name))
            password = self._config.get("http-basic.{}.password".format(name))
            if not username and not password:
                return None
        else:
            username, password = auth["username"], auth.get("password")
            if password is None:
                password = self.keyring.get_password(name, username)

        return {
            "username": username,
            "password": password,
        } 
Example #5
Source File: keyring_storage.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #6
Source File: keyring_storage.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #7
Source File: keyring_storage.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #8
Source File: keyring_storage.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #9
Source File: keyring_storage.py    From sndlatr with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #10
Source File: keyring_storage.py    From splunk-ref-pas-code with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #11
Source File: keyring_storage.py    From data with GNU General Public License v3.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #12
Source File: keyring_storage.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = client.Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #13
Source File: keyring_storage.py    From billing-export-python with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #14
Source File: keyring_storage.py    From twitter-for-bigquery with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #15
Source File: auth.py    From snowflake-connector-python with Apache License 2.0 6 votes vote down vote up
def read_temporary_credential(self, host, account, user, session_parameters):
        if session_parameters.get(PARAMETER_CLIENT_STORE_TEMPORARY_CREDENTIAL, False):
            id_token = None
            if IS_MACOS or IS_WINDOWS:
                if not keyring:
                    # we will leave the exception for write_temporary_credential function to raise
                    return
                new_target = convert_target(host, user)
                try:
                    id_token = keyring.get_password(new_target, user.upper())
                except keyring.errors.KeyringError as ke:
                    logger.debug("Could not retrieve id_token from secure storage : {}".format(str(ke)))
            elif IS_LINUX:
                read_temporary_credential_file()
                id_token = TEMPORARY_CREDENTIAL.get(
                    account.upper(), {}).get(user.upper())
            else:
                logger.debug("connection parameter enable_sso_temporary_credential not set or OS not support")
            self._rest.id_token = id_token
        return 
Example #16
Source File: co3argparse.py    From resilient-python-api with MIT License 6 votes vote down vote up
def _parse_parameters(names, options):
    """Parse parameters, with a tuple of names for keyring context"""
    for key in options.keys():
        val = options[key]
        if isinstance(val, dict):
            val = _parse_parameters(names + (key,), val)
        if isinstance(val, string_types) and len(val) > 1 and val[0] == "^":
            # Decode a secret from the keystore
            val = val[1:]
            service = ".".join(names) or "_"
            if service == "resilient":
                # Special case, becuase of the way we parse commandlines, treat this as root
                service = "_"
            logger.debug("keyring get('%s', '%s')", service, val)
            val = keyring.get_password(service, val)
        if isinstance(val, string_types) and len(val) > 1 and val[0] == "$":
            # Read a value from the environment
            val = val[1:]
            logger.debug("env('%s')", val)
            val = os.environ.get(val)
        options[key] = val
    return options 
Example #17
Source File: keyring_storage.py    From alfred-gmail with MIT License 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = client.Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #18
Source File: keyring_storage.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #19
Source File: keyring_storage.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #20
Source File: credential_store.py    From azure-devops-cli-extension with MIT License 6 votes vote down vote up
def get_password(self, key):
        try:
            import keyring
        except ImportError:
            return None
        token = None
        try:
            token = keyring.get_password(key, self._USERNAME)
        except Exception as ex:  # pylint: disable=broad-except
            # fetch credentials from file if keyring is missing or malfunctioning
            if sys.platform.startswith(self._LINUX_PLATFORM):
                token = None
            else:
                raise CLIError(ex)
        # look for credential in file too for linux if token is None
        if token is None and sys.platform.startswith(self._LINUX_PLATFORM):
            token = self.get_PAT_from_file(key)
        return token 
Example #21
Source File: keyring_storage.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #22
Source File: keyring_storage.py    From googleapps-message-recall with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
    """Retrieve Credential from file.

    Returns:
      oauth2client.client.Credentials
    """
    credentials = None
    content = keyring.get_password(self._service_name, self._user_name)

    if content is not None:
      try:
        credentials = Credentials.new_from_json(content)
        credentials.set_store(self)
      except ValueError:
        pass

    return credentials 
Example #23
Source File: keyring_storage.py    From aqua-monitor with GNU Lesser General Public License v3.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #24
Source File: keyring_storage.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def locked_get(self):
        """Retrieve Credential from file.

        Returns:
            oauth2client.client.Credentials
        """
        credentials = None
        content = keyring.get_password(self._service_name, self._user_name)

        if content is not None:
            try:
                credentials = Credentials.new_from_json(content)
                credentials.set_store(self)
            except ValueError:
                pass

        return credentials 
Example #25
Source File: manager.py    From runsqlrun with MIT License 6 votes vote down vote up
def update_connections(self):
        if not os.path.exists(CONNECTIONS_FILE):
            return
        with open(CONNECTIONS_FILE) as f:
            data = json.load(f)
        for key in data:
            if key in self._connections:
                self._connections[key].update_config(data[key])
            else:
                config = data[key].copy()
                password = keyring.get_password('runsqlrun', key)
                if password is not None:
                    config['password'] = password
                conn = Connection(key, config)
                self._connections[key] = conn
                conn.start()
        # remove deleted connections
        for key in list(self._connections):
            if key not in data:
                conn = self._connections.pop(key)
                conn.keep_running = False
                conn.join()
                self.emit('connection-deleted', conn.key) 
Example #26
Source File: test_set_key.py    From pushbullet-cli with MIT License 5 votes vote down vote up
def test_set_key(set_key, pb_api, mocker):
    import keyring
    import getpass
    import six
    prev_token = six.text_type(keyring.get_password("pushbullet", "cli"))
    try:
        with mocker.patch.object(getpass, 'getpass', return_value='abc'):
            set_key()
            assert keyring.get_password("pushbullet", "cli") == 'abc'
    finally:
        keyring.set_password("pushbullet", "cli", prev_token) 
Example #27
Source File: keyring_utils.py    From resilient-community-apps with MIT License 5 votes vote down vote up
def _list_parameters(names, options):
    """Parse parameters, with a tuple of names for keyring context"""
    for key in options.keys():
        val = options[key]
        if isinstance(val, dict):
            val = _list_parameters(names + (key,), val)
        if isinstance(val, str) and len(val) > 1 and val[0] == "^":
            # This value is from the keyring
            tag = val
            val = val[1:]
            service = ".".join(names) or "_"
            LOG.debug("keyring get('%s', '%s')", service, val)
            value = keyring.get_password(service, val)

            if value is None:
                print("[{0}] {1}: <not set>".format(",".join(names), key))
            else:
                print("[{0}] {1}: {2}".format(",".join(names), key, tag))

            newvalue = None
            do_set = True
            while do_set:
                newvalue = raw_input("  Enter new value (or <ENTER> to leave unchanged): ")
                if len(newvalue) == 0:
                    do_set = False
                    break
                confirm = raw_input("  Confirm new value: ")
                if confirm == newvalue:
                    break
                print("Values do not match, try again.")

            if do_set:
                keyring.set_password(service, val, newvalue)
                print("Value set.")

        options[key] = val
    return options 
Example #28
Source File: app.py    From pushbullet-cli with MIT License 5 votes vote down vote up
def _get_pb():
    if 'PUSHBULLET_KEY' in os.environ:
        return pushbullet.PushBullet(os.environ['PUSHBULLET_KEY'])

    password = keyring.get_password("pushbullet", "cli")
    if not password:
        raise NoApiKey()

    return pushbullet.PushBullet(password) 
Example #29
Source File: pkconfig.py    From pkmeter with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get(self, namespace, path, default=None, from_keyring=False):
        path = '%s.%s' % (namespace, path)
        if from_keyring:
            value = keyring.get_password(APPNAME, path)
        else:
            value = utils.rget(self.values, path)
        return value if value is not None else default 
Example #30
Source File: pyicloud_ic3.py    From icloud3 with MIT License 5 votes vote down vote up
def get_password_from_keyring(username):
    """Get the password from a username."""
    result = keyring.get_password(KEYRING_SYSTEM, username)
    if result is None:
        raise PyiCloudNoStoredPasswordAvailableException(
            "No pyicloud password for {username} could be found "
            "in the system keychain.  Use the `--store-in-keyring` "
            "command-line option for storing a password for this "
            "username.".format(username=username,)
        )

    return result