aws-cfn-decompiler 0.5.2 → 0.6.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 +4 -4
- data/aws-cfn-decompiler.iml +1 -17
- data/lib/aws/cfn/decompiler/base.rb +42 -66
- data/lib/aws/cfn/decompiler/main.rb +14 -3
- data/lib/aws/cfn/decompiler/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aeb28a3e087cf7ada2d2842283f27c34076fa70
|
4
|
+
data.tar.gz: 756e2950012c76c57c6ade2965096d5fe25b265b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bc4574d3bcbfaaef555a4b6ae54862508f83fe33c0ea25b7235abb399e5b7a1b59d5f967cb1fb7a5928cd6b9dd9cab360217ce43ad876800c7b37290a79ce32
|
7
|
+
data.tar.gz: 9a7d623cf3adfd4f88aeae49a43abe388e1c3a9fa520e37daf05b41d842ff34b3825cccf814e0a3eab896c79d51b1de2dee99e54dcdb42c7775f38c437b4b9d6
|
data/aws-cfn-decompiler.iml
CHANGED
@@ -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-
|
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
|
14
|
+
def save_dsl(output_dir)
|
15
15
|
|
16
16
|
specification = {}
|
17
17
|
format = @opts[:format] rescue 'yaml'
|
18
|
-
|
18
|
+
ruby = (not format.match(%r'^ruby|rb$').nil?)
|
19
|
+
if ruby
|
19
20
|
pprint_cfn_template simplify(@items)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
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[:
|
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
|
-
|
51
|
+
load_template @opts[:template]
|
41
52
|
|
42
53
|
validate(@items)
|
43
54
|
|
44
55
|
output_dir = @opts[:output] || Dir.pwd
|
45
|
-
|
56
|
+
save_dsl(output_dir)
|
46
57
|
|
47
58
|
@logger.step '*** Decompiled Successfully ***'
|
48
59
|
end
|