aws-cfn-decompiler 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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f180799b3fab6757e8326a52443d9ecf0606663b
4
- data.tar.gz: c0580cd70f1f96a1e6a92f6f93b4e5f6c85c8eb4
3
+ metadata.gz: 7aeb28a3e087cf7ada2d2842283f27c34076fa70
4
+ data.tar.gz: 756e2950012c76c57c6ade2965096d5fe25b265b
5
5
  SHA512:
6
- metadata.gz: 9707cc9a2f5b7070f30125f631d69a479a342abeba846fb011134883079f730022cc8fd9cc620eb1cb05d11294b47eaede28c902cc8f87bef80b5b6da121b27c
7
- data.tar.gz: bb86570d78d67a89bb1b74496de78d1f07f969bec5e59b6b31dc65033062d1b91d8710aea71469c0f10f81cd893379a29c6aead221c3497cb1edb136532c65c6
6
+ metadata.gz: 2bc4574d3bcbfaaef555a4b6ae54862508f83fe33c0ea25b7235abb399e5b7a1b59d5f967cb1fb7a5928cd6b9dd9cab360217ce43ad876800c7b37290a79ce32
7
+ data.tar.gz: 9a7d623cf3adfd4f88aeae49a43abe388e1c3a9fa520e37daf05b41d842ff34b3825cccf814e0a3eab896c79d51b1de2dee99e54dcdb42c7775f38c437b4b9d6
@@ -10,23 +10,7 @@
10
10
  <orderEntry type="sourceFolder" forTests="false" />
11
11
  <orderEntry type="module" module-name="aws-cfn-compiler" />
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">
@@ -11,18 +11,20 @@ module Aws
11
11
  class Base < ::Aws::Cfn::Compiler::Base
12
12
  attr_accessor :template
13
13
 
14
- def save(output_dir)
14
+ def save_dsl(output_dir)
15
15
 
16
16
  specification = {}
17
17
  format = @opts[:format] rescue 'yaml'
18
- if format.match(%r'^ruby|rb$')
18
+ ruby = (not format.match(%r'^ruby|rb$').nil?)
19
+ if ruby
19
20
  pprint_cfn_template simplify(@items)
20
- else
21
- @items.each do |section, section_items|
22
- case section
23
- when /Mappings|Parameters|Resources|Outputs/
24
- specification[section] = []
25
- section_items.each do |name,value|
21
+ end
22
+ @items.each do |section, section_items|
23
+ case section
24
+ when /Mappings|Parameters|Resources|Outputs/
25
+ specification[section] = []
26
+ section_items.each do |name,value|
27
+ unless ruby
26
28
  dir = File.join(output_dir,section.to_s)
27
29
  unless File.directory?(dir)
28
30
  Dir.mkdir(dir)
@@ -31,82 +33,56 @@ module Aws
31
33
  hash = { name => value }
32
34
 
33
35
  save_section(dir, file, format, section, hash)
34
- specification[section] << name
35
36
  end
36
- when /AWSTemplateFormatVersion|Description/
37
- specification[section] = section_items
38
- else
39
- abort! "Unsupported section '#{section}' in template"
40
- end
41
-
37
+ specification[section] << name
38
+ end
39
+ when /AWSTemplateFormatVersion|Description/
40
+ specification[section] = section_items
41
+ else
42
+ abort! "Unsupported section '#{section}' in template"
42
43
  end
44
+ end
43
45
 
44
- # Save specification
45
- unless @opts[:specification].nil?
46
- dir = File.dirname(@opts[:specification])
47
- dir = output_dir unless dir
48
- save_section(dir, File.basename(@opts[:specification]), format, '', specification, "Specification to #{dir}/")
49
- end
46
+ # Save specification
47
+ unless @opts[:specification].nil?
48
+ dir = File.dirname(@opts[:specification])
49
+ dir = output_dir unless dir
50
+ save_section(dir, File.basename(@opts[:specification]), format, '', specification, "Specification in #{dir}/")
50
51
  end
51
52
 
52
53
  end
53
54
 
55
+ protected
56
+
54
57
  def save_section(dir, file, format, section, hash, join='/')
55
58
  logStep "Saving section #{hash.keys[0]} to #{section}/#{file} "
56
59
  path = File.join(dir, file)
57
60
 
58
61
  begin
59
- # File.delete path if File.exists? path
60
- File.open path, File::CREAT|File::TRUNC|File::RDWR, 0644 do |f|
61
- case format
62
- when /ruby|rb/
63
- @output.unshift f
64
- pprint(hash)
65
- @output.shift
66
- when /json|js/
67
- f.write JSON.pretty_generate(hash)
68
- when /yaml|yml/
69
- f.write hash.to_yaml line_width: 1024, indentation: 4, canonical: false
70
- else
71
- raise "Unsupported format #{format}. Should have noticed this earlier!"
72
- end
73
- f.close
74
- end
75
- puts " decompiled #{section}#{join}#{file}."
76
- rescue
77
- puts "!!! Could not write compiled file #{path}: #{$!}"
78
- abort!
79
- end
80
- end
81
-
82
- def load(file=nil)
83
- if file
84
- logStep "Loading #{file}"
85
- begin
86
- abs = File.absolute_path(File.expand_path(file))
87
- unless File.exists?(abs) or @opts[:output].nil?
88
- abs = File.absolute_path(File.expand_path(File.join(@opts[:output],file)))
89
- end
90
- rescue
91
- # pass
92
- end
93
- if File.exists?(abs)
94
- case File.extname(File.basename(abs)).downcase
95
- when /json|js/
96
- @items = JSON.parse(File.read(abs))
97
- when /yaml|yml/
98
- @items = YAML.load(File.read(abs))
99
- else
100
- abort! "Unsupported file type for specification: #{file}"
62
+ if i_am_maintainer(path)
63
+ # File.delete path if File.exists? path
64
+ File.open path, File::CREAT|File::TRUNC|File::RDWR, 0644 do |f|
65
+ case format
66
+ when /ruby|rb|yaml|yml/
67
+ f.write maintainer_comment('')
68
+ f.write hash.to_yaml line_width: 1024, indentation: 4, canonical: false
69
+ when /json|js/
70
+ # You wish ... f.write maintainer_comment('')
71
+ f.write JSON.pretty_generate(hash)
72
+ else
73
+ abort! "Internal: Unsupported format #{format}. Should have noticed this earlier!"
74
+ end
75
+ f.close
101
76
  end
77
+ @logger.info " decompiled #{section}#{join}#{file}."
102
78
  else
103
- abort! "Unable to open template: #{abs}"
79
+ @logger.warn " Did not overwrite #{section}#{join}#{file}."
104
80
  end
81
+ rescue
82
+ abort! "!!! Could not write compiled file #{path}: #{$!}"
105
83
  end
106
84
  end
107
85
 
108
- protected
109
-
110
86
  end
111
87
  end
112
88
  end
@@ -18,9 +18,20 @@ module Aws
18
18
  on :f, :format=, 'The output format of the components. [JSON|YAML|Ruby]', as: String, match: %r/ruby|rb|yaml|yml|json|js/i
19
19
  on :s, :specification=, 'The specification file to create.', as: String
20
20
  on :n, :functions=, 'Enable function use.', as: String, match: %r/0|1|yes|no|on|off|enable|disable|set|unset|true|false|raw/i
21
+ on :O, :overwrite, 'Overwrite existing generated source files. (HINT: Think twice ...)', { as: String, optional_argument: true, default: 'off', match: %r/0|1|yes|no|on|off|enable|disable|set|unset|true|false|raw/i }
21
22
  end
22
23
 
23
- @config[:functions] = @opts[:functions].downcase.match %r'^(1|true|on|yes|enable|set)$'
24
+ @config[:overwrite] = if @opts[:overwrite].downcase.match %r'^(1|true|on|yes|enable|set)$'
25
+ true
26
+ else
27
+ false
28
+ end
29
+ @config[:functions] = if @opts[:functions]
30
+ (not @opts[:functions].downcase.match(%r'^(1|true|on|yes|enable|set)$').nil?)
31
+ else
32
+ false
33
+ end
34
+ @config[:directory] = @opts[:output]
24
35
 
25
36
  unless @opts[:template]
26
37
  @logger.error @opts
@@ -37,12 +48,12 @@ module Aws
37
48
  end
38
49
  end
39
50
 
40
- load @opts[:template]
51
+ load_template @opts[:template]
41
52
 
42
53
  validate(@items)
43
54
 
44
55
  output_dir = @opts[:output] || Dir.pwd
45
- save(output_dir)
56
+ save_dsl(output_dir)
46
57
 
47
58
  @logger.step '*** Decompiled Successfully ***'
48
59
  end
@@ -1,7 +1,7 @@
1
1
  module Aws
2
2
  module Cfn
3
3
  module DeCompiler
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-decompiler
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
  - Christo De Lange