Sha256: ddb509b4d7ad75ef68fdb6ecdbef7e0d59430ab54d75e3fd075984fea7431b5d
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 KB
Contents
module Proxy::OpenSCAP class ForemanForwarder < Proxy::HttpRequest::ForemanRequest include ::Proxy::Log def post_arf_report(cname, policy_id, date, data) parser = Proxy::OpenSCAP::Parse.new(data) begin foreman_api_path = upload_path(cname, policy_id, date) response = send_request(foreman_api_path, parser.as_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 OpenSCAP::OpenSCAPError => e logger.debug e.backtrace.join("\n\t") raise e rescue StandardError => e logger.debug response.body if response logger.debug e.backtrace.join("\n\t") raise e ensure parser.cleanup 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
smart_proxy_openscap-0.6.4 | lib/smart_proxy_openscap/foreman_forwarder.rb |
smart_proxy_openscap-0.6.3 | lib/smart_proxy_openscap/foreman_forwarder.rb |