How to use the keyring.errors 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 nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / pyfs.py View on Github external
def delete_password(self, service, username):
        service = escape_for_ini(service)
        username = escape_for_ini(username)

        try:
            self.config.remove_option(service, username)
        except configparser.NoSectionError:
            raise errors.PasswordDeleteError('Password not found')
        config_file = UnicodeWriterAdapter(self._open('w'))
        self.config.write(config_file)
        config_file.close()
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / multi.py View on Github external
def delete_password(self, service, username):
        self._keyring.delete_password(service, username)
        count = itertools.count(1)
        while True:
            part_name = '%(username)s{{part_%(index)d}}' % dict(
                index = next(count), **vars())
            try:
                self._keyring.delete_password(service, part_name)
            except errors.PasswordDeleteError:
                break
github gkluoe / git2jss / git2jss / jss_keyring.py View on Github external
def get_creds_from_keychain(service, user):
    """" Fetch the credentials for `jss_url` from the keychain """
    try:
        result = keyring.get_password(service, user)
    except keyring.errors.KeyringError as error:
        print("Failed to get credentials from keychain: {}".format(error))
        print("If you are running in a virtualenv, this is expected")
        print("See: https://github.com/jaraco/keyring/issues/219")
        raise
    if result:
        return result
    else:
        raise keyring.errors.KeyringError(("Couldn't find a password in the keychain for\n"
                                           "%s on %s" % (user, service)))
github zbarge / stocklook / stocklook / utils / security.py View on Github external
and replaces with a new one if desired.

        :param service_name: (str)
            The service name to remove.

        :param username: (str)
            The username to remove the password for.

        :param new_secret_items: (list, default None)
            The new secret item(s) to assign to the username if desired.

        :return: (None)
        """
        try:
            keyring.delete_password(service_name, username)
        except keyring.errors.PasswordDeleteError:
            pass

        if new_secret_items:
            new_pass = self._join_password_items(new_secret_items)
            keyring.set_password(service_name, username, new_pass)
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
def _del_entry(self, keyring_dict, service, username):
        service_entries = keyring_dict.get(service)
        if not service_entries:
            raise errors.PasswordDeleteError("No matching service")
        try:
            del service_entries[username]
        except KeyError:
            raise errors.PasswordDeleteError("Not found")
        if not service_entries:
            del keyring_dict[service]
github Azure / azure-devops-cli-extension / azure-devops / azext_devops / dev / common / credential_store.py View on Github external
try:
                keyring_token = keyring.get_password(key, self._USERNAME)
                if keyring_token:
                    keyring.delete_password(key, self._USERNAME)
            except Exception as ex:  # pylint: disable=broad-except
                logger.debug("%s", ex)
            finally:
                file_token = self.get_PAT_from_file(key)
                if file_token:
                    self.delete_PAT_from_file(key)
            if(keyring_token is None and file_token is None):
                raise CLIError(self._CRDENTIAL_NOT_FOUND_MSG)
        else:
            try:
                keyring.delete_password(key, self._USERNAME)
            except keyring.errors.PasswordDeleteError:
                raise CLIError(self._CRDENTIAL_NOT_FOUND_MSG)
            except RuntimeError as ex:  # pylint: disable=broad-except
                raise CLIError(ex)
github Tyilo / auprint / auprint.py View on Github external
super().__setattr__(key, value)

		if key == 'username':
			try:
				if value == None:
					Path(self.filename).unlink()
				else:
					with open(self.filename, 'w') as f:
						f.write(self.username)
			except IOError:
				pass
		elif key == 'password':
			if value == None:
				try:
					keyring.delete_password('auprint', 'auid')
				except keyring.errors.PasswordDeleteError:
					pass
			else:
				keyring.set_password('auprint', 'auid', value)