Sha256: bdec0cd7aa444f3af48ad12c74f9f4557260cdb9bbe15ca8aa0f52aefa6d1faf
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
module Proxy::OpenSCAP class ForemanForwarder < Proxy::HttpRequest::ForemanRequest include ::Proxy::Log def post_arf_report(cname, policy_id, date, data) begin foreman_api_path = upload_path(cname, policy_id, date) json = Proxy::OpenSCAP::Parse.new(cname, policy_id, date).as_json(data) raise OpenSCAP::OpenSCAPError, "Failed to parse report" if json.nil? || json.empty? response = send_request(foreman_api_path, json) # Raise an HTTP error if the response is not 2xx (success). response.value res = JSON.parse(response.body) raise StandardError, "Received response: #{response.code} #{response.msg}" unless res['result'] == 'OK' rescue StandardError => e logger.debug response.body if response logger.debug e.backtrace.join("\n\t") raise e end res end private def upload_path(cname, policy_id, date) "/api/v2/compliance/arf_reports/#{cname}/#{policy_id}/#{date}" end def send_request(path, body) # Override the parent method to set the right headers path = [uri.path, path].join('/') unless uri.path.empty? req = Net::HTTP::Post.new(URI.join(uri.to_s, path).path) req.add_field('Accept', 'application/json,version=2') req.content_type = 'application/json' req.body = body http.request(req) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
smart_proxy_openscap-0.6.5 | lib/smart_proxy_openscap/foreman_forwarder.rb |