Skip to content

Commit

Permalink
added a function for deleting keys from json
Browse files Browse the repository at this point in the history
  • Loading branch information
killswitch committed Jan 13, 2024
1 parent 1a41fd8 commit 8ca8888
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions keyringwarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,25 @@ def add_key():
save_key(service, name)
print("Your key has been saved!")

def remove_key_from_json(service, name):
keys_file = 'keys.json'

with open(keys_file, 'r') as file:
keys = json.load(file)

# Filter out the key to be removed
keys = [key_info for key_info in keys if not (key_info['service'] == service and key_info['name'] == name)]

# Write the updated keys list back to the file
with open(keys_file, 'w') as file:
json.dump(keys, file)

def remove_key():
service = input("Enter service: ")
name = input("Enter name: ")
try:
keyring.delete_password(service, name)
remove_key_from_json(service, name) # Call function to remove key from json
print("Your key has been removed!")
except keyring.errors.PasswordDeleteError:
print("The specified key was not found!")
Expand Down

0 comments on commit 8ca8888

Please sign in to comment.