aws-cfn-compiler 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aws/cfn/compiler.rb +57 -17
- data/lib/aws/cfn/compiler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0341ec58a6fdcaa0aa8db05578913d55d08b9183
|
4
|
+
data.tar.gz: fda2436952d6ac8c9ace1dc971128fc11a622bd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bda6cd298f8f9309360fe238835b30276c26dcb53dc2a804d9a1d6971047aab545aa8ba3166b186e09358a961524531d14801d3e3d1d57ac14c108f614f299d4
|
7
|
+
data.tar.gz: 65c1ede2af535e67c39fb2cc50bb7ed517fdbb972132a47231478b22cef4b9d651b935929bf41cb87e0a1dedbac41bca34f537e7f7ab55435d4a9ebdbf527cc4
|
data/lib/aws/cfn/compiler.rb
CHANGED
@@ -42,13 +42,14 @@ module Aws
|
|
42
42
|
if @spec and @spec['AWSTemplateFormatVersion']
|
43
43
|
vers = @spec['AWSTemplateFormatVersion']
|
44
44
|
end
|
45
|
+
# noinspection RubyStringKeysInHashInspection
|
45
46
|
compiled = {
|
46
|
-
AWSTemplateFormatVersion
|
47
|
-
Description
|
48
|
-
Parameters
|
49
|
-
Mappings
|
50
|
-
Resources
|
51
|
-
Outputs
|
47
|
+
'AWSTemplateFormatVersion' => (@opts[:formatversion].nil? ? vers : @opts[:formatversion]),
|
48
|
+
'Description' => (@opts[:description].nil? ? desc : @opts[:description]),
|
49
|
+
'Parameters' => @items['Parameters'],
|
50
|
+
'Mappings' => @items['Mappings'],
|
51
|
+
'Resources' => @items['Resources'],
|
52
|
+
'Outputs' => @items['Outputs'],
|
52
53
|
}
|
53
54
|
|
54
55
|
puts
|
@@ -66,9 +67,9 @@ module Aws
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def validate(compiled)
|
69
|
-
raise 'No
|
70
|
-
raise 'No
|
71
|
-
names = compiled[
|
70
|
+
raise 'No Resources!?' unless compiled['Resources']
|
71
|
+
#raise 'No Parameters!?' unless compiled['Parameters']
|
72
|
+
names = compiled['Resources'].keys + (compiled['Parameters'].nil? ? [] : compiled['Parameters'].keys)
|
72
73
|
refs = find_refs(compiled).select { |a| !(a =~ /^AWS::/) }
|
73
74
|
|
74
75
|
unless (refs-names).empty?
|
@@ -79,12 +80,32 @@ module Aws
|
|
79
80
|
abort!
|
80
81
|
end
|
81
82
|
puts ' References validated'
|
83
|
+
names = compiled['Resources'].keys + (compiled['Mappings'].nil? ? [] : compiled['Mappings'].keys)
|
84
|
+
maps = find_maps(compiled) #.select { |a| !(a =~ /^AWS::/) }
|
85
|
+
|
86
|
+
unless (maps-names).empty?
|
87
|
+
puts '!!! Unknown mappings !!!'
|
88
|
+
(maps-names).each do |name|
|
89
|
+
puts " #{name}"
|
90
|
+
end
|
91
|
+
abort!
|
92
|
+
end
|
93
|
+
puts ' References validated'
|
82
94
|
end
|
83
95
|
|
84
96
|
def save(compiled, output_file)
|
85
97
|
begin
|
98
|
+
hash = {}
|
99
|
+
compiled.each do |item,value|
|
100
|
+
unless value.nil?
|
101
|
+
if (not value.is_a?(Hash)) or (value.count > 0)
|
102
|
+
hash[item] = value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
86
107
|
File.open output_file, 'w' do |f|
|
87
|
-
f.write JSON.pretty_generate(
|
108
|
+
f.write JSON.pretty_generate(hash)
|
88
109
|
end
|
89
110
|
puts ' Compiled file written.'
|
90
111
|
rescue
|
@@ -111,19 +132,19 @@ module Aws
|
|
111
132
|
|
112
133
|
case File.extname(File.basename(abs)).downcase
|
113
134
|
when /json/
|
114
|
-
spec = JSON.parse(spec)
|
135
|
+
@spec = JSON.parse(spec)
|
115
136
|
when /yaml/
|
116
|
-
spec = YAML.load(spec)
|
137
|
+
@spec = YAML.load(spec)
|
117
138
|
else
|
118
139
|
raise "Unsupported file type for specification: #{spec}"
|
119
140
|
end
|
120
|
-
@spec = spec
|
141
|
+
# @spec = spec
|
121
142
|
else
|
122
143
|
raise "Unable to open specification: #{abs}"
|
123
144
|
end
|
124
145
|
end
|
125
|
-
%w
|
126
|
-
load_dir(dir
|
146
|
+
%w( Mappings Parameters Resources Outputs ).each do |dir|
|
147
|
+
load_dir(dir,@spec)
|
127
148
|
end
|
128
149
|
end
|
129
150
|
|
@@ -151,6 +172,21 @@ module Aws
|
|
151
172
|
end
|
152
173
|
end
|
153
174
|
|
175
|
+
def find_maps(hash)
|
176
|
+
if hash.is_a? Hash
|
177
|
+
tr = []
|
178
|
+
hash.keys.collect do |key|
|
179
|
+
if 'Fn::FindInMap' == key
|
180
|
+
hash[key].first
|
181
|
+
else
|
182
|
+
find_maps(hash[key])
|
183
|
+
end
|
184
|
+
end.flatten.compact.uniq
|
185
|
+
elsif hash.is_a? Array
|
186
|
+
hash.collect{|a| find_maps(a)}.flatten.compact.uniq
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
154
190
|
def load_dir(dir,spec=nil)
|
155
191
|
puts "Loading #{dir}..."
|
156
192
|
raise "No such directory: #{@opts[:directory]}" unless File.directory?(@opts[:directory])
|
@@ -166,8 +202,9 @@ module Aws
|
|
166
202
|
end
|
167
203
|
set.collect do |filename|
|
168
204
|
next unless filename =~ /\.(json|ya?ml)\z/i
|
169
|
-
if spec and spec
|
205
|
+
if spec and spec.has_key?(dir)
|
170
206
|
base = File.basename(filename).gsub(%r/\.(rb|yaml)/, '')
|
207
|
+
next if spec[dir].nil? # Edge case ... explicitly want NONE of these!
|
171
208
|
next unless spec[dir].include?(base)
|
172
209
|
puts "\tUsing #{dir}/#{base}"
|
173
210
|
end
|
@@ -190,10 +227,13 @@ module Aws
|
|
190
227
|
abort!
|
191
228
|
end
|
192
229
|
end
|
230
|
+
if spec and spec[dir]
|
231
|
+
raise "Suspect that a #{dir} item was missed! \nRequested: #{spec[dir]}\n Found: #{@items[dir].keys}" unless (@items[dir].keys.count == spec[dir].count)
|
232
|
+
end
|
193
233
|
end
|
194
234
|
|
195
235
|
def get_file_set(dir)
|
196
|
-
Dir[File.join(@opts[:directory], "#{dir}.*")] | Dir[File.join(@opts[:directory], dir, "**", "*")]
|
236
|
+
Dir[File.join(@opts[:directory], "#{dir}.*")] | Dir[File.join(@opts[:directory], dir.to_s, "**", "*")]
|
197
237
|
end
|
198
238
|
|
199
239
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-cfn-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PKinney
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|