Class: ProxyAPI::Openscap
- Inherits:
-
Resource
- Object
- Resource
- ProxyAPI::Openscap
- Defined in:
- app/lib/proxy_api/openscap.rb
Constant Summary collapse
- HTTP_ERRORS =
[ EOFError, Errno::ECONNRESET, Errno::EINVAL, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Timeout::Error, ProxyAPI::ProxyException ].freeze
Instance Method Summary collapse
- #arf_report_bzip(report, cname) ⇒ Object
- #arf_report_html(report, cname) ⇒ Object
- #destroy_report(report, cname) ⇒ Object
- #fetch_policies_for_scap_content(scap_file) ⇒ Object
- #fetch_profiles_for_tailoring_file(scap_file) ⇒ Object
-
#initialize(args) ⇒ Openscap
constructor
A new instance of Openscap.
- #policy_html_guide(scap_file, policy) ⇒ Object
- #spool_status ⇒ Object
- #validate_scap_file(scap_file, type) ⇒ Object
Constructor Details
#initialize(args) ⇒ Openscap
Returns a new instance of Openscap.
14 15 16 17 18 19 |
# File 'app/lib/proxy_api/openscap.rb', line 14 def initialize(args) @url = args[:url] + '/compliance/' super args @connect_params[:headers][:content_type] = :xml @connect_params[:timeout] = timeout end |
Instance Method Details
#arf_report_bzip(report, cname) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/lib/proxy_api/openscap.rb', line 55 def arf_report_bzip(report, cname) begin @connect_params[:headers] = { :content_type => 'application/arf-bzip2', :content_encoding => 'x-bzip2' } get "/arf/#{report.id}/#{cname}/#{report.reported_at.to_i}/#{report.policy_arf_report.digest}/xml" rescue => e raise ::ProxyAPI::ProxyException.new(url, e, N_("Unable to get XML version of requested report from Smart Proxy")) end end |
#arf_report_html(report, cname) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/lib/proxy_api/openscap.rb', line 46 def arf_report_html(report, cname) begin @connect_params[:headers] = { :accept => 'application/html' } get "/arf/#{report.id}/#{cname}/#{report.reported_at.to_i}/#{report.policy_arf_report.digest}/html" rescue => e raise ::ProxyAPI::ProxyException.new(url, e, N_("Unable to get HTML version of requested report from Smart Proxy")) end end |
#destroy_report(report, cname) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'app/lib/proxy_api/openscap.rb', line 64 def destroy_report(report, cname) begin parse(delete("arf/#{report.id}/#{cname}/#{report.reported_at.to_i}/#{report.policy_arf_report.digest}")) rescue => e msg = "Failed to destroy arf report with id #{report.id} on Smart Proxy, cause: #{e.}" logger.error msg report.errors.add(:base, msg) false end end |
#fetch_policies_for_scap_content(scap_file) ⇒ Object
21 22 23 |
# File 'app/lib/proxy_api/openscap.rb', line 21 def fetch_policies_for_scap_content(scap_file) parse(post(scap_file, "scap_content/policies")) end |
#fetch_profiles_for_tailoring_file(scap_file) ⇒ Object
25 26 27 |
# File 'app/lib/proxy_api/openscap.rb', line 25 def fetch_profiles_for_tailoring_file(scap_file) parse(post(scap_file, "tailoring_file/profiles")) end |
#policy_html_guide(scap_file, policy) ⇒ Object
41 42 43 44 |
# File 'app/lib/proxy_api/openscap.rb', line 41 def policy_html_guide(scap_file, policy) guide = parse(post(scap_file, "scap_content/guide/#{policy}")) guide['html'] end |
#spool_status ⇒ Object
75 76 77 78 79 80 81 |
# File 'app/lib/proxy_api/openscap.rb', line 75 def spool_status parse(get('spool_errors')) rescue => e msg = "Failed to get spool status from proxy, cause: #{e.}" logger.error msg {} end |
#validate_scap_file(scap_file, type) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/lib/proxy_api/openscap.rb', line 29 def validate_scap_file(scap_file, type) parse(post(scap_file, "scap_file/validator/#{type}")) rescue RestClient::RequestTimeout => e raise ::ProxyAPI::ProxyException.new(url, e, N_("Request timed out. Please try increasing Settings -> proxy_request_timeout")) rescue RestClient::ResourceNotFound => e raise ::ProxyAPI::ProxyException.new(url, e, N_("Could not validate %s. Please make sure you have appropriate proxy version to use this functionality") % type.humanize) rescue => e raise ::ProxyAPI::ProxyException.new(url, e, N_("Could not validate %{file_type}. Error %{error}") % { :file_type => type.humanize, :error => e. }) end |