-
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathRakefile
61 lines (54 loc) · 1.56 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'yaml'
require 'nokogiri'
require 'open-uri'
namespace :lint do
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:yaml)
rescue LoadError => e
task :spec do
abort "Please run `gem install rspec` to install RSpec."
end
end
task :cve do
Dir.glob('{gems,libraries,rubies}/*/*.yml') do |path|
advisory = YAML.load_file(path)
unless advisory['cve']
puts "Missing CVE: #{path}"
end
end
end
end
config = YAML.load(File.read("./config.yml"))
namespace :db do
# TODO: sleep after each generation
desc "generate files"
task :update => config.select {|k,attrs| attrs["exec"]}.keys.map { |name| "db:update:#{name}"}
namespace :update do
config.each do |name, attrs|
next unless attrs["exec"]
desc "generate #{name} files"
task name do
doc = open(attrs["url"]) { |f| Nokogiri::XML(f) }
doc.xpath(attrs["entry_condition"]).each do |elem|
h = attrs["base_attributes"].merge(attrs["attribute_conditions"].map {|k, conds|
if conds.kind_of?(Array)
# FIXME
[k, elem.xpath(conds[0]).first.xpath(conds[1]).to_s]
else
[k, elem.xpath(conds).first.content]
end
}.to_h)
path = File.join(attrs["path"], "CVE-" + h["cve"] + ".yml")
if !File.exists?(path)
File.open(path, "w") do |f|
f.write(h.to_yaml)
end
end
end
end
end
end
end
task :lint => ['lint:yaml', 'lint:cve']
task :default => :lint