Class: Exos::Commands::Keys::AuthorizedKeys
- Inherits:
-
Hash
- Object
- Hash
- Exos::Commands::Keys::AuthorizedKeys
- Defined in:
- lib/exos/commands/keys.rb
Instance Method Summary collapse
- #add(key) ⇒ Object
- #backup! ⇒ Object
-
#initialize ⇒ AuthorizedKeys
constructor
A new instance of AuthorizedKeys.
- #persist! ⇒ Object
- #remove(key) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ AuthorizedKeys
Returns a new instance of AuthorizedKeys.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# 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 |
Instance Method Details
#add(key) ⇒ Object
104 105 106 |
# File 'lib/exos/commands/keys.rb', line 104 def add(key) self[key.email] = key end |
#backup! ⇒ Object
122 123 124 |
# File 'lib/exos/commands/keys.rb', line 122 def backup! File.open( File.("~/.exos-keys"), "w" ) { |file| file << raw_keys } end |
#persist! ⇒ Object
118 119 120 |
# File 'lib/exos/commands/keys.rb', line 118 def persist! Bastions.exec("echo '#{to_s}' > ~/.ssh/authorized_keys") end |
#remove(key) ⇒ Object
108 109 110 |
# File 'lib/exos/commands/keys.rb', line 108 def remove(key) delete(key.email) end |
#to_s ⇒ Object
112 113 114 115 116 |
# File 'lib/exos/commands/keys.rb', line 112 def to_s reduce("") do |out, (_, key)| out << key.to_s end end |