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
print_keys_list()
click to toggle source
# File lib/exos/commands/keys.rb, line 47 def print_keys_list table = ::Terminal::Table.new({ title: "Users with access", headings: ["Email address", "Status", "Created at", "Updated at", "Public key"] }) authorized_keys.each do |_, auth_key| # Allow administrative keys to be hidden. next if auth_key.status == "IGNORE" cells = [ auth_key.email, auth_key.status, auth_key.created_at, auth_key.updated_at, auth_key.key_fragment ].map do |cell| cell.to_s.send( auth_key.active? ? :green : :red ) end table << cells end puts table end
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