Class: Github::Auth::KeysFile
- Inherits:
-
Object
- Object
- Github::Auth::KeysFile
- 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
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #delete!(keys) ⇒ Object
- #github_users ⇒ Object
-
#initialize(options = {}) ⇒ KeysFile
constructor
A new instance of KeysFile.
- #write!(keys) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ KeysFile
Returns a new instance of KeysFile.
11 12 13 14 |
# File 'lib/github/auth/keys_file.rb', line 11 def initialize( = {}) @path = File.([:path] || DEFAULT_PATH) @command = [:command] end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
4 5 6 |
# File 'lib/github/auth/keys_file.rb', line 4 def command @command end |
#path ⇒ Object (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
29 30 31 32 33 |
# File 'lib/github/auth/keys_file.rb', line 29 def delete!(keys) new_content = keys_file_content_without keys write_keys_file { |keys_file| keys_file.write new_content } end |
#github_users ⇒ Object
35 36 37 38 39 |
# File 'lib/github/auth/keys_file.rb', line 35 def github_users # http://rubular.com/r/zXCkewmm0i regex = %r{github\.com/(\S+)} keys_file_content.scan(regex).flatten.uniq.sort end |
#write!(keys) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/github/auth/keys_file.rb', line 16 def write!(keys) Array(keys).each do |key| unless keys_file_content.include? key.key append_keys_file do |keys_file| unless keys_file_content.empty? || keys_file_content.end_with?("\n") keys_file.write "\n" end keys_file.write "#{"command=\"#{command}\" " if command}#{key}\n" end end end end |