smart_proxy_openscap 0.7.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/bin/smart-proxy-openscap-send +5 -1
  4. data/lib/smart_proxy_openscap/arf_parser.rb +74 -17
  5. data/lib/smart_proxy_openscap/content_parser.rb +19 -25
  6. data/lib/smart_proxy_openscap/fetch_scap_file.rb +45 -0
  7. data/lib/smart_proxy_openscap/foreman_arf_forwarder.rb +15 -0
  8. data/lib/smart_proxy_openscap/foreman_forwarder.rb +19 -16
  9. data/lib/smart_proxy_openscap/foreman_oval_forwarder.rb +19 -0
  10. data/lib/smart_proxy_openscap/openscap_api.rb +59 -28
  11. data/lib/smart_proxy_openscap/openscap_exception.rb +1 -0
  12. data/lib/smart_proxy_openscap/openscap_html_generator.rb +1 -1
  13. data/lib/smart_proxy_openscap/openscap_import_api.rb +3 -3
  14. data/lib/smart_proxy_openscap/openscap_lib.rb +5 -3
  15. data/lib/smart_proxy_openscap/openscap_plugin.rb +2 -1
  16. data/lib/smart_proxy_openscap/oval_report_parser.rb +54 -0
  17. data/lib/smart_proxy_openscap/oval_report_storage_fs.rb +26 -0
  18. data/lib/smart_proxy_openscap/profiles_parser.rb +22 -23
  19. data/lib/smart_proxy_openscap/spool_forwarder.rb +4 -4
  20. data/lib/smart_proxy_openscap/storage.rb +0 -2
  21. data/lib/smart_proxy_openscap/storage_fs.rb +7 -4
  22. data/lib/smart_proxy_openscap/storage_fs_common.rb +42 -0
  23. data/lib/smart_proxy_openscap/version.rb +1 -1
  24. data/settings.d/openscap.yml.example +3 -0
  25. data/smart_proxy_openscap.gemspec +2 -0
  26. data/test/data/oval-results.xml.bz2 +0 -0
  27. data/test/data/rhel-7-including-unpatched.oval.xml.bz2 +0 -0
  28. data/test/fetch_oval_content_api_test.rb +38 -0
  29. data/test/fetch_scap_api_test.rb +1 -1
  30. data/test/oval_report_parser_test.rb +14 -0
  31. data/test/post_oval_report_api_test.rb +30 -0
  32. data/test/post_report_api_test.rb +2 -2
  33. data/test/scap_content_parser_api_test.rb +1 -1
  34. data/test/script_class_test.rb +0 -58
  35. metadata +29 -11
  36. data/bin/smart-proxy-arf-json +0 -7
  37. data/bin/smart-proxy-scap-profiles +0 -7
  38. data/bin/smart-proxy-scap-validation +0 -7
  39. data/lib/smart_proxy_openscap/arf_json.rb +0 -114
  40. data/lib/smart_proxy_openscap/fetch_scap_content.rb +0 -17
  41. data/lib/smart_proxy_openscap/fetch_tailoring_file.rb +0 -17
  42. data/lib/smart_proxy_openscap/scap_profiles.rb +0 -52
  43. data/lib/smart_proxy_openscap/scap_validation.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3ca973805c62a08862ac41ec711531af26d63da27cde44dde331aa4f407d371
4
- data.tar.gz: ec270baf1ad3fabebe31f231ae52446bcf2ca0caad6fc1fcca7b5174b82a07c7
3
+ metadata.gz: b4d1a52c4299cb9828c2cb492622a4cc13f9cd3d234fc6a9940dc9768840761b
4
+ data.tar.gz: bfa0d9e1444579127bec7bf5f32fe37d73577c99ab803dfd07b59c0ed6f1e15a
5
5
  SHA512:
6
- metadata.gz: d323a7623a4ecfefb4dbb255e578199abcfa0204b52c073f4400cdfdbe039ced7caab5eba20d420eba266d6e0857b5a7e631046a40849d29240175966263c20c
7
- data.tar.gz: 15bc8b4a4960196256b2f176ee59fa63424e45f917fd8d8e66a484bb6eefac6ab43ce7620e30d79ac7853303fea90b3878f160f728c98433c0e132609bf06efc
6
+ metadata.gz: 49c8ece151fb60cdf31a3c396b22df455d3f653648640f5e6d05505c67c386128bf09970bd9d08b82e94710d493c3ba8dd003d47d584e05819204cd32987ffc3
7
+ data.tar.gz: 18acfdafceecc4845da3fce3703f7e670d0c991ddda0d6cb542c00ccb6d399cd4090b63cf44dbeb2fef5aa99cfa0fb7710a2a54cf5b6d4b1678f98b70d01678b
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gemspec
4
4
  group :development do
5
5
  gem 'test-unit'
6
6
  gem 'pry'
7
+ gem 'pry-byebug'
7
8
  gem 'rubocop'
8
9
  gem 'rack', '~> 1.6.8' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
9
10
  gem 'smart_proxy', :github => "theforeman/smart-proxy", :branch => 'develop'
@@ -1,3 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
- scl enable tfm smart-proxy-openscap-send-inner
3
+ if command -v scl &>/dev/null;then
4
+ scl enable tfm smart-proxy-openscap-send-inner
5
+ else
6
+ smart-proxy-openscap-send-inner
7
+ fi
@@ -1,38 +1,95 @@
1
- require 'smart_proxy_openscap/shell_wrapper'
1
+ require 'openscap_parser/test_result_file'
2
+ require 'smart_proxy_openscap/openscap_exception'
2
3
 
3
4
  module Proxy
4
5
  module OpenSCAP
5
- class ArfParser < ShellWrapper
6
+ class ArfParser
7
+ include Proxy::Log
6
8
 
7
9
  def initialize(cname, policy_id, date)
8
10
  @cname = cname
9
11
  @policy_id = policy_id
10
12
  @date = date
11
- @script_name = 'smart-proxy-arf-json'
12
13
  end
13
14
 
14
15
  def as_json(arf_data)
15
- execute_shell_command arf_data
16
- end
16
+ begin
17
+ file = Tempfile.new
18
+ file.write(arf_data)
19
+ file.rewind
20
+ decompressed = `bunzip2 -dc #{file.path}`
21
+ rescue => e
22
+ logger.error e
23
+ raise Proxy::OpenSCAP::ReportDecompressError, "Failed to decompress received report bzip, cause: #{e.message}"
24
+ ensure
25
+ file.close
26
+ file.unlink
27
+ end
28
+ arf_file = ::OpenscapParser::TestResultFile.new(decompressed)
29
+ rules = arf_file.benchmark.rules.reduce({}) do |memo, rule|
30
+ memo[rule.id] = rule
31
+ memo
32
+ end
17
33
 
18
- def in_filename
19
- "#{super}-#{@cname}-#{@policy_id}-#{@date}-"
34
+ arf_digest = Digest::SHA256.hexdigest(arf_data)
35
+ report = parse_results(rules, arf_file.test_result, arf_digest)
36
+ report[:openscap_proxy_name] = Proxy::OpenSCAP::Plugin.settings.registered_proxy_name
37
+ report[:openscap_proxy_url] = Proxy::OpenSCAP::Plugin.settings.registered_proxy_url
38
+ report.to_json
20
39
  end
21
40
 
22
- def out_filename
23
- "#{in_filename}json-"
41
+ private
42
+
43
+ def parse_results(rules, test_result, arf_digest)
44
+ results = test_result.rule_results
45
+ set_values = test_result.set_values
46
+ report = {}
47
+ report[:logs] = []
48
+ passed = 0
49
+ failed = 0
50
+ othered = 0
51
+ results.each do |result|
52
+ next if result.result == 'notapplicable' || result.result == 'notselected'
53
+ # get rules and their results
54
+ rule_data = rules[result.id]
55
+ report[:logs] << populate_result_data(result.id, result.result, rule_data, set_values)
56
+ # create metrics for the results
57
+ case result.result
58
+ when 'pass', 'fixed'
59
+ passed += 1
60
+ when 'fail'
61
+ failed += 1
62
+ else
63
+ othered += 1
64
+ end
65
+ end
66
+ report[:digest] = arf_digest
67
+ report[:metrics] = { :passed => passed, :failed => failed, :othered => othered }
68
+ report[:score] = test_result.score
69
+ report
24
70
  end
25
71
 
26
- def failure_message
27
- "Failure when running script which parses reports"
72
+ def populate_result_data(result_id, rule_result, rule_data, set_values)
73
+ log = {}
74
+ log[:source] = result_id
75
+ log[:result] = rule_result
76
+ log[:title] = rule_data.title
77
+ log[:description] = rule_data.description
78
+ log[:rationale] = rule_data.rationale
79
+ log[:references] = rule_data.references.map { |ref| { :href => ref.href, :title => ref.label }}
80
+ log[:fixes] = populate_fixes rule_data.fixes, set_values
81
+ log[:severity] = rule_data.severity
82
+ log
28
83
  end
29
84
 
30
- def command(in_file, out_file)
31
- "#{script_location} " <<
32
- "#{in_file.path} " <<
33
- "#{out_file.path} " <<
34
- "#{Proxy::OpenSCAP::Plugin.settings.registered_proxy_name} " <<
35
- "#{Proxy::OpenSCAP::Plugin.settings.registered_proxy_url}"
85
+ def populate_fixes(fixes, set_values)
86
+ fixes.map do |fix|
87
+ {
88
+ :id => fix.id,
89
+ :system => fix.system,
90
+ :full_text => fix.full_text(set_values)
91
+ }
92
+ end
36
93
  end
37
94
  end
38
95
  end
@@ -1,30 +1,24 @@
1
- require 'smart_proxy_openscap/shell_wrapper'
1
+ require 'openscap_parser/datastream_file'
2
+ require 'openscap_parser/tailoring_file'
2
3
 
3
4
  module Proxy::OpenSCAP
4
- class ContentParser < ShellWrapper
5
- def initialize(type)
6
- @type = type
7
- @script_name = 'smart-proxy-scap-validation'
8
- end
9
-
10
- def validate(scap_file)
11
- execute_shell_command scap_file
12
- end
13
-
14
- def out_filename
15
- "#{in_filename}json-"
16
- end
17
-
18
- def in_filename
19
- "#{super}-#{@type}-validate-"
20
- end
21
-
22
- def failure_message
23
- "Failure when running script which validates scap files"
24
- end
25
-
26
- def command(in_file, out_file)
27
- "#{script_location} #{in_file.path} #{out_file.path} #{@type}"
5
+ class ContentParser
6
+ def validate(file_type, scap_file)
7
+ msg = 'Invalid SCAP file type'
8
+ errors = []
9
+ file = nil
10
+ begin
11
+ case file_type
12
+ when 'scap_content'
13
+ file = ::OpenscapParser::DatastreamFile.new(scap_file)
14
+ when 'tailoring_file'
15
+ file = ::OpenscapParser::TailoringFile.new(scap_file)
16
+ end
17
+ errors << msg unless file.valid?
18
+ rescue Nokogiri::XML::SyntaxError => e
19
+ errors << msg
20
+ end
21
+ { errors: errors }
28
22
  end
29
23
  end
30
24
  end
@@ -0,0 +1,45 @@
1
+ require 'smart_proxy_openscap/fetch_file'
2
+
3
+ module Proxy::OpenSCAP
4
+ class FetchScapFile < FetchFile
5
+ def initialize(type)
6
+ raise "Expected one of the following symbols: #{allowed_types.join(', ')}, got: #{type}" unless allowed_types.include? type
7
+ @type = type
8
+ end
9
+
10
+ def fetch(policy_id, digest, content_dir)
11
+ store_dir = File.join(Proxy::OpenSCAP.fullpath(content_dir), policy_id.to_s)
12
+ scap_file = File.join(store_dir, file_name(policy_id, digest))
13
+
14
+ file_download_path = download_path.sub(':policy_id', policy_id)
15
+ create_store_dir store_dir
16
+ file = policy_content_file scap_file
17
+ clean_store_folder store_dir unless file
18
+ file ||= save_or_serve_scap_file scap_file, file_download_path
19
+ end
20
+
21
+ def download_path
22
+ case @type
23
+ when :scap_content
24
+ "api/v2/compliance/policies/:policy_id/content"
25
+ when :tailoring_file
26
+ "api/v2/compliance/policies/:policy_id/tailoring"
27
+ when :oval_content
28
+ "api/v2/compliance/oval_policies/:policy_id/oval_content"
29
+ end
30
+ end
31
+
32
+ def file_name(policy_id, digest)
33
+ case @type
34
+ when :scap_content, :tailoring_file
35
+ "#{policy_id}_#{digest}.xml"
36
+ when :oval_content
37
+ "#{digest}.oval.xml.bz2"
38
+ end
39
+ end
40
+
41
+ def allowed_types
42
+ [:scap_content, :tailoring_file, :oval_content]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ require 'smart_proxy_openscap/foreman_forwarder'
2
+
3
+ module Proxy::OpenSCAP
4
+ class ForemanArfForwarder < ForemanForwarder
5
+ private
6
+
7
+ def parse_report(cname, policy_id, date, report_data)
8
+ Proxy::OpenSCAP::ArfParser.new(cname, policy_id, date).as_json(report_data)
9
+ end
10
+
11
+ def report_upload_path(cname, policy_id, date)
12
+ upload_path "arf_reports", cname, policy_id, date
13
+ end
14
+ end
15
+ end
@@ -4,26 +4,29 @@ module Proxy::OpenSCAP
4
4
  class ForemanForwarder < Proxy::HttpRequest::ForemanRequest
5
5
  include ::Proxy::Log
6
6
 
7
- def post_arf_report(cname, policy_id, date, data, timeout)
8
- begin
9
- foreman_api_path = upload_path(cname, policy_id, date)
10
- json = Proxy::OpenSCAP::ArfParser.new(cname, policy_id, date).as_json(data)
11
- response = send_request(foreman_api_path, json, timeout)
12
- # Raise an HTTP error if the response is not 2xx (success).
13
- response.value
14
- JSON.parse(response.body)
15
- rescue Net::HTTPServerException => e
16
- logger.debug "Received response: #{response.code} #{response.msg}"
17
- logger.debug response.body
18
- raise ReportUploadError, e.message if response.code.to_i == 422
19
- raise e
20
- end
7
+ def post_report(cname, policy_id, date, data, timeout)
8
+ foreman_api_path = report_upload_path(cname, policy_id, date)
9
+
10
+ json = parse_report(cname, policy_id, date, data)
11
+ response = send_request(foreman_api_path, json, timeout)
12
+ # Raise an HTTP error if the response is not 2xx (success).
13
+ response.value
14
+ JSON.parse(response.body)
15
+ rescue Net::HTTPServerException => e
16
+ logger.debug "Received response: #{response.code} #{response.msg}"
17
+ logger.debug response.body
18
+ raise ReportUploadError, e.message if response.code.to_i == 422
19
+ raise e
21
20
  end
22
21
 
23
22
  private
24
23
 
25
- def upload_path(cname, policy_id, date)
26
- "/api/v2/compliance/arf_reports/#{cname}/#{policy_id}/#{date}"
24
+ def upload_path(resource, cname, policy_id, date)
25
+ "/api/v2/compliance/#{resource}/#{cname}/#{policy_id}/#{date}"
26
+ end
27
+
28
+ def parse_report(cname, policy_id, date, data)
29
+ raise NotImplementedError
27
30
  end
28
31
 
29
32
  def send_request(path, body, timeout)
@@ -0,0 +1,19 @@
1
+ require 'smart_proxy_openscap/foreman_forwarder'
2
+
3
+ module Proxy::OpenSCAP
4
+ class ForemanOvalForwarder < ForemanForwarder
5
+ private
6
+
7
+ def parse_report(cname, policy_id, date, report_data)
8
+ {
9
+ :oval_results => OvalReportParser.new.parse_cves(report_data),
10
+ :oval_policy_id => policy_id,
11
+ :cname => cname
12
+ }.to_json
13
+ end
14
+
15
+ def report_upload_path(cname, policy_id, date)
16
+ upload_path "oval_reports", cname, policy_id, date
17
+ end
18
+ end
19
+ end
@@ -25,48 +25,73 @@ module Proxy::OpenSCAP
25
25
  include ::Proxy::Log
26
26
  helpers ::Proxy::Helpers
27
27
  authorize_with_ssl_client
28
+ CLIENT_PATHS = Regexp.compile(%r{^(/arf/\d+|/policies/\d+/content/|/policies/\d+/tailoring/)})
28
29
 
29
- post "/arf/:policy" do
30
- # first let's verify client's certificate
30
+ # authorize via trusted hosts but let client paths in without such authorization
31
+ before do
32
+ pass if request.path_info =~ CLIENT_PATHS
33
+ do_authorize_with_trusted_hosts
34
+ end
35
+
36
+ before '(/arf/*|/oval_reports/*)' do
31
37
  begin
32
- cn = Proxy::OpenSCAP::common_name request
38
+ @cn = Proxy::OpenSCAP::common_name request
33
39
  rescue Proxy::Error::Unauthorized => e
34
40
  log_halt 403, "Client authentication failed: #{e.message}"
35
41
  end
36
- date = Time.now.to_i
42
+ @reported_at = Time.now.to_i
43
+ end
44
+
45
+ post "/arf/:policy" do
37
46
  policy = params[:policy]
38
47
 
39
48
  begin
40
- post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string, Proxy::OpenSCAP::Plugin.settings.timeout)
41
- Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, cn, post_to_foreman['id'], date).store_archive(request.body.string)
49
+ post_to_foreman = ForemanArfForwarder.new.post_report(@cn, policy, @reported_at, request.body.string, Proxy::OpenSCAP::Plugin.settings.timeout)
50
+ Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, @cn, post_to_foreman['id'], @reported_at).store_archive(request.body.string)
42
51
  post_to_foreman.to_json
43
52
  rescue Proxy::OpenSCAP::StoreReportError => e
44
- Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, cn, post_to_foreman['id'], date).store_failed(request.body.string)
53
+ Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, @cn, post_to_foreman['id'], @reported_at).store_failed(request.body.string)
45
54
  logger.error "Failed to save Report in reports directory (#{Proxy::OpenSCAP::Plugin.settings.reportsdir}). Failed with: #{e.message}.
46
55
  Saving file in #{Proxy::OpenSCAP::Plugin.settings.failed_dir}. Please copy manually to #{Proxy::OpenSCAP::Plugin.settings.reportsdir}"
47
56
  { :result => 'Storage failure on proxy, see proxy logs for details' }.to_json
48
- rescue Proxy::OpenSCAP::OpenSCAPException => e
57
+ rescue Nokogiri::XML::SyntaxError => e
49
58
  error = "Failed to parse Arf Report, moving to #{Proxy::OpenSCAP::Plugin.settings.corrupted_dir}"
50
59
  logger.error error
51
- Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.corrupted_dir, cn, policy, date).store_corrupted(request.body.string)
60
+ Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.corrupted_dir, @cn, policy, @reported_at).store_corrupted(request.body.string)
52
61
  { :result => (error << ' on proxy') }.to_json
53
62
  rescue *HTTP_ERRORS => e
54
63
  ### If the upload to foreman fails then store it in the spooldir
55
64
  msg = "Failed to upload to Foreman, saving in spool. Failed with: #{e.message}"
56
65
  logger.error msg
57
- Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.spooldir, cn, policy, date).store_spool(request.body.string)
66
+ Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.spooldir, @cn, policy, @reported_at).store_spool(request.body.string)
58
67
  { :result => msg }.to_json
59
68
  rescue Proxy::OpenSCAP::StoreSpoolError => e
60
69
  log_halt 500, e.message
61
- rescue Proxy::OpenSCAP::ReportUploadError => e
70
+ rescue Proxy::OpenSCAP::ReportUploadError, Proxy::OpenSCAP::ReportDecompressError => e
62
71
  { :result => e.message }.to_json
63
72
  end
64
73
  end
65
74
 
75
+ post "/oval_reports/:oval_policy_id" do
76
+ ForemanOvalForwarder.new.post_report(@cn, params[:oval_policy_id], @reported_at, request.body.string, Plugin.settings.timeout)
77
+
78
+ { :reported_at => Time.at(@reported_at) }.to_json
79
+ rescue *HTTP_ERRORS => e
80
+ msg = "Failed to upload to Foreman, failed with: #{e.message}"
81
+ logger.error e
82
+ { :result => msg }.to_json
83
+ rescue Nokogiri::XML::SyntaxError => e
84
+ logger.error e
85
+ { :result => 'Failed to parse OVAL report, see proxy logs for details' }.to_json
86
+ rescue Proxy::OpenSCAP::ReportUploadError, Proxy::OpenSCAP::ReportDecompressError => e
87
+ { :result => e.message }.to_json
88
+ end
89
+
90
+
66
91
  get "/arf/:id/:cname/:date/:digest/xml" do
67
92
  content_type 'application/x-bzip2'
68
93
  begin
69
- Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).get_arf_xml(params[:digest])
94
+ Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).get_arf_xml(params[:digest])
70
95
  rescue FileNotFound => e
71
96
  log_halt 500, "Could not find requested file, #{e.message}"
72
97
  end
@@ -74,7 +99,7 @@ module Proxy::OpenSCAP
74
99
 
75
100
  delete "/arf/:id/:cname/:date/:digest" do
76
101
  begin
77
- Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).delete_arf_file
102
+ Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).delete_arf_file
78
103
  rescue FileNotFound => e
79
104
  logger.debug "Could not find requested file, #{e.message} - Assuming deleted"
80
105
  end
@@ -93,32 +118,34 @@ module Proxy::OpenSCAP
93
118
  get "/policies/:policy_id/content/:digest" do
94
119
  content_type 'application/xml'
95
120
  begin
96
- Proxy::OpenSCAP::FetchScapContent.new.get_policy_content(params[:policy_id], params[:digest])
121
+ Proxy::OpenSCAP::FetchScapFile.new(:scap_content)
122
+ .fetch(params[:policy_id], params[:digest], Proxy::OpenSCAP::Plugin.settings.contentdir)
97
123
  rescue *HTTP_ERRORS => e
98
- log_halt e.response.code.to_i, "File not found on Foreman. Wrong policy id?"
124
+ log_halt e.response.code.to_i, file_not_found_msg
99
125
  rescue StandardError => e
100
126
  log_halt 500, "Error occurred: #{e.message}"
101
127
  end
102
128
  end
103
129
 
104
- get "/policies/:policy_id/content" do
130
+ get "/policies/:policy_id/tailoring/:digest" do
105
131
  content_type 'application/xml'
106
- logger.warn 'DEPRECATION WARNING: /policies/:policy_id/content/:digest should be used, please update foreman_openscap'
107
132
  begin
108
- Proxy::OpenSCAP::FetchScapContent.new.get_policy_content(params[:policy_id], 'scap_content')
133
+ Proxy::OpenSCAP::FetchScapFile.new(:tailoring_file)
134
+ .fetch(params[:policy_id], params[:digest], Proxy::OpenSCAP::Plugin.settings.tailoring_dir)
109
135
  rescue *HTTP_ERRORS => e
110
- log_halt e.response.code.to_i, "File not found on Foreman. Wrong policy id?"
136
+ log_halt e.response.code.to_i, file_not_found_msg
111
137
  rescue StandardError => e
112
138
  log_halt 500, "Error occurred: #{e.message}"
113
139
  end
114
140
  end
115
141
 
116
- get "/policies/:policy_id/tailoring/:digest" do
117
- content_type 'application/xml'
142
+ get "/oval_policies/:oval_policy_id/oval_content/:digest" do
143
+ content_type 'application/x-bzip2'
118
144
  begin
119
- Proxy::OpenSCAP::FetchTailoringFile.new.get_tailoring_file(params[:policy_id], params[:digest])
120
- rescue *HTTP_ERRORS => e
121
- log_halt e.response.code.to_i, "File not found on Foreman. Wrong policy id?"
145
+ Proxy::OpenSCAP::FetchScapFile.new(:oval_content)
146
+ .fetch(params[:oval_policy_id], params[:digest], Proxy::OpenSCAP::Plugin.settings.oval_content_dir)
147
+ rescue *HTTP => e
148
+ log_halt e.response.code.to_i, file_not_found_msg
122
149
  rescue StandardError => e
123
150
  log_halt 500, "Error occurred: #{e.message}"
124
151
  end
@@ -126,7 +153,7 @@ module Proxy::OpenSCAP
126
153
 
127
154
  post "/scap_content/policies" do
128
155
  begin
129
- Proxy::OpenSCAP::ProfilesParser.new('scap_content').profiles(request.body.string)
156
+ Proxy::OpenSCAP::ProfilesParser.new.profiles('scap_content', request.body.string)
130
157
  rescue *HTTP_ERRORS => e
131
158
  log_halt 500, e.message
132
159
  rescue StandardError => e
@@ -136,7 +163,7 @@ module Proxy::OpenSCAP
136
163
 
137
164
  post "/tailoring_file/profiles" do
138
165
  begin
139
- Proxy::OpenSCAP::ProfilesParser.new('tailoring_file').profiles(request.body.string)
166
+ Proxy::OpenSCAP::ProfilesParser.new.profiles('tailoring_file', request.body.string)
140
167
  rescue *HTTP_ERRORS => e
141
168
  log_halt 500, e.message
142
169
  rescue StandardError => e
@@ -166,7 +193,7 @@ module Proxy::OpenSCAP
166
193
 
167
194
  get "/spool_errors" do
168
195
  begin
169
- Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.corrupted_dir, nil, nil, nil).spool_errors.to_json
196
+ Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.corrupted_dir, nil, nil, nil).spool_errors.to_json
170
197
  rescue StandardError => e
171
198
  log_halt 500, "Error occurred: #{e.message}"
172
199
  end
@@ -176,12 +203,16 @@ module Proxy::OpenSCAP
176
203
 
177
204
  def validate_scap_file(params)
178
205
  begin
179
- Proxy::OpenSCAP::ContentParser.new(params[:type]).validate(request.body.string)
206
+ Proxy::OpenSCAP::ContentParser.new.validate(params[:type], request.body.string).to_json
180
207
  rescue *HTTP_ERRORS => e
181
208
  log_halt 500, e.message
182
209
  rescue StandardError => e
183
210
  log_halt 500, "Error occurred: #{e.message}"
184
211
  end
185
212
  end
213
+
214
+ def file_not_found_msg
215
+ "File not found on Foreman. Wrong policy id?"
216
+ end
186
217
  end
187
218
  end