Class: Cabal::SSH

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

Overview

Generates SSH sessions for remote server interaction

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cluster, ssh_signature, client, identity_timeout, kernel) ⇒ SSH

Returns a new instance of SSH.



35
36
37
38
39
40
41
# File 'lib/cabal/ssh.rb', line 35

def initialize(cluster, ssh_signature, client, identity_timeout, kernel)
  @cluster = cluster
  @ssh_signature = ssh_signature
  @client = client
  @identity_timeout = identity_timeout
  @kernel = kernel
end

Class Method Details

.connect(options = {}) ⇒ nil

Create a new instance and use it to generate an SSH session

Parameters:

  • options (Hash) (defaults to: {})

    the options to pass along to the new instance

Options Hash (options):

  • :cluster (String)

    the name of the cluster key to use (required)

  • :ssh_signature (String)

    the user@hostname that would be passed if the normal ssh CLI utility were used (required)

  • :client (Cabal::Client)

    the instance of Cabal::Client to use for key retrieval (required)

  • :identity_timeout (Integer)

    the number of seconds that keys should be forwarded in the resulting SSH session (optional)

  • :kernel (Kernel)

    the Kernel-compliant object used for issuing calls to #system for the SSH session (optional)

Returns:

  • (nil)


25
26
27
28
29
30
31
32
33
# File 'lib/cabal/ssh.rb', line 25

def self.connect(options = {})
  new(
    options[:cluster],
    options[:ssh_signature],
    options[:client],
    options[:identity_timeout] || 1800,
    options[:kernel] || Kernel
  ).connect
end

Instance Method Details

#connectnil

Initiate an SSH connection in the current terminal

Returns:

  • (nil)


53
54
55
56
57
58
59
60
# File 'lib/cabal/ssh.rb', line 53

def connect
  begin
    write_private_key
    initiate_connection
  ensure
    terminate_connection
  end
end

#lifetimeString

The lifetime option that would be passed to ssh-add for this session

Returns:

  • (String)

    the empty string for immortal sessions, “-t identity_timeout” for sessions with a defined lifetime



46
47
48
49
# File 'lib/cabal/ssh.rb', line 46

def lifetime
  return '' if identity_timeout == 0
  "-t #{identity_timeout}"
end