Class: Tomo::SSH::Options

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

Constant Summary collapse

DEFAULTS =
{
  ssh_connect_timeout: 5,
  ssh_executable: "ssh",
  ssh_extra_opts: %w[-o PasswordAuthentication=no].map(&:freeze),
  ssh_forward_agent: true,
  ssh_reuse_connections: true,
  ssh_strict_host_key_checking: "accept-new"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Options

Returns a new instance of Options.



17
18
19
20
21
22
23
# File 'lib/tomo/ssh/options.rb', line 17

def initialize(options)
  DEFAULTS.merge(options).each do |attr, value|
    unprefixed_attr = attr.to_s.sub(/^ssh_/, "")
    send(:"#{unprefixed_attr}=", value)
  end
  freeze
end

Instance Attribute Details

#executableObject

Returns the value of attribute executable.



15
16
17
# File 'lib/tomo/ssh/options.rb', line 15

def executable
  @executable
end

Instance Method Details

#build_args(host, script, control_path, verbose) ⇒ Object

rubocop:disable Metrics/AbcSize



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tomo/ssh/options.rb', line 25

def build_args(host, script, control_path, verbose) # rubocop:disable Metrics/AbcSize
  args = [verbose ? "-v" : ["-o", "LogLevel=ERROR"]]
  args << "-A" if forward_agent
  args << connect_timeout_option
  args << strict_host_key_checking_option
  args.push(*control_opts(control_path, verbose)) if reuse_connections
  args.push(*extra_opts) if extra_opts
  args << "-tt" if script.pty?
  args << host.to_ssh_args
  args << "--"

  [executable, args, script.to_s].flatten
end