diff options
Diffstat (limited to 'bin/cisa-sizes.rb')
-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 |