aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-03-16 07:52:37 -0400
committerPaul Duncan <pabs@pablotron.org>2022-03-16 07:52:37 -0400
commit48214af517844252377b3e24368b423e44c61304 (patch)
treed3dd3f84c21d783c4fc9def7bca3741475276b53 /bin
parent00810ff2fee26b6e6bf514abca918d0105fe7a81 (diff)
downloadcvez-48214af517844252377b3e24368b423e44c61304.tar.bz2
cvez-48214af517844252377b3e24368b423e44c61304.zip
bin/cisa-sizes.rb: print results as csv
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cisa-sizes.rb15
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