Class: Pair::Session::AuthorizedKeysFile
- Inherits:
-
Object
- Object
- Pair::Session::AuthorizedKeysFile
- Defined in:
- lib/pair/session/authorized_keys_file.rb
Overview
TODO replace with authorized_keys gem
Constant Summary collapse
- ACCESS_TYPE =
"type"
- KEYS =
"keys"
Instance Attribute Summary collapse
-
#attach_command ⇒ Object
Returns the value of attribute attach_command.
-
#key_file_path ⇒ Object
Returns the value of attribute key_file_path.
-
#member_keys ⇒ Object
Returns the value of attribute member_keys.
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, attach_command) ⇒ AuthorizedKeysFile
constructor
A new instance of AuthorizedKeysFile.
- #install ⇒ Object
- #key_file_exists? ⇒ Boolean
- #move_backup_file ⇒ Object
- #remove_existing_file ⇒ Object
Constructor Details
#initialize(member_keys, attach_command) ⇒ AuthorizedKeysFile
Returns a new instance of AuthorizedKeysFile.
12 13 14 15 16 |
# File 'lib/pair/session/authorized_keys_file.rb', line 12 def initialize(member_keys, attach_command) self.member_keys = member_keys || {} self.attach_command = attach_command self.key_file_path = File.("~/.ssh/authorized_keys") end |
Instance Attribute Details
#attach_command ⇒ Object
Returns the value of attribute attach_command.
9 10 11 |
# File 'lib/pair/session/authorized_keys_file.rb', line 9 def attach_command @attach_command end |
#key_file_path ⇒ Object
Returns the value of attribute key_file_path.
10 11 12 |
# File 'lib/pair/session/authorized_keys_file.rb', line 10 def key_file_path @key_file_path end |
#member_keys ⇒ Object
Returns the value of attribute member_keys.
8 9 10 |
# File 'lib/pair/session/authorized_keys_file.rb', line 8 def member_keys @member_keys end |
Instance Method Details
#backup_authorized_keys ⇒ Object
34 35 36 37 |
# File 'lib/pair/session/authorized_keys_file.rb', line 34 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
53 54 55 |
# File 'lib/pair/session/authorized_keys_file.rb', line 53 def backup_key_file_exists? File.exists? backup_key_file_path end |
#backup_key_file_path ⇒ Object
57 58 59 |
# File 'lib/pair/session/authorized_keys_file.rb', line 57 def backup_key_file_path "#{self.key_file_path}.pair" end |
#cleanup ⇒ Object
25 26 27 |
# File 'lib/pair/session/authorized_keys_file.rb', line 25 def cleanup end |
#cleanup_authorized_keys ⇒ Object
29 30 31 32 |
# File 'lib/pair/session/authorized_keys_file.rb', line 29 def remove_existing_file move_backup_file if backup_key_file_exists? end |
#install ⇒ Object
18 19 20 21 22 23 |
# File 'lib/pair/session/authorized_keys_file.rb', line 18 def install return if member_keys.empty? if key_file_exists? end |
#key_file_exists? ⇒ Boolean
49 50 51 |
# File 'lib/pair/session/authorized_keys_file.rb', line 49 def key_file_exists? File.exists? self.key_file_path end |
#move_backup_file ⇒ Object
44 45 46 47 |
# File 'lib/pair/session/authorized_keys_file.rb', line 44 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
39 40 41 42 |
# File 'lib/pair/session/authorized_keys_file.rb', line 39 def remove_existing_file puts "Removing authorized_keys: #{self.key_file_path}" if $-d FileUtils.rm(self.key_file_path) end |