# # Standard libraries # require 'json' # # Third-party libraries # require 'rainbow' module Hrw # # Format result and pretty print it # class Formatter # Format result # # @param [Hash] result scan result # @return [Boolean] vulnerable or not def format(result) deps = [] result['ancestry']['layers'].each do |layer| layer['detected_features'].each do |feature| deps << feature if feature.key?('vulnerabilities') end end deps end # Pretty print result # def print_vulnerable_deps(deps) deps.each do |dep| dep['vulnerabilities'].each do |vuln| patched_version = JSON.parse(vuln['fixed_by']) puts "Name: #{dep['name']}" puts "Version: #{dep['version']}" puts "Advisory: #{vuln['name']}" puts "Severity: #{vuln['severity']}" puts "Link: #{vuln['link']}" puts "Patched version: #{patched_version['spec'].join(', ')}" puts end end end end end