forked from flexera-public/policy_templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
69 lines (61 loc) · 2.28 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
62
63
64
65
66
67
68
69
require 'rubygems'
require 'json'
require 'fileutils'
require_relative 'tools/lib/policy_parser'
# the list of policies is consumed by the tools/policy_sync/policy_sync.pt
# and the docs.rightscale.com build to generate the policies/user/policy_list.html
# the file is uploaded to S3 during a merge to master deploy step in .travis.yml
desc "Create a list of active policies to be published to the Public Policy Catalog"
task :generate_policy_list do
FileUtils.mkdir_p 'dist'
file_list = []
Dir['**/*.pt'].reject{ |f| f['msp/'] }.each do |file|
change_log = ::File.join(file.split('/')[0...-1].join('/'),'CHANGELOG.md')
readme = ::File.join(file.split('/')[0...-1].join('/'),'README.md')
publish = true
if !file.match(/test_code/)
f = File.open(file, "r:bom|utf-8")
pp = PolicyParser.new
pp.parse(file)
if pp.parsed_info
version = pp.parsed_info[:version]
provider = pp.parsed_info[:provider]
service = pp.parsed_info[:service]
policy_set = pp.parsed_info[:policy_set]
publish = pp.parsed_info[:publish]
# not all templates have the publish key
# set these to true,
if publish.nil? || publish=='true' || publish==true
publish = true
else
publish = false
end
end
# get version from long description
if version.nil? && pp.parsed_long_description =~ /Version/
version = pp.parsed_long_description.split(':').last.strip.chomp("\"")
end
# skip policy if the version isn't supplied or if version is '0.0'
if ! version || version == '0.0' || ! publish
puts "Skipping #{pp.parsed_name}, policy not published"
next
end
puts "Adding #{pp.parsed_name}"
file_list<<{
"name": pp.parsed_name,
"file_name": file,
"version": version,
"change_log": change_log,
"description": pp.parsed_short_description,
"category": pp.parsed_category,
"severity": pp.parsed_severity,
"readme": readme,
"provider": provider,
"service": service,
"policy_set": policy_set,
}
end
end
policies = {"policies": file_list }
File.open('dist/active-policy-list.json', 'w') { |file| file.write(JSON.pretty_generate(policies)+"\n") }
end