diff --git a/security_tools/redhat_tools/rhel_security_api_client.rb b/security_tools/redhat_tools/rhel_security_api_client.rb index 8e70073..0cea316 100644 --- a/security_tools/redhat_tools/rhel_security_api_client.rb +++ b/security_tools/redhat_tools/rhel_security_api_client.rb @@ -41,4 +41,9 @@ class RhelSecurityApiClient } end end + + def cve_id(cve_id) + params = {} + request("/cve/#{cve_id}.json", params) + end end diff --git a/security_tools/redhat_tools/rpm_pkg_audit.rb b/security_tools/redhat_tools/rpm_pkg_audit.rb index 11eb5bc..1ac6129 100755 --- a/security_tools/redhat_tools/rpm_pkg_audit.rb +++ b/security_tools/redhat_tools/rpm_pkg_audit.rb @@ -5,6 +5,7 @@ require 'optparse' require 'json' require './rhel_rpm_to_cve' require './rhel_security_api_client' +require 'pry' ARGV << '-h' if ARGV.empty? @@ -26,6 +27,9 @@ parser = OptionParser.new do |parser| parser.on('-r', '--refresh', 'Refresh rpm-to-cve.xml file with latest pkgs and cves') do |_refresh| options[:refresh] = true end + parser.on('-c', '--cve CVE_ID', 'Takes a cve id and returns cve json from redhats security API.') do |cve| + options[:cve] = cve + end end parser.parse! @@ -39,6 +43,7 @@ end rpm_auditer = RhelRpmToCve.new(filepath: data_file) rhel_api_client = RhelSecurityApiClient.new +# this is getting long and nasty probably change this to a case statment if xmlpkg_name json = rpm_auditer.cves_per_pkg_name(xmlpkg_name).to_json puts JSON.pretty_generate(JSON.parse(json)) @@ -49,6 +54,10 @@ elsif pkg_name puts JSON.pretty_generate(cve_pkgs_and_adv) elsif options[:refresh] rpm_auditer.refresh_rpm_to_cve_file('./rpm-to-cve.xml') +elsif options[:cve] + cve = options[:cve] + r = rhel_api_client.cve_id(cve) + puts JSON.pretty_generate(r) else options.key?(:list) - puts rpm_auditer.list_pkg_names.sort + puts rpm_auditer.list_pkg_names.sort end