aws-cfn-compiler 0.9.9 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGYzYzY2Mzg1NTIwZDUxOTQ4YmJmZjA0YjI1MDhmOTg1NjQ2OTY0NQ==
4
+ OGMwOGEzN2JlYTE1NjY3MzI1YzIwNTljMTYwZDM1NDBiMzdmOTU2MQ==
5
5
  data.tar.gz: !binary |-
6
- NWMzYjczYjA3ZGZhYmQyODJhMmQyNDY1YjA0NGI0NDVhMThjNjQ4MQ==
6
+ ODJlNzFmNjhmZjY3YzFkOGE0OTQwNWFkNjM2ZmNmMjU2OWVlNjBjNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTE5MTRhZjM2NTQzMWRhZjM4ODRmOGM5Y2Q5MjYyMDM4Y2FmYWE4N2YwZmIw
10
- ODc0MDMxMmQ3YTBiMDA0ZTI1ODJkZDJhYWNlNWMzNWFmYmZhODJmOGZjNTQ5
11
- YTE5NjZhNzU3OWI4NTY1Nzk2MjgyZTFiMGRmZjlhOTNjZWRkZmY=
9
+ NGQwZWRmZjYyMzFkZDY0YWVlZWExYmMzZGYyNTc4MDYzZWI3YTc0ZmQ1NzQx
10
+ MjE1NTY3Nzk0YTAwOTJjODRjZWUwOWY1YWQ4ZmJlYWMwZmZjYWYyYjM0NDFm
11
+ MWQxMGY2MWNiOGZhNDg2OTk5NzUwMzU5MGI2NzYxZDA0MTg3ZjI=
12
12
  data.tar.gz: !binary |-
13
- OWM3MGQwYjQ5YTMwYmRiMGViMGYxMTFjMTAwY2ExZjU4N2NjNjBkZGY3NTM4
14
- NTg0MGFlZTdkOTYxZjQwMWI0YjExMTI4YjExYzQ0NGJjZmIzOTA4MTc4OTYy
15
- NWFjODBiMzBlNzVhOTVjMGMyMDg2NDZmMDA3NTg3OWVjZmMzMjQ=
13
+ ZmY0NjhlNTdlN2MyOGM3MTljZTE1OWUxZTZjZDE1MjJmZDk2NmQ3M2ZhYzY4
14
+ ODZhODc0ODgyYjYxZTQ4MTgyNzc3Mzg3NWY5YTUxNzdlOGI3ZWQ2NWMwZjM2
15
+ NTYxYWQ0ZjgyZDFkMDliNjA4YzMxYjU0YzRmYTQxZjc4ZDc0Mzk=
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'slop'
25
25
  spec.add_dependency 'inifile'
26
26
  spec.add_dependency 'semverse', '>= 1.1.0'
27
- spec.add_dependency 'aws-cfn-dsl', '>= 0.9.5'
27
+ spec.add_dependency 'aws-cfn-dsl', '>= 0.9.6'
28
28
  spec.add_dependency 'mixlib-cli', '> 0'
29
29
  spec.add_dependency 'dldinternet-mixlib-cli', '>= 0.2.0'
30
30
  spec.add_dependency 'dldinternet-mixlib-logging', '>= 0.4.0'
@@ -17,29 +17,37 @@ module Aws
17
17
  def initialize
18
18
  super
19
19
  @items = {}
20
+ @dynamic_items = {}
21
+ end
22
+
23
+ def dynamic_item(section,resource,hash)
24
+ @dynamic_items[section][resource] = hash
20
25
  end
21
26
 
22
27
  def validate(compiled)
23
28
  abort! 'No Resources!?' unless compiled['Resources']
24
29
  logStep 'Validating template'
25
30
 
31
+ # --- Parameters ----------------------------------------------------------------------------------------------
26
32
  prms = compiled['Parameters'].keys rescue []
27
- compiled['Parameters'].each do |name,hash|
28
- abort! "Parameter #{name} has an invalid compiled block!\n#{hash.ai}" unless hash.is_a?(Hash)
29
- if hash['Type']
30
- unless %w(String Number CommaDelimitedList).include?(hash['Type'])
31
- abort! "Parameter #{name} has an invalid type: #{hash['Type']}"
33
+ if compiled['Parameters']
34
+ compiled['Parameters'].each do |name,hash|
35
+ abort! "Parameter #{name} has an invalid compiled block!\n#{hash.ai}" unless hash.is_a?(Hash)
36
+ if hash['Type']
37
+ unless %w(String Number CommaDelimitedList).include?(hash['Type'])
38
+ abort! "Parameter #{name} has an invalid type: #{hash['Type']}"
39
+ end
32
40
  end
33
- end
34
- if hash['Default']
35
- unless hash['Default'].is_a?(String)
36
- abort! "Parameter #{name} has an invalid default (Must be string): #{hash['Default']}"
41
+ if hash['Default']
42
+ unless hash['Default'].is_a?(String)
43
+ abort! "Parameter #{name} has an invalid default (Must be string): #{hash['Default']}"
44
+ end
37
45
  end
38
46
  end
47
+ @logger.info ' Parameters validated'
39
48
  end
40
- @logger.info ' Parameters validated'
41
49
 
42
- # Mappings => Resources
50
+ # --- functions ----------------------------------------------------------------------------------------------
43
51
  funs = find_fns(compiled) #.select { |a| !(a =~ /^AWS::/) }
44
52
 
45
53
  bad = []
@@ -53,19 +61,23 @@ module Aws
53
61
  end
54
62
  @logger.info ' Functions validated'
55
63
 
56
- # Mappings => Resources
57
- maps = find_maps(compiled) #.select { |a| !(a =~ /^AWS::/) }
64
+ # --- Mappings ----------------------------------------------------------------------------------------------
65
+ mappings = find_maps(compiled)
58
66
  mpgs = compiled['Mappings'].nil? ? [] : compiled['Mappings'].keys
59
67
  names = mpgs # rscs+
60
68
 
61
- unless (maps-names).empty?
69
+ maps = {}
70
+ mappings.each{|m| maps[m[:mapping]] = m[:source] }
71
+ mapnames = maps.keys
72
+ net = (mapnames-names)
73
+ unless net.empty?
62
74
  @logger.error '!!! Unknown mappings !!!'
63
- (maps-names).each do |name|
64
- @logger.error " #{name}"
75
+ net.each do |name|
76
+ @logger.error " #{name} (Location in template: #{maps[name].join('/')})"
65
77
  end
66
78
  abort!
67
79
  end
68
- net = (names-maps)
80
+ net = (names-mapnames)
69
81
  unless net.empty?
70
82
  @logger.warn '!!! Unused mappings !!!'
71
83
  net.each do |name|
@@ -74,11 +86,32 @@ module Aws
74
86
  end
75
87
  @logger.info ' Mappings validated'
76
88
 
89
+ # --- Conditions ----------------------------------------------------------------------------------------------
90
+ cond = find_conditions(compiled)
91
+ cnds = compiled['Conditions'].keys rescue []
92
+ names = cnds
93
+
94
+ net = (cond-names)
95
+ unless net.empty?
96
+ @logger.error '!!! Unknown conditions !!!'
97
+ net.each do |name|
98
+ @logger.error " #{name}"
99
+ end
100
+ abort!
101
+ end
102
+ net = (names-cond)
103
+ unless net.empty?
104
+ @logger.warn '!!! Unused conditions !!!'
105
+ net.each do |name|
106
+ @logger.warn " #{name}"
107
+ end
108
+ end
109
+ @logger.info ' Conditions validated'
110
+
111
+ # --- References ----------------------------------------------------------------------------------------------
77
112
  # Parameters => Resources => Outputs
78
113
  refs = find_refs(compiled).select { |a,_| !(a =~ /^AWS::/) }
79
114
  rscs = compiled['Resources'].keys
80
- cnds = compiled['Conditions'].keys rescue []
81
- # outs = compiled['Outputs'].keys rescue []
82
115
  names = rscs+prms+cnds
83
116
 
84
117
  net = (refs.keys-names)
@@ -96,9 +129,9 @@ module Aws
96
129
  @logger.warn " #{name}"
97
130
  end
98
131
  end
99
- net = (rscs-refs.keys)
132
+ net = (rscs.sort-refs.keys.sort)
100
133
  unless net.empty?
101
- @logger.info '!!! Unreported Resources !!!'
134
+ @logger.info '!!! Unreferenced Resources !!!'
102
135
  net.each do |name|
103
136
  @logger.info " #{name}"
104
137
  end
@@ -190,7 +223,12 @@ module Aws
190
223
  when /json|jts/
191
224
  @spec = JSON.parse(spec)
192
225
  when /yaml|yts/
193
- @spec = YAML.load(spec)
226
+ begin
227
+ @spec = YAML.load(spec)
228
+ rescue Psych::SyntaxError => e
229
+ i = 0
230
+ abort! "Error in the template specification: #{e.message}\n#{spec.split(/\n/).map{|l| "#{i+=1}: #{l}"}.join("\n")}"
231
+ end
194
232
  else
195
233
  abort! "Unsupported file type for specification: #{spec}"
196
234
  end
@@ -245,17 +245,36 @@ module Aws
245
245
  r
246
246
  end
247
247
 
248
- def find_maps(hash)
248
+ def find_maps(hash,source=[])
249
249
  if hash.is_a? Hash
250
250
  hash.keys.collect do |key|
251
251
  if 'Fn::FindInMap' == key
252
- hash[key].first
252
+ { mapping: hash[key].first, source: source }
253
253
  else
254
- find_maps(hash[key])
254
+ find_maps(hash[key], [ source, key ].flatten!)
255
255
  end
256
256
  end.flatten.compact.uniq
257
257
  elsif hash.is_a? Array
258
- hash.collect{|a| find_maps(a)}.flatten.compact.uniq
258
+ hash.collect{|a|
259
+ find_maps(a,source)}.flatten.compact.uniq
260
+ end
261
+ end
262
+
263
+ def find_conditions(hash)
264
+ if hash.is_a? Hash
265
+ hash.keys.collect do |key|
266
+ if 'Condition' == key
267
+ if hash[key].is_a?(Array)
268
+ hash[key].first
269
+ else
270
+ hash[key]
271
+ end
272
+ else
273
+ find_conditions(hash[key])
274
+ end
275
+ end.flatten.compact.uniq
276
+ elsif hash.is_a? Array
277
+ hash.collect{|a| find_conditions(a)}.flatten.compact.uniq
259
278
  end
260
279
  end
261
280
 
@@ -101,7 +101,7 @@ module Aws
101
101
  end
102
102
 
103
103
  unless File.directory?(path)
104
- @logger.error " !! error: Cannot load bricks from #{patn} with brick path: \n\t#{@config[:brick_path_list].join("\n\t")} \n(started with #{File.join(base, dir)}')"
104
+ @logger.error " !! error: Cannot load #{dir}/#{rsrc} with brick path: \n\t#{@config[:brick_path_list].join("\n\t")} \n(started with #{File.join(base, dir)}')"
105
105
  abort!
106
106
  end
107
107
  path
@@ -79,6 +79,7 @@ module Aws
79
79
  if spec and spec[section]
80
80
  @items ||= {}
81
81
  @items[section] ||= {}
82
+ @dynamic_items[section] ||= {}
82
83
  get = {}
83
84
  item = {}
84
85
  spec[section].each do |rsrc|
@@ -125,7 +126,12 @@ module Aws
125
126
  abort! " !! error: #{$!}"
126
127
  end
127
128
  else
128
- abort! " !! error: #{section}/#{base} not found!"
129
+ pm = []
130
+ set.map { |r,f|
131
+ b = File.basename(f).gsub( %r(\..*?$), '' )
132
+ pm << b if b.downcase == rsrc.downcase
133
+ }
134
+ abort! " !! error: #{section}/#{base} not found! Possible matches: #{pm}"
129
135
  end
130
136
  end
131
137
  item.keys.each { |key|
@@ -135,7 +141,7 @@ module Aws
135
141
  }
136
142
  @items[section].merge! item
137
143
 
138
- unless @items[section].keys.count == spec[section].count
144
+ unless @items[section].keys.count == (spec[section].count + @dynamic_items[section].keys.count)
139
145
  abort! " !! error: Suspect that a #{section} item was missed or not properly named (Brick name and file name mismatch?)! \nRequested: #{spec[section]}\n Found: #{@items[section].keys}"
140
146
  end
141
147
  end
@@ -1,7 +1,7 @@
1
1
  module Aws
2
2
  module Cfn
3
3
  module Compiler
4
- VERSION = '0.9.9'
4
+ VERSION = '0.9.12'
5
5
  end
6
6
  end
7
7
  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.9.9
4
+ version: 0.9.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - PKinney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -106,14 +106,14 @@ dependencies:
106
106
  requirements:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
- version: 0.9.5
109
+ version: 0.9.6
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ! '>='
115
115
  - !ruby/object:Gem::Version
116
- version: 0.9.5
116
+ version: 0.9.6
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: mixlib-cli
119
119
  requirement: !ruby/object:Gem::Requirement