本文整理汇总了Python中keyring.delete_password方法的典型用法代码示例。如果您正苦于以下问题:Python keyring.delete_password方法的具体用法?Python keyring.delete_password怎么用?Python keyring.delete_password使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keyring
的用法示例。
在下文中一共展示了keyring.delete_password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reset_credentials
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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)
示例2: refresh_access_token
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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)
示例3: delete_temporary_credential
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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()
示例4: delete_password
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
def delete_password(self, account):
try:
import keyring
keyring.delete_password(self.identifier, account)
except:
pass # don't care - silently fail
# singleton
示例5: delete_password
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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)
)
示例6: delete_pypi_token
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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__")
示例7: delete_http_password
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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))
示例8: clear_auth
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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")
示例9: write
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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 = {}
示例10: delete
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
def delete(name):
keyring.delete_password(DOMAIN, name)
示例11: delete_account
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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.')
示例12: test_save_and_load
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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')
示例13: set_password
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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)
示例14: clear_password
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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)
示例15: clear_config
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import delete_password [as 别名]
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')