Skip to content

Commit

Permalink
Move ssh proxy command generation
Browse files Browse the repository at this point in the history
Reduces Cyclomatic and Percieved complexity

Signed-off-by: Mike Beattie <mike@ethernal.org>
  • Loading branch information
mjbnz committed Feb 19, 2022
1 parent 48735e2 commit c97c04d
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lib/oxidized/input/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,13 @@ def make_ssh_opts
ssh_opts[:auth_methods] = auth_methods
Oxidized.logger.debug "AUTH METHODS::#{auth_methods}"

proxy_host = vars(:ssh_proxy)
if defined?(proxy_host) && !proxy_host.nil? && !proxy_host.empty?
proxy_command = "ssh "
proxy_command += "-o StrictHostKeyChecking=no " unless secure
if (proxy_port = vars(:ssh_proxy_port))
proxy_command += "-p #{proxy_port} "
end
proxy_command += "#{proxy_host} -W [%h]:%p"
proxy = Net::SSH::Proxy::Command.new(proxy_command)
ssh_opts[:proxy] = proxy
end
ssh_opts[:proxy] = make_ssh_proxy_command(vars(:ssh_proxy), vars(:ssh_proxy_port), secure) if vars(:ssh_proxy)

ssh_opts[:keys] = [vars(:ssh_keys)].flatten if vars(:ssh_keys)
ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
ssh_opts[:keys] = [vars(:ssh_keys)].flatten if vars(:ssh_keys)
ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
ssh_opts[:encryption] = vars(:ssh_encryption).split(/,\s*/) if vars(:ssh_encryption)
ssh_opts[:host_key] = vars(:ssh_host_key).split(/,\s*/) if vars(:ssh_host_key)
ssh_opts[:hmac] = vars(:ssh_hmac).split(/,\s*/) if vars(:ssh_hmac)
ssh_opts[:host_key] = vars(:ssh_host_key).split(/,\s*/) if vars(:ssh_host_key)
ssh_opts[:hmac] = vars(:ssh_hmac).split(/,\s*/) if vars(:ssh_hmac)

if Oxidized.config.input.debug?
ssh_opts[:logger] = Oxidized.logger
Expand All @@ -159,5 +149,16 @@ def make_ssh_opts

ssh_opts
end

def make_ssh_proxy_command(proxy_host, proxy_port, secure)
return nil unless !proxy_host.nil? && !proxy_host.empty?

proxy_command = "ssh "
proxy_command += "-o StrictHostKeyChecking=no " unless secure
proxy_command += "-p #{proxy_port} " if proxy_port
proxy_command += "#{proxy_host} -W [%h]:%p"
proxy = Net::SSH::Proxy::Command.new(proxy_command)
proxy
end
end
end

0 comments on commit c97c04d

Please sign in to comment.