class Exos::Commands::Keys

Constants

LOCKFILE_NAME
PATTERN_ATTRS_LINE
PATTERN_KEY_LINE

Public Instance Methods

run() click to toggle source
# File lib/exos/commands/keys.rb, line 28
def run
  authorized_keys.backup!
  Bastions.role = options.role

  if email = options.grant
    add_key(email)
  elsif email = options.revoke
    remove_key(email, options.delete)
  else
    print_keys_list
  end
end

Private Instance Methods

add_key(email) click to toggle source
# File lib/exos/commands/keys.rb, line 73
def add_key(email)
  if found_key = authorized_keys[email]
    found_key.activate
  else
    key_text = ask("Enter public key:")
    authorized_keys.add( Key.new(email: email, key: key_text) )
  end

  authorized_keys.persist!

  print_keys_list
end
authorized_keys() click to toggle source
# File lib/exos/commands/keys.rb, line 43
def authorized_keys
  @authorized_keys ||= AuthorizedKeys.new
end
print_keys_list() click to toggle source
remove_key(email, delete) click to toggle source
# File lib/exos/commands/keys.rb, line 86
def remove_key(email, delete)
  if found_key = authorized_keys[email]
    if delete
      authorized_keys.remove(found_key)
    else
      found_key.deactivate
    end

    authorized_keys.persist!
  else
    abort "No key found."
  end

  print_keys_list
end