Sha256: 5d0e1e9793954a15e6791e130100298c92607868e1ea498e2015b0455e14c19a

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'lockr/action/aes'

class ShowAction < AesAction
  
  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
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lockr-0.2.1 lib/lockr/action/show.rb
lockr-0.2.0 lib/lockr/action/show.rb