From 65b0f79c32aa501511b6caabd67351281f11e7b7 Mon Sep 17 00:00:00 2001 From: Robert Cheramy Date: Wed, 21 Feb 2024 09:21:36 +0100 Subject: [PATCH] Fix RuboCop warnings introduced by PR #3047 --- lib/oxidized/input/http.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/oxidized/input/http.rb b/lib/oxidized/input/http.rb index ca9a4b5f0..fb9dd7291 100644 --- a/lib/oxidized/input/http.rb +++ b/lib/oxidized/input/http.rb @@ -49,29 +49,29 @@ def cmd_str(string) def get_http(path) schema = @secure ? "https://" : "http://" uri = URI("#{schema}#{@node.ip}#{path}") - + Oxidized.logger.debug "Making request to: #{uri}" - + ssl_verify = Oxidized.config.input.http.ssl_verify? ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE - + res = make_request(uri, ssl_verify) - + if res.code == '401' && res['www-authenticate']&.include?('Digest') uri.user = @username uri.password = @password Oxidized.logger.debug "Server requires Digest authentication" auth = Net::HTTP::DigestAuth.new.auth_header(uri, res['www-authenticate'], 'GET') - + res = make_request(uri, ssl_verify, 'Authorization' => auth) elsif @username && @password Oxidized.logger.debug "Falling back to Basic authentication" res = make_request(uri, ssl_verify, 'Authorization' => basic_auth_header) end - + Oxidized.logger.debug "Response code: #{res.code}" res.body end - + def make_request(uri, ssl_verify, extra_headers = {}) Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https", verify_mode: ssl_verify) do |http| req = Net::HTTP::Get.new(uri) @@ -80,7 +80,7 @@ def make_request(uri, ssl_verify, extra_headers = {}) http.request(req) end end - + def basic_auth_header "Basic " + ["#{@username}:#{@password}"].pack('m').delete("\r\n") end