Class: ProxyAPI::Openscap

Inherits:
Resource
  • Object
show all
Defined in:
app/lib/proxy_api/openscap.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Openscap

Returns a new instance of Openscap.



3
4
5
6
7
8
# File 'app/lib/proxy_api/openscap.rb', line 3

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



44
45
46
47
48
49
50
51
# File 'app/lib/proxy_api/openscap.rb', line 44

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



35
36
37
38
39
40
41
42
# File 'app/lib/proxy_api/openscap.rb', line 35

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



53
54
55
56
57
58
59
60
61
62
# File 'app/lib/proxy_api/openscap.rb', line 53

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.message}"
    logger.error msg
    report.errors.add(:base, msg)
    false
  end
end

#fetch_policies_for_scap_content(scap_file) ⇒ Object



10
11
12
# File 'app/lib/proxy_api/openscap.rb', line 10

def fetch_policies_for_scap_content(scap_file)
  parse(post(scap_file, "scap_content/policies"))
end

#fetch_profiles_for_tailoring_file(scap_file) ⇒ Object



14
15
16
# File 'app/lib/proxy_api/openscap.rb', line 14

def fetch_profiles_for_tailoring_file(scap_file)
  parse(post(scap_file, "tailoring_file/profiles"))
end

#policy_html_guide(scap_file, policy) ⇒ Object



30
31
32
33
# File 'app/lib/proxy_api/openscap.rb', line 30

def policy_html_guide(scap_file, policy)
  guide = parse(post(scap_file, "scap_content/guide/#{policy}"))
  guide['html']
end

#spool_statusObject



64
65
66
67
68
69
70
# File 'app/lib/proxy_api/openscap.rb', line 64

def spool_status
  parse(get('spool_errors'))
rescue => e
  msg = "Failed to get spool status from proxy, cause: #{e.message}"
  logger.error msg
  {}
end

#validate_scap_file(scap_file, type) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'app/lib/proxy_api/openscap.rb', line 18

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.message })
end