Class: Vinz::Clortho::SSHSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/vinz/clortho/ssh_setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSSHSetup



6
7
8
# File 'lib/vinz/clortho/ssh_setup.rb', line 6

def initialize
  @ssh_key_path_mgr = SSHKeyPathManager.new
end

Instance Attribute Details

#key_expiryObject (readonly)

Returns the value of attribute key_expiry.



4
5
6
# File 'lib/vinz/clortho/ssh_setup.rb', line 4

def key_expiry
  @key_expiry
end

Instance Method Details

#login(initials = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vinz/clortho/ssh_setup.rb', line 10

def (initials = nil)
  set_key_expiry
  key_ttl = @key_expiry.to_i - Time.now.to_i
  if initials.nil?
     key_ttl
  else
    key_path = @ssh_key_path_mgr.key_path_for initials
    raise Errno::ENOENT.new unless File.exist? key_path
    ssh_add(key_ttl, key_path)
  end
end

#login_all(key_ttl = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vinz/clortho/ssh_setup.rb', line 22

def (key_ttl = nil)
  if key_ttl.nil?
    set_key_expiry
    key_ttl = @key_expiry.to_i - Time.now.to_i
  end

  @ssh_key_path_mgr.key_paths.each do |key_path|
    path = key_path.path
    ssh_add(key_ttl, path) if File.exist?(path)
  end
end

#ssh_add(key_ttl, key_path) ⇒ Object



34
35
36
# File 'lib/vinz/clortho/ssh_setup.rb', line 34

def ssh_add(key_ttl, key_path)
  `ssh-add -t #{key_ttl} #{key_path}`
end

#usage_msgObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vinz/clortho/ssh_setup.rb', line 38

def usage_msg
  committers_and_keypaths = @ssh_key_path_mgr.key_paths.map do |key_path|
    "\t#{key_path.initials} : #{key_path.path}"
  end
  msg = "Usage: git ssh-login [options] [committer-initials]\n\nknown committers:\n\#{committers_and_keypaths.join(\"\\n\")}\n\nIf there is no mapping from your initials to your keypath, add it to .git-authors.\n  MSG\nend\n"