Module: GitHandler::AuthorizedKeys
- Defined in:
- lib/git_handler/authorized_keys.rb
Class Method Summary collapse
-
.write(path, content) ⇒ Object
Write contents to file with lock.
-
.write_key(path, key, command) ⇒ Object
Write a single key formatted content to file.
-
.write_keys(path, keys, command) ⇒ Object
Write formatted keys content to file.
Class Method Details
.write(path, content) ⇒ Object
Write contents to file with lock
path - Path to output file content - String buffer
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/git_handler/authorized_keys.rb', line 8 def self.write(path, content) raise ArgumentError, "File \"#{path}\" does not exist." if !File.exists?(path) raise ArgumentError, "File \"#{path}\" is not writable." if !File.writable?(path) File.open(path, 'w') do |f| f.flock(File::LOCK_EX) f.write(content) f.flock(File::LOCK_UN) end end |
.write_key(path, key, command) ⇒ Object
Write a single key formatted content to file
path - Path to the output file key - GitHandler::PublicKey instance command - A custom command for the key
36 37 38 |
# File 'lib/git_handler/authorized_keys.rb', line 36 def self.write_key(path, key, command) self.write_keys(path, [key], command) end |
.write_keys(path, keys, command) ⇒ Object
Write formatted keys content to file
path - Path to authorized_keys file keys - Array of GitHandler::PublicKey instances command - A custom command for the key
25 26 27 28 |
# File 'lib/git_handler/authorized_keys.rb', line 25 def self.write_keys(path, keys, command) content = keys.map { |k| k.to_system_key(command) }.join("\n").strip self.write(path, content) end |