module Donjon::Commands

Public Instance Methods

config_del(key) click to toggle source
# File lib/donjon/commands/config.rb, line 68
def config_del(key)
  database[key] = nil
end
config_fset(key, path) click to toggle source
# File lib/donjon/commands/config.rb, line 46
def config_fset(key, path)
  database[key] = Pathname(path).read
end
config_get(*keys) click to toggle source
# File lib/donjon/commands/config.rb, line 50
def config_get(*keys)
  keys.each do |key|
    puts "#{key}: #{database[key]}"
  end
end
config_mget(regexp = nil) click to toggle source
# File lib/donjon/commands/config.rb, line 56
def config_mget(regexp = nil)
  regexp = Regexp.new(regexp) if regexp
  database.each do |key, value|
    next if regexp && regexp !~ key
    puts "#{key}: #{value}"
  end
rescue RegexpError => e
  say "Misformatted regular expression '#{regexp}'", :red
  say "(#{e.message})"
  exit 1
end
config_mset(*keyvals) click to toggle source
# File lib/donjon/commands/config.rb, line 26
def config_mset(*keyvals)
  keyvals.each do |keyval|
    m = /([^=]*)=(.*)/.match(keyval)
    if m.nil?
      say "Misformatted key-value pair '#{keyval}'"
      exit 1
    end
    key = m[1]
    value = m[2]
    database[key] = value
  end
  say "Warning: the keys and values you just set may be saved to your shell history", :red
  say "You can clear your history by running `history -c`."
end
config_set(key) click to toggle source
# File lib/donjon/commands/config.rb, line 41
def config_set(key)
  value = _get_password("Please enter the value for '#{key}'")
  database[key] = value
end
init() click to toggle source
# File lib/donjon/commands/vault.rb, line 14
def init
  if settings.configured?
    say 'This vault is already configured :)', :green
    say 'If you want another one, set DONJONRC to a new configuration file'
    say "(if it doesn't exist I will create one for you)"
    return
  end

  Configurator.new(settings: settings).run
end
user_add(name, path = nil) click to toggle source
# File lib/donjon/commands/user.rb, line 15
def user_add(name, path = nil)
  if path == nil
    say "Please paste #{name}'s public key in PEM format.", :green
    say "They can obtain it by running e.g.:"
    say "$ openssl rsa -in ~/.ssh/id_rsa -pubout -outform pem"
    $stderr.write('> ')
    key_data = ''
    while line = $stdin.gets
      break if line.strip.empty?
      key_data << line
    end
  else
    key_data = Pathname.new(path).expand_path.read
  end

  key = OpenSSL::PKey::RSA.new(key_data, '').public_key
  say "Saving #{name}'s public key..."
  User.new(name: name, key: key, repo: actor.repo).save
  say "Making the database readable by #{name}..."
  database.update
  say "Success! #{name} has been added to the vault.", [:green, :bold]
end
user_key() click to toggle source
# File lib/donjon/commands/user.rb, line 38
def user_key
  puts actor.key.public_key.to_pem 
end