class Hunter2::Command

Public Instance Methods

add() click to toggle source
# File lib/hunter2/command.rb, line 17
def add
  if option(:p).nil?
    puts "You need to enter a password."
    exit
  end

  # Encrypt password using FastAES
  encrypted_pass = AES.encrypt(option(:p))

  # Save password and key to database
  password = Hunter2::Model::Password.create_or_update(
    :key      => option(:k),
    :password => encrypted_pass
  )

  puts "Password #{option(:k)} successfully added. Use show -k "+
    "#{option(:k)} to show your password."
end
delete() click to toggle source
# File lib/hunter2/command.rb, line 52
def delete
  password = Hunter2::Model::Password.filter(:key => option(:k)).limit(1)
  password.delete

  puts "Password #{option(:k)} successfully deleted."
end
index() click to toggle source
# File lib/hunter2/command.rb, line 13
def index

end
setup() click to toggle source
# File lib/hunter2/command.rb, line 72
def setup
  Sequel::Migrator.run(
    Hunter2.database,
    File.expand_path('../../../migrations', __FILE__),
      :target => nil
  )
end
show() click to toggle source
# File lib/hunter2/command.rb, line 59
def show
  # Get encrypted password for this key
  password = Hunter2::Model::Password.select(:password) \
    .filter(:key => option(:k)) \
    .limit(1) \
    .single_value

  # Decrypt password
  password = AES.decrypt(password)

  puts "Password for #{option(:key)}: #{password}"
end
update() click to toggle source
# File lib/hunter2/command.rb, line 36
def update
  if option(:p).nil?
    puts "You need to enter a password."
    exit
  end

  # Encrypt password using FastAES
  encrypted_pass = AES.encrypt(option(:p))

  # Update password
  password = Hunter2::Model::Password.filter(:key => option(:k)).limit(1)
  password.update(:password => encrypted_pass)

  puts "Password #{option(:k)} successfully updated."
end

Protected Instance Methods

version() click to toggle source
# File lib/hunter2/command.rb, line 82
def version
  puts Hunter2::Version
  exit
end