aws-cfn-compiler 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmQ4ODM4MjllY2FjYWM4YjUzNDRkODYwMDNiNGZhZWFiNTk5ZGE5Mg==
4
+ MWFiNWI1NTIzY2VhNjQ4NjM3ZDgzOWIwNTg4MzczZDI3OWFlNzFlMw==
5
5
  data.tar.gz: !binary |-
6
- Zjc3MTdkNmY0MDIyZTNmOWYyOWViMDE2ZTEzOWRmNDk2OTRkZWNkZQ==
6
+ YjIwMjMwNzlkY2Q2YzliM2U3ZWM0YjE2ODgyZDcyMjUzMDM2MzJmMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmI4NWIwNjU1NjNlODQ2OGMwN2E0Mzc2MTE2OGVmMTExNWViODcwOGU5ZjU1
10
- YzA2ZDQ0ZWU1NjYyZjA4NTk4NzhmOGUwZjk0YTlhYTUyNmJmYzlmZjJiNTI1
11
- ZWY2ZTY4MWMxZGFmNzcwMzZkNTc4NWVjNWIyYWNiNzk5YTFhMmM=
9
+ NDhjYjgyZjZlNzM4ZWExMTA0Y2QxNGIzMWM3ZTNmZWQ2ZWUxNDdlMDlhNzA3
10
+ ZjI4Y2QxNDgwNDYwZjNiNTRjODY5ZmE3ZjBlYmJjYmYxMzhkYmJjN2YzMjNh
11
+ YTMwYjQ2Y2U4NDE2N2Q0NTJlZWZiNDVlZjg5MjFhMDRhMWRjNzk=
12
12
  data.tar.gz: !binary |-
13
- YmEyZmViZmEzZDRmYmVkNzQ5ZDg0MDZlMDVlYTlmZmFlNmVhNjNlYTMwMThh
14
- MGFmYmQ5NWMyNTlmMGViYWQ4MWQ5ZjVkMTViZmZiYzNjYzU2YTZmN2I2Nzcx
15
- OTM3ZmVmMGE4NWYzNWNkZDcxODA1MmI4MTZiYmRjNjE1YTgwNmY=
13
+ NGYyNzU2MWE2NTZhOGFkZTRjYTgxZTMzNzVjOGVmZDJjZjQzOTQxNzg3M2Vh
14
+ ODY1YzQ1YWI5OWMxOGU5OGY5MzEyMTg0YjY2NzdiODcyYzUzNTk0ODVjNjQw
15
+ MjBhMmQzMmZmYzM3MTIxNTc1MzFlZTkyZWUxNGUzYWYxNTFkZDg=
data/aws-cfn-compiler.iml CHANGED
@@ -10,23 +10,7 @@
10
10
  <orderEntry type="sourceFolder" forTests="false" />
11
11
  <orderEntry type="module" module-name="aws-cfn-decompiler" />
12
12
  <orderEntry type="module" module-name="aws-cfn-dsl" />
13
- <orderEntry type="module-library">
14
- <library name="aws-cfn-stacker (v[path], /Users/cdelange/Dropbox/DLDInternet/ws/gems-ws/aws-cfn-stacker) [path][gem]">
15
- <CLASSES>
16
- <root url="file://$MODULE_DIR$/../aws-cfn-stacker/bin" />
17
- <root url="file://$MODULE_DIR$/../aws-cfn-stacker/lib" />
18
- <root url="file://$MODULE_DIR$/../aws-cfn-stacker/pkg" />
19
- <root url="file://$MODULE_DIR$/../aws-cfn-stacker/.idea" />
20
- </CLASSES>
21
- <JAVADOC />
22
- <SOURCES>
23
- <root url="file://$MODULE_DIR$/../aws-cfn-stacker/bin" />
24
- <root url="file://$MODULE_DIR$/../aws-cfn-stacker/lib" />
25
- <root url="file://$MODULE_DIR$/../aws-cfn-stacker/pkg" />
26
- <root url="file://$MODULE_DIR$/../aws-cfn-stacker/.idea" />
27
- </SOURCES>
28
- </library>
29
- </orderEntry>
13
+ <orderEntry type="module" module-name="aws-cfn-stacker" />
30
14
  <orderEntry type="module" module-name="aws-cfn-yats" />
31
15
  <orderEntry type="module" module-name="cloudformation-ruby-dsl" />
32
16
  <orderEntry type="module-library">
@@ -2,3 +2,16 @@ require "aws/cfn/compiler/version"
2
2
  require "aws/cfn/compiler/base"
3
3
  require "aws/cfn/compiler/main"
4
4
 
5
+ module Aws::Cfn::Compiler
6
+ attr_accessor :binding
7
+
8
+ @binding ||= {}
9
+
10
+ def self.binding=(b)
11
+ @binding = b
12
+ end
13
+
14
+ def self.binding
15
+ @binding
16
+ end
17
+ end
@@ -9,7 +9,7 @@ require 'aws/cfn/dsl/template'
9
9
  module Aws
10
10
  module Cfn
11
11
  module Compiler
12
- class Base < Aws::Cfn::Dsl::Base
12
+ class Base < ::Aws::Cfn::Dsl::Base
13
13
  attr_accessor :items
14
14
  attr_accessor :opts
15
15
  attr_accessor :spec
@@ -54,7 +54,7 @@ module Aws
54
54
  @logger.info ' References validated'
55
55
  end
56
56
 
57
- def save(output_file,compiled)
57
+ def save_template(output_file,compiled)
58
58
  output_file = File.realpath(File.expand_path(output_file)) if @config[:expandedpaths]
59
59
  logStep "Writing compiled file to #{output_file}..."
60
60
  begin
@@ -77,21 +77,21 @@ module Aws
77
77
  end
78
78
  end
79
79
 
80
- def load(spec=nil)
80
+ def load_spec(spec=nil)
81
81
  if spec
82
82
  abs = nil
83
- [spec, File.join(@opts[:directory],spec)].each do |p|
83
+ [spec, File.join(@config[:directory],spec)].each do |p|
84
84
  begin
85
85
  abs = File.realpath(File.absolute_path(File.expand_path(p)))
86
86
  break if File.exists?(abs)
87
87
  rescue => e
88
- @logger.error e
88
+ @logger.debug e
89
89
  # pass
90
90
  end
91
91
  end
92
92
 
93
- if File.exists?(abs)
94
- logStep "Loading specification #{@opts[:expandedpaths] ? abs : spec}..."
93
+ if not abs.nil? and File.exists?(abs)
94
+ logStep "Loading specification #{@config[:expandedpaths] ? abs : spec}..."
95
95
  unless abs =~ /\.(json|ya?ml|jts|yts)\z/i
96
96
  abort! "Unsupported specification file type: #{spec}=>#{abs}\n\tSupported types are: json,yaml,jts,yts\n"
97
97
  end
@@ -107,9 +107,9 @@ module Aws
107
107
  abort! "Unsupported file type for specification: #{spec}"
108
108
  end
109
109
  else
110
- abort! "Unable to open specification: #{abs}"
110
+ abort! "Unable to open specification"+ (abs.nil? ? " or {,#{@config[:directory]}/}#{spec} not found" : ": #{abs}")
111
111
  end
112
- @dsl ||= Aws::Cfn::Dsl::Template.new(@opts[:directory])
112
+ @dsl ||= Aws::Cfn::Dsl::Template.new(@config[:directory])
113
113
  %w( Mappings Parameters Resources Outputs ).each do |dir|
114
114
  load_dir(dir,@spec)
115
115
  end
@@ -125,7 +125,7 @@ module Aws
125
125
  logStep "Loading #{dir}..."
126
126
 
127
127
  if spec and spec[dir]
128
- raise "No such directory: #{@opts[:directory]}" unless File.directory?(@opts[:directory])
128
+ raise "No such directory: #{@config[:directory]}" unless File.directory?(@config[:directory])
129
129
  path = vet_path(dir)
130
130
  @items ||= {}
131
131
  @items[dir] ||= {}
@@ -135,7 +135,7 @@ module Aws
135
135
 
136
136
  item = {}
137
137
  spec[dir].each do |rsrc|
138
- @logger.info "\tUsing #{dir}/#{rsrc}"
138
+ @logger.info "\tUsing #{dir}::#{rsrc}"
139
139
  set = get[path]
140
140
  refp,sub,base,rel = map_resource_reference(rsrc)
141
141
  unless refp.nil?
@@ -163,18 +163,7 @@ module Aws
163
163
  next if content.size==0
164
164
 
165
165
  if filename =~ /\.(rb|ruby)\z/i
166
- $Aws_Cfn_Compiler ||= {}
167
- $Aws_Cfn_Compiler[dir] ||= {}
168
- $Aws_Cfn_Compiler[dir][base] ||= {
169
- brick_path: @opts[:directory],
170
- template: @dsl,
171
- logger: @logger
172
- }
173
- source_file = File.expand_path(filename)
174
- eval "require source_file", binding
175
- unless @dsl.dict[dir.to_sym]
176
- raise "Unable to expand #{filename} for #{dir}/#{base}"
177
- end
166
+ compile_rb_file(base, dir, filename)
178
167
  item.merge! @dsl.dict[dir.to_sym]
179
168
  elsif filename =~ /\.js(|on)\z/i
180
169
  item.merge! JSON.parse(content)
@@ -209,6 +198,22 @@ module Aws
209
198
 
210
199
  end
211
200
 
201
+ def compile_rb_file(base, dir, filename)
202
+ Aws::Cfn::Compiler.binding ||= {}
203
+ Aws::Cfn::Compiler.binding[dir] ||= {}
204
+ Aws::Cfn::Compiler.binding[dir][base] ||= {
205
+ brick_path: @config[:directory],
206
+ template: @dsl,
207
+ logger: @logger
208
+ }
209
+ source_file = File.expand_path(filename)
210
+ # source = IO.read(source_file)
211
+ eval "require source_file", binding
212
+ unless @dsl.dict[dir.to_sym]
213
+ abort! "Unable to compile/expand #{filename} for #{dir}/#{base}"
214
+ end
215
+ end
216
+
212
217
  def find_refs(hash, type='Reference', parent='')
213
218
  h = {}
214
219
  newparent = parent
@@ -334,6 +339,9 @@ module Aws
334
339
  if rsrc.match %r'^(\.\./.*?)::(.*)$'
335
340
  # Relative path stack reference
336
341
  path,sub,ref,rel = map_resource_reference(File.basename(rsrc))
342
+ elsif rsrc.match %r'^(~/.*?)$'
343
+ # Relative to HOME
344
+ path,sub,ref,rel = map_resource_reference(File.expand_path(rsrc))
337
345
  elsif rsrc.match %r'^(\.\./[^:]*?)$'
338
346
  # Relative path
339
347
  path = File.dirname(rsrc)
@@ -341,26 +349,26 @@ module Aws
341
349
  path = File.dirname(path)
342
350
  ref = File.basename(rsrc)
343
351
  rel = true
352
+ elsif rsrc.match %r'(^/.*?)::(.*)$'
353
+ # Absolute path
354
+ _,sub,ref,rel = map_resource_reference(File.basename(rsrc))
355
+ path = File.realpath(File.join(File.dirname(rsrc),_))
344
356
  elsif rsrc.match %r'(^/.*?[^:]*?)$'
345
357
  # Absolute path
346
358
  path = File.dirname(rsrc)
347
359
  sub = File.basename(path)
348
360
  path = File.dirname(path)
349
361
  ref = File.basename(rsrc)
350
- elsif rsrc.match %r'(^/.*?)::(.*)$'
351
- # Absolute path
352
- path = File.dirname(rsrc)
353
- ref = map_resource_reference(File.basename(rsrc))
354
362
  elsif (match = rsrc.match %r'^(.*?)::(.*)$')
355
363
  # Inherited stack reference
356
364
  ref = match[2]
357
365
  # noinspection RubyParenthesesAroundConditionInspection
358
366
  if (subm = match[1].match(%r'^(.+?)/(.+)$'))
359
- path = File.join(File.dirname(@opts[:directory]),subm[1])
367
+ path = File.join(File.dirname(@config[:directory]),subm[1])
360
368
  sub = subm[2]
361
369
  else
362
370
  # sub = nil
363
- path = File.join(File.dirname(@opts[:directory]),match[1])
371
+ path = File.join(File.dirname(@config[:directory]),match[1])
364
372
  end
365
373
  else
366
374
  # Otherwise it is what it seems ;)
@@ -371,9 +379,9 @@ module Aws
371
379
 
372
380
  def vet_path(dir,base=nil,rel=false)
373
381
  if rel
374
- base = File.realpath(File.expand_path(File.join(@opts[:directory], base)))
382
+ base = File.realpath(File.expand_path(File.join(@config[:directory], base)))
375
383
  else
376
- base = @opts[:directory] unless base
384
+ base = @config[:directory] unless base
377
385
  end
378
386
  path = nil
379
387
  [dir, dir.downcase].each do |d|
@@ -13,13 +13,24 @@ module Aws
13
13
 
14
14
  @opts = Slop.parse(help: true) do
15
15
  # command File.basename(__FILE__,'.rb')
16
- on :d, :directory=, 'The directory to look in', as: String
16
+ on :d, :directory=, 'The directory containing template sections', as: String
17
17
  on :o, :output=, 'The JSON file to output', as: String
18
18
  on :s, :specification=, 'The specification to use when selecting components. A JSON or YAML file or JSON object', as: String
19
- on :f, :formatversion=, 'The AWS Template format version. Default 2010-09-09', as: String
20
- on :p, :precedence=, 'The precedence of template component types. Default: rb,yaml,yml,json,js', as: String, default: 'rb,ruby,yaml,yml,json,js'
21
- on :t, :description=, "The AWS Template description. Default: output basename or #{File.basename(__FILE__,'.rb')}", as: String
22
- on :x, :expandedpaths=, 'Show expanded paths in output', as: String, default: 'off'
19
+ on :f, :formatversion=, 'The AWS Template format version. ', { as: String,
20
+ optional_argument: true,
21
+ default: '2010-09-09' }
22
+ on :p, :precedence=, 'The precedence of template component types. Default: rb,ruby,yaml,yml,json,js', { as: String,
23
+ default: 'rb,ruby,yaml,yml,json,js' }
24
+ on :t, :description=, "The AWS Template description. Default: output basename or #{File.basename(__FILE__,'.rb')}", { as: String,
25
+ default: File.basename(__FILE__,'.rb') }
26
+ on :x, :expandedpaths, 'Show expanded paths in output', { as: String,
27
+ optional_argument: true,
28
+ default: 'off',
29
+ match: %r/0|1|yes|no|on|off|enable|disable|set|unset|true|false|raw/i }
30
+ on :O, :overwrite, 'Overwrite existing generated source files. (HINT: Think twice ...)', { as: String,
31
+ optional_argument: true,
32
+ default: 'off',
33
+ match: %r/0|1|yes|no|on|off|enable|disable|set|unset|true|false|raw/i }
23
34
  end
24
35
 
25
36
  unless @opts[:directory]
@@ -29,8 +40,9 @@ module Aws
29
40
 
30
41
  @config[:precedence] = @opts[:precedence].split(%r',+\s*').reverse
31
42
  @config[:expandedpaths] = @opts[:expandedpaths].downcase.match %r'^(1|true|on|yes|enable|set)$'
43
+ @config[:directory] = @opts[:directory]
32
44
 
33
- load @opts[:specification]
45
+ load_spec @opts[:specification]
34
46
 
35
47
  desc = @opts[:output] ? File.basename(@opts[:output]).gsub(%r/\.(json|yaml)/, '') : File.basename(__FILE__,'.rb')
36
48
  if @spec and @spec['Description']
@@ -53,7 +65,7 @@ module Aws
53
65
  validate(compiled)
54
66
 
55
67
  output_file = @opts[:output] || 'compiled.json'
56
- save(output_file,compiled)
68
+ save_template(output_file,compiled)
57
69
 
58
70
  @logger.step '*** Compiled Successfully ***'
59
71
  end
@@ -1,7 +1,7 @@
1
1
  module Aws
2
2
  module Cfn
3
3
  module Compiler
4
- VERSION = "0.5.2"
4
+ VERSION = "0.6.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-cfn-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PKinney