Class: Pair::Session::AuthorizedKeysFile
- Inherits:
-
Object
- Object
- Pair::Session::AuthorizedKeysFile
- Defined in:
- lib/pair/session/authorized_keys_file.rb
Constant Summary collapse
- ACCESS_TYPE =
"type"
- KEYS =
"keys"
Instance Attribute Summary collapse
-
#key_file_path ⇒ Object
Returns the value of attribute key_file_path.
-
#member_keys ⇒ Object
Returns the value of attribute member_keys.
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
- #backup_authorized_keys ⇒ Object
- #backup_key_file_exists? ⇒ Boolean
- #backup_key_file_path ⇒ Object
- #cleanup ⇒ Object
- #cleanup_authorized_keys ⇒ Object
-
#initialize(member_keys = {}, session) ⇒ AuthorizedKeysFile
constructor
A new instance of AuthorizedKeysFile.
- #install ⇒ Object
- #key_file_exists? ⇒ Boolean
- #line_numbers_of(key) ⇒ Object
- #move_backup_file ⇒ Object
- #remove_existing_file ⇒ Object
Constructor Details
#initialize(member_keys = {}, session) ⇒ AuthorizedKeysFile
Returns a new instance of AuthorizedKeysFile.
11 12 13 14 15 |
# File 'lib/pair/session/authorized_keys_file.rb', line 11 def initialize(member_keys = {}, session) self.member_keys = member_keys self.session = session self.key_file_path = File.("~/.ssh/authorized_keys") end |
Instance Attribute Details
#key_file_path ⇒ Object
Returns the value of attribute key_file_path.
9 10 11 |
# File 'lib/pair/session/authorized_keys_file.rb', line 9 def key_file_path @key_file_path end |
#member_keys ⇒ Object
Returns the value of attribute member_keys.
7 8 9 |
# File 'lib/pair/session/authorized_keys_file.rb', line 7 def member_keys @member_keys end |
#session ⇒ Object
Returns the value of attribute session.
8 9 10 |
# File 'lib/pair/session/authorized_keys_file.rb', line 8 def session @session end |
Instance Method Details
#backup_authorized_keys ⇒ Object
33 34 35 36 |
# File 'lib/pair/session/authorized_keys_file.rb', line 33 def puts "Backing up authorized_keys: #{self.key_file_path}" if $-d FileUtils.cp(self.key_file_path, backup_key_file_path) end |
#backup_key_file_exists? ⇒ Boolean
56 57 58 |
# File 'lib/pair/session/authorized_keys_file.rb', line 56 def backup_key_file_exists? File.exists? backup_key_file_path end |
#backup_key_file_path ⇒ Object
60 61 62 |
# File 'lib/pair/session/authorized_keys_file.rb', line 60 def backup_key_file_path "#{self.key_file_path}.pair" end |
#cleanup ⇒ Object
24 25 26 |
# File 'lib/pair/session/authorized_keys_file.rb', line 24 def cleanup end |
#cleanup_authorized_keys ⇒ Object
28 29 30 31 |
# File 'lib/pair/session/authorized_keys_file.rb', line 28 def remove_existing_file move_backup_file if backup_key_file_exists? end |
#install ⇒ Object
17 18 19 20 21 22 |
# File 'lib/pair/session/authorized_keys_file.rb', line 17 def install return nil if self.member_keys.values.empty? || self.member_keys.values.map { |k,v| v }.empty? if key_file_exists? end |
#key_file_exists? ⇒ Boolean
52 53 54 |
# File 'lib/pair/session/authorized_keys_file.rb', line 52 def key_file_exists? File.exists? self.key_file_path end |
#line_numbers_of(key) ⇒ Object
48 49 50 |
# File 'lib/pair/session/authorized_keys_file.rb', line 48 def line_numbers_of(key) `grep -ns ".*#{key}.*" #{self.key_file_path} | sed 's/\:.*//'`.split('\n').map(&:strip) end |
#move_backup_file ⇒ Object
43 44 45 46 |
# File 'lib/pair/session/authorized_keys_file.rb', line 43 def move_backup_file puts "Moving backup: #{self.backup_key_file_path}" if $-d FileUtils.mv(backup_key_file_path, self.key_file_path) end |
#remove_existing_file ⇒ Object
38 39 40 41 |
# File 'lib/pair/session/authorized_keys_file.rb', line 38 def remove_existing_file puts "Removing authorized_keys: #{self.key_file_path}" if $-d FileUtils.rm(self.key_file_path) end |