Python keyring.get_password() Examples

The following are 30 code examples for showing how to use keyring.get_password(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module keyring , or try the search function .

Example 1
Project: snowflake-connector-python   Author: snowflakedb   File: auth.py    License: 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 2
Project: earthengine   Author: mortcanty   File: keyring_storage.py    License: 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 3
Project: poetry   Author: python-poetry   File: password_manager.py    License: 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 4
Project: splunk-ref-pas-code   Author: splunk   File: keyring_storage.py    License: 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 5
Project: sndlatr   Author: Schibum   File: keyring_storage.py    License: 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 6
Project: billing-export-python   Author: googlearchive   File: keyring_storage.py    License: 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 7
Project: aqua-monitor   Author: Deltares   File: keyring_storage.py    License: 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 8
Project: googleapps-message-recall   Author: google   File: keyring_storage.py    License: 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 9
Project: azure-devops-cli-extension   Author: Azure   File: credential_store.py    License: 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 10
Project: resilient-python-api   Author: ibmresilient   File: co3argparse.py    License: 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 11
Project: CumulusCI   Author: SFDO-Tooling   File: runtime.py    License: 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 12
Project: alfred-gmail   Author: fniephaus   File: keyring_storage.py    License: 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 13
Project: luci-py   Author: luci   File: keyring_storage.py    License: 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
Project: luci-py   Author: luci   File: keyring_storage.py    License: 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
Project: luci-py   Author: luci   File: keyring_storage.py    License: 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 16
Project: luci-py   Author: luci   File: keyring_storage.py    License: 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 17
Project: luci-py   Author: luci   File: keyring_storage.py    License: 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 18
Project: twitter-for-bigquery   Author: twitterdev   File: keyring_storage.py    License: 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
Project: runsqlrun   Author: andialbrecht   File: manager.py    License: 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 20
Project: jarvis   Author: haynieresearch   File: keyring_storage.py    License: 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 21
Project: data   Author: jmankoff   File: keyring_storage.py    License: 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 22
Project: data   Author: jmankoff   File: keyring_storage.py    License: 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 23
Project: data   Author: jmankoff   File: keyring_storage.py    License: 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 24
Project: data   Author: jmankoff   File: keyring_storage.py    License: 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 25
Project: data   Author: jmankoff   File: keyring_storage.py    License: 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 26
Project: pkmeter   Author: pkkid   File: pkconfig.py    License: 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 27
Project: EDMarketConnector   Author: EDCD   File: config.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_password(self, account):
        try:
            import keyring
            return keyring.get_password(self.identifier, account)
        except ImportError:
            return None 
Example 28
Project: poetry   Author: python-poetry   File: password_manager.py    License: MIT License 5 votes vote down vote up
def get_password(self, name, username):
        if not self.is_available():
            return

        import keyring
        import keyring.errors

        name = self.get_entry_name(name)

        try:
            return keyring.get_password(name, username)
        except (RuntimeError, keyring.errors.KeyringError):
            raise KeyRingError(
                "Unable to retrieve the password for {} from the key ring".format(name)
            ) 
Example 29
Project: poetry   Author: python-poetry   File: password_manager.py    License: MIT License 5 votes vote down vote up
def get_pypi_token(self, name):
        if not self.keyring.is_available():
            return self._config.get("pypi-token.{}".format(name))

        return self.keyring.get_password(name, "__token__") 
Example 30
Project: jira   Author: pycontribs   File: jirashell.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def handle_basic_auth(auth, server):
    if auth.get("password"):
        password = auth["password"]
        if input("Would you like to remember password in OS keyring? (y/n)") == "y":
            keyring.set_password(server, auth["username"], password)
    else:
        print("Getting password from keyring...")
        password = keyring.get_password(server, auth["username"])
        assert password, "No password provided!"
    return (auth["username"], password)