Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def clear_password_store(self):
try:
keyring.delete_password(self.KEYRING_APP_ID, self.USERNAME)
print("Password removed from Keyring")
except PasswordDeleteError:
logging.error("Password cannot be deleted or already has been removed")
sys.exit(0)
login_json['stateToken'] = state_token
response = self._http_client.post(
url,
json=login_json,
headers=self._get_headers(),
verify=self._verify_ssl_certs
)
response.raise_for_status()
response_data = response.json()
if 'errorCode' in response_data:
if self.KEYRING_ENABLED:
try:
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)
func_result = {'apiResponse': response_data}
if 'stateToken' in response_data:
func_result['stateToken'] = response_data['stateToken']
return func_result
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]
def clear_password_store(self):
try:
keyring.delete_password(self.KEYRING_APP_ID, self.USERNAME)
print("Password removed from Keyring")
except PasswordDeleteError:
logging.error("Password cannot be deleted or already has been removed")
def delete_password(account_name):
log.info('Remove password from keyring')
if not KEYRING_AVAILABLE:
return
try:
return keyring_backend.delete_password('gajim', account_name)
except keyring.errors.PasswordDeleteError as error:
log.warning('Removing password failed: %s', error)
except Exception:
log.exception('Removing password failed')
if args.action == "set":
entered_secret = getpass.getpass(f"Please enter the secret for {args.name}: ")
keyring.set_password(_SECRET_NAMESPACE, args.name, entered_secret)
print(f"Secret {args.name} set successfully")
elif args.action == "get":
the_secret = keyring.get_password(_SECRET_NAMESPACE, args.name)
if the_secret is None:
print(f"Secret {args.name} not found")
else:
print(f"Secret {args.name}={the_secret}")
elif args.action == "del":
try:
keyring.delete_password(_SECRET_NAMESPACE, args.name)
print(f"Deleted secret {args.name}")
except keyring.errors.PasswordDeleteError:
print(f"Secret {args.name} not found")
def delete_password(self, service, username):
"""Delete the password for the username of the service.
"""
service = escape_for_ini(service)
username = escape_for_ini(username)
config = configparser.RawConfigParser()
if os.path.exists(self.file_path):
config.read(self.file_path)
try:
if not config.remove_option(service, username):
raise PasswordDeleteError("Password not found")
except configparser.NoSectionError:
raise PasswordDeleteError("Password not found")
# update the file
with open(self.file_path, 'w') as config_file:
config.write(config_file)