Skip to content

Commit

Permalink
Merge pull request #3079 from robertcheramy/fix-rubocop-warnings-PR3047
Browse files Browse the repository at this point in the history
Fix RuboCop warnings introduced by PR #3047
  • Loading branch information
robertcheramy authored Feb 21, 2024
2 parents a02255a + 65b0f79 commit 1694ff3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/oxidized/input/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 1694ff3

Please sign in to comment.