diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-03-16 07:52:37 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-03-16 07:52:37 -0400 |
commit | 48214af517844252377b3e24368b423e44c61304 (patch) | |
tree | d3dd3f84c21d783c4fc9def7bca3741475276b53 | |
parent | 00810ff2fee26b6e6bf514abca918d0105fe7a81 (diff) | |
download | cvez-48214af517844252377b3e24368b423e44c61304.tar.bz2 cvez-48214af517844252377b3e24368b423e44c61304.zip |
bin/cisa-sizes.rb: print results as csv
-rwxr-xr-x | bin/cisa-sizes.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/bin/cisa-sizes.rb b/bin/cisa-sizes.rb index 934ac23..5670ac5 100755 --- a/bin/cisa-sizes.rb +++ b/bin/cisa-sizes.rb @@ -6,6 +6,7 @@ require 'json' require 'zlib' +require 'csv' # path to vulnerabilities PATH = File.join(__dir__, '../cisa/testdata/cisa-kevc-20220313.json.gz') @@ -13,10 +14,18 @@ PATH = File.join(__dir__, '../cisa/testdata/cisa-kevc-20220313.json.gz') # read vulns ROWS = JSON(Zlib::GzipReader.new(File.open(PATH)).read)['vulnerabilities'] -# get/print json-encoded min/max field lengths -puts JSON(ROWS.each.with_object(Hash.new { |h, k| h[k] = {} }) do |row, r| +# get limits +sizes = ROWS.each.with_object(Hash.new { |h, k| h[k] = {} }) do |row, r| row.each do |k, v| r[k][:min] = v.size if !r[k][:min] || v.size < r[k][:min] r[k][:max] = v.size if !r[k][:max] || v.size > r[k][:max] end -end) +end + +# print limits +CSV(STDOUT) do |csv| + csv << %w{name min max} + sizes.keys.sort.each do |k| + csv << [k, sizes[k][:min], sizes[k][:max]] + end +end |