Class: Tomo::SSH::ConnectionValidator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tomo/ssh/connection_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(executable, connection) ⇒ ConnectionValidator

Returns a new instance of ConnectionValidator.



13
14
15
16
# File 'lib/tomo/ssh/connection_validator.rb', line 13

def initialize(executable, connection)
  @executable = executable
  @connection = connection
end

Instance Method Details

#assert_valid_connection!Object



31
32
33
34
35
36
# File 'lib/tomo/ssh/connection_validator.rb', line 31

def assert_valid_connection!
  script = Script.new("echo hi", silent: !Tomo.debug?, echo: false, raise_on_error: false)
  res = connection.ssh_subprocess(script, verbose: Tomo.debug?)
  raise_connection_failure(res) if res.exit_status == 255
  raise_unknown_error(res) if res.failure? || res.stdout.chomp != "hi"
end

#assert_valid_executable!Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tomo/ssh/connection_validator.rb', line 18

def assert_valid_executable!
  result = begin
    ChildProcess.execute(executable, "-V")
  rescue StandardError => e
    handle_bad_executable(e)
  end

  Tomo.logger.debug(result.output)
  return if result.success? && supported?(result.output)

  raise_unsupported_version(result.output)
end

#dump_envObject



38
39
40
41
42
# File 'lib/tomo/ssh/connection_validator.rb', line 38

def dump_env
  script = Script.new("env", silent: true, echo: false)
  res = connection.ssh_subprocess(script)
  Tomo.logger.debug("#{host} environment:\n#{res.stdout.strip}")
end