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

Returns a new instance of SSHSetup.



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

def initialize
  @git_authors_mgr = GitAuthorsManager.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) ⇒ Object

Raises:

  • (Errno::ENOENT)


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

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

#login_all(key_ttl = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/vinz/clortho/ssh_setup.rb', line 18

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

  @git_authors_mgr.all_key_paths.values.each do |path|
    ssh_add(key_ttl, path) if File.exist?(path)
  end
end

#ssh_add(key_ttl, key_path) ⇒ Object



29
30
31
# File 'lib/vinz/clortho/ssh_setup.rb', line 29

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

#usage_msgObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vinz/clortho/ssh_setup.rb', line 33

def usage_msg
  committers_and_keypaths = @git_authors_mgr.all_key_paths.map do |committer_initials, keypath|
    "\t#{committer_initials} : #{keypath}"
  end
  msg = <<-MSG
Usage: git ssh-login [options] (committer-initials)

known committers:
#{committers_and_keypaths.join("\n")}

If there is no mapping from your initials to your keypath, add it to .git-authors.
  MSG
end