Class: Proxy::OpenSCAP::ArfParser
- Inherits:
-
Object
- Object
- Proxy::OpenSCAP::ArfParser
- Includes:
- Log
- Defined in:
- lib/smart_proxy_openscap/arf_parser.rb
Instance Method Summary collapse
- #as_json(arf_data) ⇒ Object
-
#initialize(cname, policy_id, date) ⇒ ArfParser
constructor
A new instance of ArfParser.
Constructor Details
#initialize(cname, policy_id, date) ⇒ ArfParser
Returns a new instance of ArfParser.
9 10 11 12 13 |
# File 'lib/smart_proxy_openscap/arf_parser.rb', line 9 def initialize(cname, policy_id, date) @cname = cname @policy_id = policy_id @date = date end |
Instance Method Details
#as_json(arf_data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/smart_proxy_openscap/arf_parser.rb', line 15 def as_json(arf_data) decompressed = Tempfile.create do |file| file.write(arf_data) file.flush Proxy::OpenSCAP.execute!('bunzip2', '-dc', file.path).first rescue => e logger.error e raise Proxy::OpenSCAP::ReportDecompressError, "Failed to decompress received report bzip, cause: #{e.}" end arf_file = ::OpenscapParser::TestResultFile.new(decompressed) rules = arf_file.benchmark.rules.reduce({}) do |memo, rule| memo[rule.id] = rule memo end arf_digest = Digest::SHA256.hexdigest(arf_data) report = parse_results(rules, arf_file.test_result, arf_digest) report[:openscap_proxy_name] = Proxy::OpenSCAP::Plugin.settings.registered_proxy_name report[:openscap_proxy_url] = Proxy::OpenSCAP::Plugin.settings.registered_proxy_url report.to_json end |