aws-cfn-dsl 0.2.0 → 0.5.0

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,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4a3fe04c5cf9704bc7d15981e3a6b711e24511e5
4
- data.tar.gz: 0db31d25dbd543b2a4256d11ac81752c79d927c7
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTRkZGM3ZjljMDFlZDk5NjFkNGNmNjRlYzYwM2ExNTNlNGRhMjM2NQ==
5
+ data.tar.gz: !binary |-
6
+ MDhjZTc2YzRhMmRhMTU2ODg3OGQxZDhmMDU0ZmM4Yzc2MzAzYWRhNA==
5
7
  SHA512:
6
- metadata.gz: d9c7d4f3cd64dad255c1c629de8a3efef649ad18ee5a4702d45453cc182e82330401b0f17c97b5cc60b7a2be92a49b707e379ef5d9566bc4c61e156e0b4939f4
7
- data.tar.gz: 00380934662ed35d83bfbbdf4ab0ca8e8598b95913ed715572df5959700c112a94d5628ef7df696dee85dad967845f500481b032ce6ab8574484093ca86e7c6e
8
+ metadata.gz: !binary |-
9
+ ZDIyMmZkNDQ1ZDFjNWNmZjI0NzEzNTI0MDJhZjIwOTcwZDMyMTkwNjU3MWU2
10
+ MzBlNDAwNjUxZjg0ZjlhODhjMGI2ZGI3NzA2ODAzZjkyYmExZjc2ODFiZTM0
11
+ ZjRjOGRkYTcwYjBjNzY5NjRjYmUyNWIzOTg2NjExOGM4ZjhhNzI=
12
+ data.tar.gz: !binary |-
13
+ ZTI1MmVkZWQzODgwZWVjMTUzMDJmMTcwMmVhZGZiOTRmY2Y0OWEwOWVlYzk0
14
+ ZWJhNzQxYWIxMDkwNDAzMGEzYTU2YzBlMDU1ODhiYzk4YmU2OGYwNzdhMzA3
15
+ MzVkNWQzYTYxZDlkNWVlOGEyMzNiOGU2MDE4Y2ZkMjE4YmRhOTc=
data/Gemfile CHANGED
@@ -4,6 +4,15 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'cloudformation-ruby-dsl', :path => '../cloudformation-ruby-dsl', :group => :development
7
+
8
+ gem 'dldinternet-mixlib-logging', :path => '../dldinternet-mixlib-logging', :group => :development
9
+ gem 'dldinternet-mixlib-cli', :path => '../dldinternet-mixlib-cli', :group => :development
10
+ gem 'aws-cfn-dsl', :path => '../aws-cfn-dsl', :group => :development
11
+ gem 'aws-cfn-decompiler', :path => '../aws-cfn-decompiler', :group => :development
12
+ gem 'aws-cfn-compiler', :path => '../aws-cfn-compiler', :group => :development
13
+ gem 'aws-cfn-yats', :path => '../aws-cfn-yats', :group => :development
14
+ gem 'aws-cfn-stacker', :path => '../aws-cfn-stacker', :group => :development
15
+
7
16
  gem 'slop', :group => :development
8
17
 
9
18
  gem 'json_pure', :group => :development
data/aws-cfn-dsl.iml CHANGED
@@ -8,11 +8,72 @@
8
8
  <content url="file://$MODULE_DIR$" />
9
9
  <orderEntry type="inheritedJdk" />
10
10
  <orderEntry type="sourceFolder" forTests="false" />
11
+ <orderEntry type="module" module-name="aws-cfn-compiler" />
12
+ <orderEntry type="module" module-name="aws-cfn-decompiler" />
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>
30
+ <orderEntry type="module" module-name="aws-cfn-yats" />
11
31
  <orderEntry type="module" module-name="cloudformation-ruby-dsl" />
32
+ <orderEntry type="module-library">
33
+ <library name="dldinternet-mixlib-cli (v0.1.0, /Users/cdelange/Dropbox/DLDInternet/ws/gems-ws/dldinternet-mixlib-cli) [path][gem]">
34
+ <CLASSES>
35
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-cli/bin" />
36
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-cli/lib" />
37
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-cli/pkg" />
38
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-cli/.idea" />
39
+ </CLASSES>
40
+ <JAVADOC />
41
+ <SOURCES>
42
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-cli/bin" />
43
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-cli/lib" />
44
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-cli/pkg" />
45
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-cli/.idea" />
46
+ </SOURCES>
47
+ </library>
48
+ </orderEntry>
49
+ <orderEntry type="module-library">
50
+ <library name="dldinternet-mixlib-logging (v0.2.0, /Users/cdelange/Dropbox/DLDInternet/ws/gems-ws/dldinternet-mixlib-logging) [path][gem]">
51
+ <CLASSES>
52
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-logging/bin" />
53
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-logging/lib" />
54
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-logging/pkg" />
55
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-logging/.idea" />
56
+ </CLASSES>
57
+ <JAVADOC />
58
+ <SOURCES>
59
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-logging/bin" />
60
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-logging/lib" />
61
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-logging/pkg" />
62
+ <root url="file://$MODULE_DIR$/../dldinternet-mixlib-logging/.idea" />
63
+ </SOURCES>
64
+ </library>
65
+ </orderEntry>
12
66
  <orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.2.0, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
67
+ <orderEntry type="library" scope="PROVIDED" name="colorize (v0.7.3, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
13
68
  <orderEntry type="library" scope="PROVIDED" name="detabulator (v0.1.0, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
69
+ <orderEntry type="library" scope="PROVIDED" name="inifile (v2.0.2, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
14
70
  <orderEntry type="library" scope="PROVIDED" name="json (v1.8.1, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
15
71
  <orderEntry type="library" scope="PROVIDED" name="json_pure (v1.8.1, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
72
+ <orderEntry type="library" scope="PROVIDED" name="little-plugger (v1.1.3, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
73
+ <orderEntry type="library" scope="PROVIDED" name="logging (v1.8.2, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
74
+ <orderEntry type="library" scope="PROVIDED" name="mixlib-cli (v1.5.0, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
75
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.10.1, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
76
+ <orderEntry type="library" scope="PROVIDED" name="psych (v2.0.5, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
16
77
  <orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
17
78
  <orderEntry type="library" scope="PROVIDED" name="slop (v3.5.0, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
18
79
  </component>
@@ -1,13 +1,51 @@
1
1
  require "aws/cfn/decompiler"
2
2
  require "aws/cfn/dsl/fncall"
3
3
 
4
+ require 'ap'
5
+
4
6
  module Aws
5
7
  module Cfn
6
8
  module Dsl
7
- class Base < Aws::Cfn::DeCompiler::Base
9
+ class Base
10
+ attr_accessor :items
11
+ attr_reader :output
12
+
13
+ require 'dldinternet/mixlib/logging'
14
+ include DLDInternet::Mixlib::Logging
8
15
 
9
16
  def initialize
17
+ super
10
18
  @output = []
19
+ @config ||= {}
20
+
21
+ lcs = ::Logging::ColorScheme.new( 'compiler', :levels => {
22
+ :trace => :blue,
23
+ :debug => :cyan,
24
+ :info => :green,
25
+ :step => :green,
26
+ :warn => :yellow,
27
+ :error => :red,
28
+ :fatal => :red,
29
+ :todo => :purple,
30
+ })
31
+ scheme = lcs.scheme
32
+ scheme['trace'] = "\e[38;5;33m"
33
+ scheme['fatal'] = "\e[38;5;89m"
34
+ scheme['todo'] = "\e[38;5;55m"
35
+ lcs.scheme scheme
36
+ @config[:log_opts] = lambda{|mlll| {
37
+ :pattern => "%#{mlll}l: %m %C\n",
38
+ :date_pattern => '%Y-%m-%d %H:%M:%S',
39
+ :color_scheme => 'compiler'
40
+ }
41
+ }
42
+ @config[:log_level] = :info
43
+ @logger = getLogger(@config)
44
+
45
+ end
46
+
47
+ def save(path=nil,parts=@items)
48
+ pprint(simplify(parts))
11
49
  end
12
50
 
13
51
  def simplify(val)
@@ -17,32 +55,34 @@ module Aws
17
55
  val
18
56
  else
19
57
  k, v = val.entries[0]
20
- case
21
- # CloudFormation functions
22
- # when k == 'Fn::Base64'
23
- # FnCall.new 'base64', [v], true
24
- # when k == 'Fn::FindInMap'
25
- # FnCall.new 'find_in_map', v
26
- # when k == 'Fn::GetAtt'
27
- # FnCall.new 'get_att', v
28
- # when k == 'Fn::GetAZs'
29
- # FnCall.new 'get_azs', v != '' ? [v] : []
30
- # when k == 'Fn::Join'
31
- # FnCall.new 'join', [v[0]] + v[1], true
32
- # when k == 'Fn::Select'
33
- # FnCall.new 'select', v
34
- # when k == 'Ref' && v == 'AWS::Region'
35
- # FnCall.new 'aws_region', []
36
- # when k == 'Ref' && v == 'AWS::StackName'
37
- # FnCall.new 'aws_stack_name', []
38
- # CloudFormation internal references
39
- # when k == 'Ref'
40
- # FnCall.new 'ref', [v]
41
- # Aws::Cfn::DSL functions
42
- when k.match(%r'^Aws::Cfn::DSL')
43
- FnCall.new k, [v]
44
- else
45
- val
58
+ case @opts[:functions]
59
+ when /1|on|set|enable|yes|true/ then
60
+ case
61
+ # CloudFormation functions
62
+ when k == 'Fn::Base64'
63
+ FnCall.new 'base64', [v], true
64
+ when k == 'Fn::FindInMap'
65
+ FnCall.new 'find_in_map', v
66
+ when k == 'Fn::GetAtt'
67
+ FnCall.new 'get_att', v
68
+ when k == 'Fn::GetAZs'
69
+ FnCall.new 'get_azs', v != '' ? [v] : []
70
+ when k == 'Fn::Join'
71
+ FnCall.new 'join', [v[0]] + v[1], true
72
+ when k == 'Fn::Select'
73
+ FnCall.new 'select', v
74
+ when k == 'Ref' && v == 'AWS::Region'
75
+ FnCall.new 'aws_region', []
76
+ when k == 'Ref' && v == 'AWS::StackName'
77
+ FnCall.new 'aws_stack_name', []
78
+ # CloudFormation internal references
79
+ when k == 'Ref'
80
+ FnCall.new 'ref', [v]
81
+ else
82
+ val
83
+ end
84
+ else
85
+ val
46
86
  end
47
87
  end
48
88
  elsif val.is_a?(Array)
@@ -71,6 +111,12 @@ module Aws
71
111
 
72
112
  protected
73
113
 
114
+ def abort!(msg=nil,rc=1)
115
+ @logger.error msg if msg
116
+ @logger.fatal '!!! Aborting !!!'
117
+ exit rc
118
+ end
119
+
74
120
  def write(*s)
75
121
  if s.is_a?(Array)
76
122
  s = s.join('')
@@ -205,18 +251,22 @@ module Aws
205
251
  def pprint_cfn_resource(name, options)
206
252
  subdir = 'Resources'
207
253
  open_output(subdir,name)
208
- write " resource #{fmt_string(name)}"
254
+ writeln '# noinspection RubyStringKeysInHashInspection'
255
+ writeln "resource #{fmt_string(name)},"
209
256
  indent = ' '
210
257
  options.each do |k, v|
258
+ case k
259
+ when /^(Metadata|Properties)$/
260
+ write "#{indent}#{fmt_key(k)} => "
261
+ pprint_value options[k], indent
262
+ writeln ','
263
+ else
264
+ write "#{indent}#{fmt_key(k)} => "
265
+ writeln "#{fmt(v)},"
266
+ end
211
267
  unless k == 'Properties'
212
- write ", #{fmt_key(k)} => #{fmt(v)}"
213
268
  end
214
269
  end
215
- if options.key?('Properties')
216
- write ", #{fmt_key('Properties')} => "
217
- pprint_value options['Properties'], indent
218
- end
219
- writeln
220
270
  writeln
221
271
  close_output
222
272
  add_brick(subdir,name)
@@ -252,7 +302,7 @@ module Aws
252
302
  end
253
303
  write "#{indent}]"
254
304
 
255
- elsif val.is_a?(FnCall) && val.multiline
305
+ elsif val.is_a?(FnCall) && val.multiline && @opts[:functions] != 'raw'
256
306
  write val.name, "("
257
307
  args = val.arguments
258
308
  sep = ''
@@ -14,14 +14,12 @@ module Aws
14
14
  end
15
15
 
16
16
  unless @opts[:template]
17
- puts @opts
18
- exit
17
+ abort! @opts
19
18
  end
20
19
 
21
- load @opts[:template]
22
-
23
- pprint(simplify(@items))
20
+ load(@opts[:template])
24
21
 
22
+ save(@opts[:output])
25
23
 
26
24
  end
27
25
  end
@@ -70,9 +70,26 @@ module Aws
70
70
  end
71
71
  end
72
72
 
73
- # def output_file(p)
74
- # file "Outputs/#{p}.rb"
75
- # end
73
+ def hash_refs(line)
74
+ match = line.match %r/^(.*?)(\{\s*:\S+\s*=>.*?\}|\{\s*\S+:\s*.*?\})(.*)$/
75
+ if match
76
+ h = nil
77
+ eval "h = #{match[2]}", binding
78
+ k = h.keys[0]
79
+ v = h.delete(k)
80
+ v = if v.is_a?Array
81
+ v.map{|e| e.to_s }
82
+ else
83
+ v.to_s
84
+ end
85
+
86
+ h[k.to_s] = v
87
+ VARS[:logger].debug h
88
+ [match[1], h, hash_refs(match[3]) ]
89
+ else
90
+ "#{line}\n"
91
+ end
92
+ end
76
93
 
77
94
  def exec!(argv=ARGV)
78
95
  @opts = Slop.parse(help: true) do
@@ -1,7 +1,7 @@
1
1
  module Aws
2
2
  module Cfn
3
3
  module Dsl
4
- VERSION = "0.2.0"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,75 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-cfn-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christo DeLange
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-27 00:00:00.000000000 Z
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cloudformation-ruby-dsl
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.4'
48
- - - ">="
48
+ - - ! '>='
49
49
  - !ruby/object:Gem::Version
50
50
  version: 0.4.3
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - "~>"
55
+ - - ~>
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0.4'
58
- - - ">="
58
+ - - ! '>='
59
59
  - !ruby/object:Gem::Version
60
60
  version: 0.4.3
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: slop
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - ! '>='
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - ! '>='
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  description: Ruby DSL for creating Cloudformation templates
@@ -80,7 +80,7 @@ executables:
80
80
  extensions: []
81
81
  extra_rdoc_files: []
82
82
  files:
83
- - ".gitignore"
83
+ - .gitignore
84
84
  - Gemfile
85
85
  - LICENSE
86
86
  - LICENSE.txt
@@ -125,12 +125,12 @@ require_paths:
125
125
  - lib
126
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - ">="
128
+ - - ! '>='
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
- - - ">="
133
+ - - ! '>='
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []