class Trunk::CLI

Public Instance Methods

add(name, password = $stdin.gets.strip) click to toggle source
# File lib/trunk/cli.rb, line 4
def add(name, password = $stdin.gets.strip)
  storage.store(name, password)
end
setup() click to toggle source
# File lib/trunk/cli.rb, line 22
def setup
  FileUtils.mkdir_p(dir)
  exit(0) unless file_collision(private_key_path) if File.exist?(private_key_path)
  IO.write(private_key_path, OpenSSL::PKey::RSA.new(4096).export(options[:algorithm], passphrase))
  FileUtils.touch(database_path)
  [database_path, private_key_path].each { |x| FileUtils.chmod(0600, x) }
end
show(name) click to toggle source
# File lib/trunk/cli.rb, line 9
def show(name)
  print storage.fetch(name)
rescue OpenSSL::PKey::RSAError => error
  say error.message, :red
end
version() click to toggle source
# File lib/trunk/cli.rb, line 16
def version
  say Trunk::VERSION
end

Private Instance Methods

database_path() click to toggle source
# File lib/trunk/cli.rb, line 36
def database_path
  File.join(dir, '.trunk.enc')
end
dir() click to toggle source
# File lib/trunk/cli.rb, line 44
def dir
  ENV['TRUNK_HOME'] || File.join(Dir.home, '.trunk')
end
passphrase() click to toggle source
# File lib/trunk/cli.rb, line 52
def passphrase
  ENV['TRUNK_PASSPHRASE'] || ask("passphrase:", echo: false)
end
private_key() click to toggle source
# File lib/trunk/cli.rb, line 48
def private_key
  OpenSSL::PKey::RSA.new(IO.read(private_key_path), passphrase)
end
private_key_path() click to toggle source
# File lib/trunk/cli.rb, line 40
def private_key_path
  File.join(dir, '.trunk.key.enc')
end
storage() click to toggle source
# File lib/trunk/cli.rb, line 32
def storage
  @storage ||= Trunk::YAMLStorage.new(database_path, private_key)
end