Class: Cabal::SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/cabal/ssh.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, ssh_signature, client) ⇒ SSH

Returns a new instance of SSH.



14
15
16
17
18
19
# File 'lib/cabal/ssh.rb', line 14

def initialize(cluster, ssh_signature, client)
  @cluster = cluster
  @ssh_signature = ssh_signature
  @client = client
  @key_file = Tempfile.new(SecureRandom.hex(8))
end

Class Method Details

.connect(cluster, ssh_signature, client) ⇒ Object



10
11
12
# File 'lib/cabal/ssh.rb', line 10

def self.connect(cluster, ssh_signature, client)
  new(cluster, ssh_signature, client).connect
end

Instance Method Details

#connectObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cabal/ssh.rb', line 21

def connect
  private_key = client.private_key(cluster)
  @key_file = Tempfile.new(SecureRandom.hex(8))
  key_file.write(private_key)
  key_file.close

  begin
    FileUtils.chmod(0700, key_file.path)
    Kernel.system("ssh-add #{key_file.path} > /dev/null 2>&1")
    Kernel.system("ssh -A #{ssh_signature}")
  ensure
    Kernel.system("ssh-add -D > /dev/null 2>&1")
    key_file.unlink
  end
end