smart_proxy_openscap 0.7.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/bin/smart-proxy-openscap-send +5 -1
- data/lib/smart_proxy_openscap/arf_parser.rb +74 -17
- data/lib/smart_proxy_openscap/content_parser.rb +19 -25
- data/lib/smart_proxy_openscap/fetch_scap_file.rb +45 -0
- data/lib/smart_proxy_openscap/foreman_arf_forwarder.rb +15 -0
- data/lib/smart_proxy_openscap/foreman_forwarder.rb +19 -16
- data/lib/smart_proxy_openscap/foreman_oval_forwarder.rb +19 -0
- data/lib/smart_proxy_openscap/openscap_api.rb +59 -28
- data/lib/smart_proxy_openscap/openscap_exception.rb +1 -0
- data/lib/smart_proxy_openscap/openscap_html_generator.rb +1 -1
- data/lib/smart_proxy_openscap/openscap_import_api.rb +3 -3
- data/lib/smart_proxy_openscap/openscap_lib.rb +5 -3
- data/lib/smart_proxy_openscap/openscap_plugin.rb +2 -1
- data/lib/smart_proxy_openscap/oval_report_parser.rb +54 -0
- data/lib/smart_proxy_openscap/oval_report_storage_fs.rb +26 -0
- data/lib/smart_proxy_openscap/profiles_parser.rb +22 -23
- data/lib/smart_proxy_openscap/spool_forwarder.rb +4 -4
- data/lib/smart_proxy_openscap/storage.rb +0 -2
- data/lib/smart_proxy_openscap/storage_fs.rb +7 -4
- data/lib/smart_proxy_openscap/storage_fs_common.rb +42 -0
- data/lib/smart_proxy_openscap/version.rb +1 -1
- data/settings.d/openscap.yml.example +3 -0
- data/smart_proxy_openscap.gemspec +2 -0
- data/test/data/oval-results.xml.bz2 +0 -0
- data/test/data/rhel-7-including-unpatched.oval.xml.bz2 +0 -0
- data/test/fetch_oval_content_api_test.rb +38 -0
- data/test/fetch_scap_api_test.rb +1 -1
- data/test/oval_report_parser_test.rb +14 -0
- data/test/post_oval_report_api_test.rb +30 -0
- data/test/post_report_api_test.rb +2 -2
- data/test/scap_content_parser_api_test.rb +1 -1
- data/test/script_class_test.rb +0 -58
- metadata +29 -11
- data/bin/smart-proxy-arf-json +0 -7
- data/bin/smart-proxy-scap-profiles +0 -7
- data/bin/smart-proxy-scap-validation +0 -7
- data/lib/smart_proxy_openscap/arf_json.rb +0 -114
- data/lib/smart_proxy_openscap/fetch_scap_content.rb +0 -17
- data/lib/smart_proxy_openscap/fetch_tailoring_file.rb +0 -17
- data/lib/smart_proxy_openscap/scap_profiles.rb +0 -52
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d1a52c4299cb9828c2cb492622a4cc13f9cd3d234fc6a9940dc9768840761b
|
4
|
+
data.tar.gz: bfa0d9e1444579127bec7bf5f32fe37d73577c99ab803dfd07b59c0ed6f1e15a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c8ece151fb60cdf31a3c396b22df455d3f653648640f5e6d05505c67c386128bf09970bd9d08b82e94710d493c3ba8dd003d47d584e05819204cd32987ffc3
|
7
|
+
data.tar.gz: 18acfdafceecc4845da3fce3703f7e670d0c991ddda0d6cb542c00ccb6d399cd4090b63cf44dbeb2fef5aa99cfa0fb7710a2a54cf5b6d4b1678f98b70d01678b
|
data/Gemfile
CHANGED
@@ -1,38 +1,95 @@
|
|
1
|
-
require '
|
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
|
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
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
23
|
-
|
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
|
27
|
-
|
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
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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 '
|
1
|
+
require 'openscap_parser/datastream_file'
|
2
|
+
require 'openscap_parser/tailoring_file'
|
2
3
|
|
3
4
|
module Proxy::OpenSCAP
|
4
|
-
class ContentParser
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
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
|
-
|
30
|
-
|
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
|
-
|
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 =
|
41
|
-
Proxy::OpenSCAP::
|
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::
|
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
|
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::
|
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::
|
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::
|
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::
|
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::
|
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,
|
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/
|
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::
|
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,
|
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 "/
|
117
|
-
content_type 'application/
|
142
|
+
get "/oval_policies/:oval_policy_id/oval_content/:digest" do
|
143
|
+
content_type 'application/x-bzip2'
|
118
144
|
begin
|
119
|
-
Proxy::OpenSCAP::
|
120
|
-
|
121
|
-
|
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'
|
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'
|
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::
|
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]
|
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
|