Class: Golem::Command::UpdateKeysFile
- Defined in:
- lib/golem/command/update_keys_file.rb
Overview
Command for updating the .ssh/authorized_keys file.
Constant Summary collapse
- CONTENT_MARK =
Content mark to identify automatically updated part of file.
"# golem keys - do not place lines below, because the content gets rewritten (AND DO NOT EDIT THIS LINE!)"
- SSH_OPTS_COMMAND_DEFAULT =
Default SSH(D) options to set if using command=“” style keys file.
"no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty"
Instance Method Summary collapse
-
#run ⇒ Object
Run the command.
Methods inherited from Base
#command, #initialize, #verbose?
Constructor Details
This class inherits a constructor from Golem::Command::Base
Instance Method Details
#run ⇒ Object
Run the command. Old content is preserved, searched for CONTENT_MARK, and only content after the mark gets replaced.
11 12 13 14 15 16 17 18 19 |
# File 'lib/golem/command/update_keys_file.rb', line 11 def run orig_content = File.exists?(Golem::Config.keys_file_path) ? File.read(Golem::Config.keys_file_path) : "" new_content = if orig_content.match(Regexp.new('^' + Regexp.escape(CONTENT_MARK) + '$')) orig_content.sub(Regexp.new('^' + Regexp.escape(CONTENT_MARK) + '$.*\z', Regexp::MULTILINE), CONTENT_MARK + "\n" + keys_str) else orig_content + "\n" + CONTENT_MARK + "\n" + keys_str end File.open(Golem::Config.keys_file_path, "w") {|f| f.write(new_content)} end |