Class: Github::Auth::KeysFile

Inherits:
Object
  • Object
show all
Defined in:
lib/github/auth/keys_file.rb

Overview

Write and delete keys from the authorized_keys file

Constant Summary collapse

PermissionDeniedError =
Class.new StandardError
FileDoesNotExistError =
Class.new StandardError
DEFAULT_PATH =
'~/.ssh/authorized_keys'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ KeysFile

Returns a new instance of KeysFile.



11
12
13
# File 'lib/github/auth/keys_file.rb', line 11

def initialize(options = {})
  @path = File.expand_path(options[:path] || DEFAULT_PATH)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/github/auth/keys_file.rb', line 4

def path
  @path
end

Instance Method Details

#delete!(keys) ⇒ Object



26
27
28
29
30
# File 'lib/github/auth/keys_file.rb', line 26

def delete!(keys)
  new_content = keys_file_content_without keys

  write_keys_file { |keys_file| keys_file.write new_content }
end

#write!(keys) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/github/auth/keys_file.rb', line 15

def write!(keys)
  Array(keys).each do |key|
    unless keys_file_content.include? key.key
      append_keys_file do |keys_file|
        keys_file.write "\n" unless keys_file_content.empty?
        keys_file.write key
      end
    end
  end
end