misc_rbtools/rpm_to_cve_parser/rhel_rpm_to_cve.rb
2020-02-04 17:15:20 -06:00

43 lines
810 B
Ruby
Executable file

require 'ox'
class RhelRpmToCve
# filepath == /path/to/rpm-to-cve.xml
attr_accessor :filepath, :file, :xml
def initialize(filepath)
@filepath = filepath
@file = File.read(filepath)
@xml = Ox.load(file, mode: :hash)
end
def list_pkg_names
xml[:rpms][:rpm].map do |key|
key.first[:rpm]
end.sort
end
def pkg_exists?(pkg_name)
list_pkg_names.include? pkg_name
end
def cves_per_pkg_name(pkg_name)
if pkg_exists? pkg_name
results = find_pkg(pkg_name).map do |r|
r[:cve]
end.compact
{
:rhel_package_name => pkg_name,
:cves => results.map {|cve| cve}
}
end
end
def find_pkg(pkg_name)
xml[:rpms][:rpm].select do |results|
results if results.first[:rpm] == pkg_name
end.first
end
end