Class: Vinz::Clortho::SSHSetup
- Inherits:
-
Object
- Object
- Vinz::Clortho::SSHSetup
- Defined in:
- lib/vinz/clortho/ssh_setup.rb
Instance Attribute Summary collapse
-
#key_expiry ⇒ Object
readonly
Returns the value of attribute key_expiry.
Instance Method Summary collapse
-
#initialize ⇒ SSHSetup
constructor
A new instance of SSHSetup.
- #login(initials = nil) ⇒ Object
- #login_all(key_ttl = nil) ⇒ Object
- #ssh_add(key_ttl, key_path) ⇒ Object
- #usage_msg ⇒ Object
Constructor Details
#initialize ⇒ SSHSetup
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_expiry ⇒ Object (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 login(initials = nil) set_key_expiry key_ttl = @key_expiry.to_i - Time.now.to_i if initials.nil? login_all 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 login_all(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_msg ⇒ Object
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" |