From 48214af517844252377b3e24368b423e44c61304 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 16 Mar 2022 07:52:37 -0400 Subject: bin/cisa-sizes.rb: print results as csv --- bin/cisa-sizes.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'bin') 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 -- cgit v1.2.3