Skip to content

Instantly share code, notes, and snippets.

@jordimassaguerpla
Created July 6, 2017 11:02
Show Gist options
  • Save jordimassaguerpla/f0e79cf7d83d36270f29675cf9a617e1 to your computer and use it in GitHub Desktop.
Save jordimassaguerpla/f0e79cf7d83d36270f29675cf9a617e1 to your computer and use it in GitHub Desktop.
get ruby security statistics based on [email protected]:rubysec/ruby-advisory-db.git
require "yaml"
if ARGV.length != 1
puts "usage: ruby get_stats.rb YEAR"
exit -1
end
if ARGV[0] !~ /\d\d\d\d/
puts "usage: ruby get_stats.rb YEAR"
exit -2
end
year = Integer(ARGV[0])
result = {}
counter = 0
Dir.entries("gems").each do |gem|
next if !File.directory?("gems/#{gem}")
$stderr.puts "\nParsing gem #{gem}"
$stderr.puts "|"
issues = Dir.entries("gems/#{gem}")
issues.each do |issue|
next if File.directory?(issue)
next if !issue.end_with?(".yml")
$stderr.puts "-- Parsing #{issue}"
data = YAML::load(File.read("gems/#{gem}/#{issue}"))
next unless data
if !data["cve"] && !data["osvdb"]
$stderr.puts "** error: no cve nor osvdb information for #{issue} **"
else
issue_year = data["date"].year
$stderr.puts " year: #{issue_year}"
if issue_year == year
counter = counter + 1
result[data["gem"]] ||= []
result[data["gem"]] << data["year"]
end
end
end
end
puts "-------------- RESULT -------------"
result.each do |k,v|
puts "#{k}, #{v.length}"
end
puts "TOTAL: #{counter}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment