Class: RemoveAction
- Inherits:
-
AesAction
- Object
- BaseAction
- AesAction
- RemoveAction
- Defined in:
- lib/lockr/action/remove.rb
Instance Method Summary collapse
-
#initialize(id, username, keyfile, vault) ⇒ RemoveAction
constructor
A new instance of RemoveAction.
Methods included from Aes
#decrypt, #derive_key_iv, #encrypt
Methods inherited from BaseAction
#calculate_hash, #load_from_vault, #rotate_vault, #save_to_vault
Constructor Details
#initialize(id, username, keyfile, vault) ⇒ RemoveAction
Returns a new instance of RemoveAction.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lockr/action/remove.rb', line 6 def initialize(id,username,keyfile,vault) keyfilehash = calculate_hash( keyfile) pwd_directory = load_from_vault( vault) unless pwd_directory.has_key?( id) puts "Id '#{id}' not found" exit 20 end pwd_directory_id = YAML::load(decrypt( pwd_directory[id][:enc], keyfilehash, pwd_directory[id][:salt])) unless pwd_directory_id.has_key?(username) puts "Username '#{username}' not found for id '#{id}'" exit 21 end confirm = ask( "Are you sure you want to delete the entry with id '#{id}' and username '#{username}'? (y/n) ") { |q| } unless confirm.downcase == 'y' exit 22 end pwd_directory_id.delete( username) if ( pwd_directory_id.size == 0 ) pwd_directory.delete( id) else pwd_directory[id] = {} pwd_directory[id][:enc], pwd_directory[id][:salt] = encrypt( pwd_directory_id.to_yaml, keyfilehash) end save_to_vault( pwd_directory, vault) puts "Entry removed" end |