Sha256: 5ccc8b8ead8cacaa555088bc9490125dd2573caadd7f0bb5f98b0b53836ee46c

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module GitHandler
  module AuthorizedKeys
    # Write contents to file with lock
    # 
    # path    - Path to output file
    # content - String buffer
    #
    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 formatted keys content to file
    #
    # path    - Path to authorized_keys file
    # keys    - Array of GitHandler::PublicKey instances
    # command - A custom command for the key
    #
    def self.write_keys(path, keys, command)
      content = keys.map { |k| k.to_system_key(command) }.join("\n").strip
      self.write(path, content)
    end

    # 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
    #
    def self.write_key(path, key, command)
      self.write_keys(path, [key], command)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git_handler-0.2.1 lib/git_handler/authorized_keys.rb
git_handler-0.2.0 lib/git_handler/authorized_keys.rb