Class: Chelsea::XMLFormatter
- Defined in:
- lib/chelsea/formatters/xml.rb
Overview
Produce output in xml format
Instance Method Summary collapse
- #do_print(results) ⇒ Object
-
#fetch_results(server_response, _reverse_deps) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
-
#get_vulnerability_block(vulnerabilities) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(options) ⇒ XMLFormatter
constructor
A new instance of XMLFormatter.
Constructor Details
#initialize(options) ⇒ XMLFormatter
Returns a new instance of XMLFormatter.
24 25 26 27 |
# File 'lib/chelsea/formatters/xml.rb', line 24 def initialize() super() @options = end |
Instance Method Details
#do_print(results) ⇒ Object
61 62 63 |
# File 'lib/chelsea/formatters/xml.rb', line 61 def do_print(results) puts Ox.dump(results) end |
#fetch_results(server_response, _reverse_deps) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chelsea/formatters/xml.rb', line 29 def fetch_results(server_response, _reverse_deps) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize doc = Ox::Document.new instruct = Ox::Instruct.new(:xml) instruct[:version] = '1.0' instruct[:encoding] = 'UTF-8' instruct[:standalone] = 'yes' doc << instruct testsuite = Ox::Element.new('testsuite') testsuite[:name] = 'purl' testsuite[:tests] = server_response.count doc << testsuite server_response.each do |coord| testcase = Ox::Element.new('testcase') testcase[:classname] = coord['coordinates'] testcase[:name] = coord['coordinates'] if coord['vulnerabilities'].length.positive? failure = Ox::Element.new('failure') failure[:type] = 'Vulnerable Dependency' failure << get_vulnerability_block(coord['vulnerabilities']) testcase << failure testsuite << testcase elsif @options[:verbose] testsuite << testcase end end doc end |
#get_vulnerability_block(vulnerabilities) ⇒ Object
rubocop:disable Metrics/MethodLength
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chelsea/formatters/xml.rb', line 65 def get_vulnerability_block(vulnerabilities) # rubocop:disable Metrics/MethodLength vuln_block = '' vulnerabilities.each do |vuln| vuln_block += "Vulnerability Title: #{vuln['title']}\n"\ "ID: #{vuln['id']}\n"\ "Description: #{vuln['description']}\n"\ "CVSS Score: #{vuln['cvssScore']}\n"\ "CVSS Vector: #{vuln['cvssVector']}\n"\ "CVE: #{vuln['cve']}\n"\ "Reference: #{vuln['reference']}"\ "\n" end vuln_block end |