Python keyring.delete_password() Examples
The following are 20
code examples of keyring.delete_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: auth.py From flytekit with Apache License 2.0 | 6 votes |
def refresh_access_token(self): if self._refresh_token is None: raise ValueError("no refresh token available with which to refresh authorization credentials") resp = _requests.post( url=self._token_endpoint, data={'grant_type': 'refresh_token', 'client_id': self._client_id, 'refresh_token': self._refresh_token}, headers=self._headers, allow_redirects=False ) if resp.status_code != _StatusCodes.OK: self._expired = True # In the absence of a successful response, assume the refresh token is expired. This should indicate # to the caller that the AuthorizationClient is defunct and a new one needs to be re-initialized. _keyring.delete_password(_keyring_service_name, _keyring_access_token_storage_key) _keyring.delete_password(_keyring_service_name, _keyring_refresh_token_storage_key) return self._initialize_credentials(resp)
Example #2
Source File: security.py From stocklook with MIT License | 6 votes |
def reset_credentials(self, service_name, username, new_secret_items=None): """ Removes a username/password from KeyRing 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)
Example #3
Source File: test_api_session.py From onedrived-dev with MIT License | 5 votes |
def test_save_and_load(self): keydict = {self.session.SESSION_ARG_KEYNAME: 'mock_key'} self.session.save_session(**keydict) session = od_api_session.OneDriveAPISession.load_session(**keydict) self.assertEqual(self.session.token_type, session.token_type) self.assertEqual(self.session.scope, session.scope) self.assertEqual(self.session.access_token, session.access_token) self.assertEqual(self.session.client_id, session.client_id) self.assertEqual(self.session.client_secret, session.client_secret) self.assertEqual(self.session.refresh_token, session.refresh_token) keyring.delete_password(od_api_session.OneDriveAPISession.KEYRING_SERVICE_NAME, 'mock_key')
Example #4
Source File: pyicloud_ic3.py From icloud3 with MIT License | 5 votes |
def delete_password_in_keyring(username): """Delete the password of a username.""" return keyring.delete_password(KEYRING_SYSTEM, username,)
Example #5
Source File: secrets.py From releasetool with Apache License 2.0 | 5 votes |
def delete_password(): keyring.delete_password(_SERVICE, "github")
Example #6
Source File: app.py From pushbullet-cli with MIT License | 5 votes |
def delete_key(): keyring.delete_password("pushbullet", "cli")
Example #7
Source File: client.py From yolo with Apache License 2.0 | 5 votes |
def clear_config(self): keyring.delete_password(const.NAMESPACE, 'rackspace_username') keyring.delete_password(const.NAMESPACE, 'rackspace_api_key') keyring.delete_password(const.NAMESPACE, 'aws_profile_name')
Example #8
Source File: credential_store.py From azure-devops-cli-extension with MIT License | 5 votes |
def clear_password(self, key): try: import keyring except ImportError: install_keyring() self._initialize_keyring() import keyring if sys.platform.startswith(self._LINUX_PLATFORM): keyring_token = None file_token = None 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)
Example #9
Source File: credential_store.py From azure-devops-cli-extension with MIT License | 5 votes |
def set_password(self, key, token): try: import keyring except ImportError: install_keyring() self._initialize_keyring() import keyring try: # check for and delete existing credential old_token = keyring.get_password(key, self._USERNAME) if old_token is not None: keyring.delete_password(key, self._USERNAME) logger.debug('Setting credential: %s', key) keyring.set_password(key, self._USERNAME, token) except Exception as ex: # pylint: disable=broad-except # store credentials in azuredevops config directory if keyring is missing or malfunctioning if sys.platform.startswith(self._LINUX_PLATFORM): logger.warning('Failed to store PAT using keyring; falling back to file storage.') logger.warning('You can clear the stored credential by running az devops logout.') logger.warning('Refer https://aka.ms/azure-devops-cli-auth to know more on sign in with PAT.') logger.debug('Keyring failed. ERROR :%s', ex) logger.debug('Storing credentials in the file: %s', self._PAT_FILE) creds_list = self._get_credentials_list() if key not in creds_list.sections(): creds_list.add_section(key) logger.debug('Added new entry to PAT file : %s ', key) creds_list.set(key, self._USERNAME, token) self._commit_change(creds_list) else: raise CLIError(ex)
Example #10
Source File: auth.py From snowflake-connector-python with Apache License 2.0 | 5 votes |
def delete_temporary_credential(host, user, store_temporary_credential=False): if (IS_MACOS or IS_WINDOWS) and keyring: new_target = convert_target(host, user) try: keyring.delete_password(new_target, user.upper()) except Exception as ex: logger.debug("Failed to delete credential in the keyring: err=[%s]", ex) elif IS_LINUX and store_temporary_credential: delete_temporary_credential_file()
Example #11
Source File: od_pref.py From onedrived-dev with MIT License | 5 votes |
def delete_account(yes=False, index=None, email=None, account_id=None): click.echo('All OneDrive accounts associated with user "%s":\n' % context.user_name) all_account_ids = print_all_accounts(context) click.echo() if index is None and email is None and account_id is None: # Print account table and ask which account to delete. index = click.prompt('Please enter row number of the account to delete (CTRL+C to abort)', type=int) if index is not None: if isinstance(index, int) and 0 <= index < len(all_account_ids): account_id = all_account_ids[index] else: error('Index is not a valid row number.') return if email is not None: try: account_id = email_to_account_id(context, email, all_account_ids) except Exception as e: error(str(e)) return if account_id is not None: if account_id not in all_account_ids: error('Account ID "%s" is not found.' % account_id) return account = context.get_account(account_id) prompt_text = 'Are you sure to delete account %s?' % account if yes or click.confirm(prompt_text): context.delete_account(account_id) keyring.delete_password(OneDriveAPISession.KEYRING_SERVICE_NAME, get_keyring_key(account_id)) save_context(context) success('Successfully deleted account from onedrived.') else: click.echo('Operation canceled.')
Example #12
Source File: keyring.py From google-analytics with ISC License | 5 votes |
def delete(name): keyring.delete_password(DOMAIN, name)
Example #13
Source File: config.py From biweeklybudget with GNU Affero General Public License v3.0 | 5 votes |
def write(self, *args): """See ConfigParser.write(). Also writes secure items to keystore.""" ConfigParser.write(self, *args) if self.keyring_available: for key, thing in self._unsaved.items(): action = thing[0] value = thing[1] if action == 'set': keyring.set_password(self.keyring_name, key, value) elif action == 'delete': try: keyring.delete_password(self.keyring_name, key) except: pass self._unsaved = {}
Example #14
Source File: humblebundle.py From humblebundle with GNU General Public License v3.0 | 5 votes |
def clear_auth(appname=None, authfile=None, cookiejar=None): '''Clear all authentication data and delete related files''' appname = appname or APPNAME authfile = authfile or AUTHFILE cookiejar = cookiejar or COOKIEJAR authfiles = [cookiejar] log.info("Clearing all authentication data") if keyring: try: log.debug("Removing credentials from keyring") keyring.delete_password(appname, appname) except AttributeError as e: log.warning("Error removing keyring credentials. Outdated library? (%s)", e) else: authfiles.append(authfile) for auth in authfiles: try: log.debug("Deleting '%s'", auth) os.remove(auth) except OSError as e: log.debug(e) log.info("Finished clearing authentication")
Example #15
Source File: password_manager.py From poetry with MIT License | 5 votes |
def delete_http_password(self, name): auth = self.get_http_auth(name) if not auth or "username" not in auth: return try: self.keyring.delete_password(name, auth["username"]) except KeyRingError: pass self._config.auth_config_source.remove_property("http-basic.{}".format(name))
Example #16
Source File: password_manager.py From poetry with MIT License | 5 votes |
def delete_pypi_token(self, name): if not self.keyring.is_available(): return self._config.auth_config_source.remove_property( "pypi-token.{}".format(name) ) self.keyring.delete_password(name, "__token__")
Example #17
Source File: config.py From EDMarketConnector with GNU General Public License v2.0 | 5 votes |
def delete_password(self, account): try: import keyring keyring.delete_password(self.identifier, account) except: pass # don't care - silently fail # singleton
Example #18
Source File: okta.py From gimme-aws-creds with Apache License 2.0 | 4 votes |
def _login_username_password(self, state_token, url): """ login to Okta with a username and password""" creds = self._get_username_password_creds() login_json = { 'username': creds['username'], 'password': creds['password'] } # If this isn't a Step-up auth flow, we won't have a stateToken if state_token is not None: login_json['stateToken'] = state_token response = self._http_client.post( url, json=login_json, headers=self._get_headers(), verify=self._verify_ssl_certs ) response_data = response.json() if response.status_code == 200: pass # Handle known Okta error codes # ref: https://developer.okta.com/docs/reference/error-codes/#example-errors-listed-by-http-return-code elif response.status_code in [400, 401, 403, 404, 409, 429, 500, 501, 503]: if response_data['errorCode'] == "E0000004": if self.KEYRING_ENABLED: try: self.ui.info("Stored password is invalid, clearing. Please try again") keyring.delete_password(self.KEYRING_SERVICE, creds['username']) except PasswordDeleteError: pass raise errors.GimmeAWSCredsError( "LOGIN ERROR: {} | Error Code: {}".format(response_data['errorSummary'], response_data['errorCode']), 2) # If the error code isn't one we know how to handle, raise an exception else: response.raise_for_status() func_result = {'apiResponse': response_data} if 'stateToken' in response_data: func_result['stateToken'] = response_data['stateToken'] return func_result
Example #19
Source File: humblebundle.py From humblebundle with GNU General Public License v3.0 | 4 votes |
def read_config(args, appname=None, authfile=None): appname = appname or APPNAME authfile = authfile or AUTHFILE username = "" password = "" # read if keyring: log.debug("Reading credentials from keyring") try: username, password = ( keyring.get_password(appname, appname).split('\n') + ['\n'] )[:2] except AttributeError as e: # Check for old keyring format and migrate before throwing warning data = keyring.get_password(appname, '') if data: log.info("Migrating credentials to new keyring format") keyring.set_password(appname, appname, data) try: keyring.delete_password(appname, '') except AttributeError as e: log.warning("Error deleting old keyring. Outdated library? (%s)", e) else: log.warning("Credentials not found in keyring. First time usage?") except IOError as e: # keyring sometimes raises this log.error(e) else: log.debug("Reading credentials from '%s'" % authfile) try: with open(authfile, 'r') as fd: username, password = (fd.read().splitlines() + ['\n'])[:2] except IOError as e: if e.errno == 2: # No such file or directory log.warning("Credentials file not found. First time usage?") else: log.error(e) # save if args.username or args.password: log.info("Saving credentials") if keyring: keyring.set_password(appname, appname, '%s\n%s' % (args.username or username, args.password or password,)) else: try: with open(authfile, 'w') as fd: fd.write("%s\n%s\n" % (args.username or username, args.password or password,)) os.chmod(authfile, 0o600) except IOError as e: log.error(e) return dict(username=username, password=password,)
Example #20
Source File: password_manager.py From poetry with MIT License | 4 votes |
def delete_password(self, name, username): if not self.is_available(): return import keyring import keyring.errors name = self.get_entry_name(name) try: keyring.delete_password(name, username) except (RuntimeError, keyring.errors.KeyringError): raise KeyRingError( "Unable to delete the password for {} from the key ring".format(name) )