class Exos::Commands::Keys::AuthorizedKeys
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/exos/commands/keys.rb, line 126 def initialize(*) super lines = raw_keys.lines.map(&:chomp).reject(&:empty?) idx = 0 while idx < lines.count attrs_line = lines[idx] unless attrs_line.match(/\A### exos-key/) idx += 1 next end key_line = lines[idx + 1] add( Key.parse(attrs_line, key_line) ) idx += 2 end end
Public Instance Methods
add(key)
click to toggle source
# File lib/exos/commands/keys.rb, line 104 def add(key) self[key.email] = key end
backup!()
click to toggle source
# File lib/exos/commands/keys.rb, line 122 def backup! File.open( File.expand_path("~/.exos-keys"), "w" ) { |file| file << raw_keys } end
persist!()
click to toggle source
# File lib/exos/commands/keys.rb, line 118 def persist! Bastions.exec("echo '#{to_s}' > ~/.ssh/authorized_keys") end
remove(key)
click to toggle source
# File lib/exos/commands/keys.rb, line 108 def remove(key) delete(key.email) end
to_s()
click to toggle source
# File lib/exos/commands/keys.rb, line 112 def to_s reduce("") do |out, (_, key)| out << key.to_s end end
Private Instance Methods
raw_keys()
click to toggle source
# File lib/exos/commands/keys.rb, line 148 def raw_keys @raw_keys ||= Bastions.exec("cat ~/.ssh/authorized_keys").stdout end
reset!()
click to toggle source
# File lib/exos/commands/keys.rb, line 152 def reset! @raw_keys = nil @all = nil end