diff options
author | ytti <saku@ytti.fi> | 2018-06-22 19:25:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-22 19:25:10 +0300 |
commit | 428708ef376884c3dc35aee1951cb8e1c55fac9f (patch) | |
tree | 8e209bdceb34385373f11796178b8706ba7e55c9 /lib/oxidized/input/ssh.rb | |
parent | f0947761b46e4ee6cdadd866b1cf3cf25bdfeedd (diff) |
Refactor smells
* reduce no/resolve_repo smell
* reduce input/ssh/connect smell
* reduce source/http load smell
* reduce node/worker smell
* reduce source/csv smell
* reduce output/http smell
Get's code climate from B to A, so I'm sure it's super duper important.
Diffstat (limited to 'lib/oxidized/input/ssh.rb')
-rw-r--r-- | lib/oxidized/input/ssh.rb | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index d321a11..82335f9 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -21,36 +21,10 @@ module Oxidized @output = '' @pty_options = { term: "vt100" } @node.model.cfg['ssh'].each { |cb| instance_exec(&cb) } - secure = Oxidized.config.input.ssh.secure @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug? - port = vars(:ssh_port) || 22 - - ssh_opts = { - port: port.to_i, - paranoid: secure, - keepalive: true, - password: @node.auth[:password], :timeout => Oxidized.config.timeout, - number_of_password_prompts: 0, - } - - auth_methods = vars(:auth_methods) || %w(none publickey password) - ssh_opts[:auth_methods] = auth_methods - Oxidized.logger.debug "AUTH METHODS::#{auth_methods}" - - if proxy_host = vars(:ssh_proxy) - proxy_command = "ssh " - proxy_command += "-o StrictHostKeyChecking=no " unless secure - proxy_command += "#{proxy_host} -W %h:%p" - proxy = Net::SSH::Proxy::Command.new(proxy_command) - ssh_opts[:proxy] = proxy - end - - ssh_opts[:keys] = vars(:ssh_keys).is_a?(Array) ? vars(:ssh_keys) : [vars(:ssh_keys)] 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) Oxidized.logger.debug "lib/oxidized/input/ssh.rb: Connecting to #{@node.name}" - @ssh = Net::SSH.start(@node.ip, @node.auth[:username], ssh_opts) + @ssh = Net::SSH.start(@node.ip, @node.auth[:username], get_ssh_opts) unless @exec shell_open @ssh begin @@ -142,5 +116,34 @@ module Oxidized end end end + + def get_ssh_opts + ssh_opts = { + port: (vars(:ssh_port) || 22).to_i, + paranoid: secure, + keepalive: true, + password: @node.auth[:password], timeout: Oxidized.config.timeout, + number_of_password_prompts: 0 + } + + auth_methods = vars(:auth_methods) || %w(none publickey password) + ssh_opts[:auth_methods] = auth_methods + Oxidized.logger.debug "AUTH METHODS::#{auth_methods}" + + if proxy_host = vars(:ssh_proxy) + proxy_command = "ssh " + proxy_command += "-o StrictHostKeyChecking=no " unless Oxidized.config.input.ssh.secure? + proxy_command += "#{proxy_host} -W %h:%p" + proxy = Net::SSH::Proxy::Command.new(proxy_command) + ssh_opts[:proxy] = proxy + end + + 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[:verbose] = Logger::DEBUG if Oxidized.config.input.debug? + + ssh_opts + end end end |