Class: ShowAction

Inherits:
AesAction show all
Defined in:
lib/lockr/action/show.rb

Instance Method Summary collapse

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) ⇒ ShowAction

Returns a new instance of ShowAction.



5
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/show.rb', line 5

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 10
  end
  
  pwd_directory_id = YAML::load(decrypt( pwd_directory[id][:enc], keyfilehash, pwd_directory[id][:salt]))
  
  if username.nil? 
    unless pwd_directory_id.length == 1
      puts "More than one username for id '#{id}'. Please provide a username!"
      exit 13
    end
     
    key = pwd_directory_id.keys[0]
    store = pwd_directory_id[key]
  else  
    unless pwd_directory_id.has_key?(username)
      puts "Username '#{username}' not found for id '#{id}'"
      exit 11
    end
    
    store = pwd_directory_id[username]
  end
  
  say("Password found")
  say("ID '<%= color('#{store.id}', :blue) %>', URL '<%= color('#{store.url}', :blue) %>'")
  say("User '<%= color('#{store.username}', :blue) %>'")
  say("Password:  <%= color('#{store.password}', :green) %>")
end