Skip to content

Commit 7f73a20

Browse files
committed
Add file generation task
1 parent c1f265c commit 7f73a20

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

Rakefile

+35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'yaml'
2+
require 'nokogiri'
3+
require 'open-uri'
24

35
namespace :lint do
46
begin
@@ -22,5 +24,38 @@ namespace :lint do
2224
end
2325
end
2426

27+
config = YAML.load(File.read("./config.yml"))
28+
namespace :db do
29+
# TODO: sleep after each generation
30+
desc "generate files"
31+
task :update => config.select {|k,attrs| attrs["exec"]}.keys.map { |name| "db:update:#{name}"}
32+
33+
namespace :update do
34+
config.each do |name, attrs|
35+
next unless attrs["exec"]
36+
desc "generate #{name} files"
37+
task name do
38+
doc = open(attrs["url"]) { |f| Nokogiri::XML(f) }
39+
doc.xpath(attrs["entry_condition"]).each do |elem|
40+
h = attrs["base_attributes"].merge(attrs["attribute_conditions"].map {|k, conds|
41+
if conds.kind_of?(Array)
42+
# FIXME
43+
[k, elem.xpath(conds[0]).first.xpath(conds[1]).to_s]
44+
else
45+
[k, elem.xpath(conds).first.content]
46+
end
47+
}.to_h)
48+
path = File.join(attrs["path"], "CVE-" + h["cve"] + ".yml")
49+
if !File.exists?(path)
50+
File.open(path, "w") do |f|
51+
f.write(h.to_yaml)
52+
end
53+
end
54+
end
55+
end
56+
end
57+
end
58+
end
59+
2560
task :lint => ['lint:yaml', 'lint:cve']
2661
task :default => :lint

config.yml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
ruby:
2+
# TODO: from CVE DB if possible
3+
url: https://www.ruby-lang.org/en/feeds/news.rss
4+
entry_condition: '//item[contains(title, "CVE")]'
5+
path: rubies/ruby/
6+
base_attributes:
7+
engine: ruby
8+
attribute_conditions:
9+
cve: ['title/text()', 'substring-after(substring-before(., ":"), "CVE-")']
10+
url: link
11+
title: ['title/text()', 'substring-after(., ": ")']
12+
date: pubDate
13+
description: description
14+
exec: true
15+
16+
rails_base: &rails_base
17+
url: "https://groups.google.com/forum/feed/rubyonrails-security/msgs/rss.xml?num=15"
18+
attribute_conditions:
19+
cve: ['title/text()', 'substring-after(substring-before(., "]"), "CVE-")']
20+
url: link
21+
title: ['title/text()', 'substring-after(., "] ")']
22+
# TODO: fix date format
23+
date: pubDate
24+
description: description
25+
exec: false
26+
27+
activerecord:
28+
<<: *rails_base
29+
entry_condition: '//item[contains(title, "Active Record")]'
30+
path: gems/activerecord/
31+
base_attributes:
32+
# TODO: move to rails_base
33+
framework: rails
34+
gem: activerecord
35+
exec: true
36+
37+
actionpack:
38+
<<: *rails_base
39+
entry_condition: '//item[contains(title, "Action Pack")]'
40+
path: gems/actionpack/
41+
base_attributes:
42+
# TODO: move to rails_base
43+
framework: rails
44+
gem: actionpack
45+
exec: true
46+
47+
actionview:
48+
<<: *rails_base
49+
entry_condition: '//item[contains(title, "Action View")]'
50+
path: gems/actionview/
51+
base_attributes:
52+
# TODO: move to rails_base
53+
framework: rails
54+
gem: actionview
55+
exec: true
56+
57+
activesupport:
58+
<<: *rails_base
59+
entry_condition: '//item[contains(title, "Active Support")]'
60+
path: gems/activesupport/
61+
base_attributes:
62+
# TODO: move to rails_base
63+
framework: rails
64+
gem: activesupport
65+
exec: true
66+
67+
activemodel:
68+
<<: *rails_base
69+
entry_condition: '//item[contains(title, "Active Model")]'
70+
path: gems/activemodel/
71+
base_attributes:
72+
# TODO: move to rails_base
73+
framework: rails
74+
gem: activemodel
75+
exec: true
76+
77+
# TODO: move to actionpack
78+
actioncontroller:
79+
<<: *rails_base
80+
entry_condition: '//item[contains(title, "Action Controller")]'
81+
path: gems/actionpack/
82+
base_attributes:
83+
# TODO: move to rails_base
84+
framework: rails
85+
gem: actionpack
86+
exec: true

0 commit comments

Comments
 (0)