Class: Pair::Session::AuthorizedKeysFile

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.expand_path("~/.ssh/authorized_keys")
end

Instance Attribute Details

#attach_commandObject

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_pathObject

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_keysObject

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_keysObject



34
35
36
37
# File 'lib/pair/session/authorized_keys_file.rb', line 34

def backup_authorized_keys
  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

Returns:

  • (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_pathObject



57
58
59
# File 'lib/pair/session/authorized_keys_file.rb', line 57

def backup_key_file_path
  "#{self.key_file_path}.pair"
end

#cleanupObject



25
26
27
# File 'lib/pair/session/authorized_keys_file.rb', line 25

def cleanup
  cleanup_authorized_keys
end

#cleanup_authorized_keysObject



29
30
31
32
# File 'lib/pair/session/authorized_keys_file.rb', line 29

def cleanup_authorized_keys
  remove_existing_file
  move_backup_file if backup_key_file_exists?
end

#installObject



18
19
20
21
22
23
# File 'lib/pair/session/authorized_keys_file.rb', line 18

def install
  return if member_keys.empty?

  backup_authorized_keys if key_file_exists?
  create_authorized_keys
end

#key_file_exists?Boolean

Returns:

  • (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_fileObject



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_fileObject



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