aws-cfn-decompiler 0.2.5 → 0.5.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
- N2I5ZjkyZGMzMGRjYTRmZDMxNTg0OGQ0ZjVkY2VmNGZlZDY2ZDFlNQ==
4
+ ZWU4ODg1ZTFhZjYyNGYxZjE3ODA0YjNiYjVhZWMyZmRjYTIxODE0Yw==
5
5
  data.tar.gz: !binary |-
6
- NjBmNmQ2NGZhNTQ1NGZkZjBhNjhjMzFlODhlOGM5NmRiZjJlNzNiYg==
6
+ YjUzZGE4NjhhZDQ1Y2UyZGIyN2Q2NjkwYzE0NWYxODc1YTg1YmMyZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDMyODkyZmYzZjc5ODI2ZWMzYWZmZWY5NDlkNTNkOWNiNWRhZWEyZTg2Zjlh
10
- YTAyZDY0ODAyNTQxNTdjMjQ5YzIyMTJlNjhhZWE4M2E1NDE2NGNjMjJmMGM0
11
- M2NlOTViNDg3ZWEyOWRjNjM4MGI4MzE5MDY4YzBlYWVjZTJhOWY=
9
+ NDM3ZTBlNzAyYzhiYTRhMGMyYjA3NTUxOTYwMWUxYzc3NDlkN2ZmZTU2ZTQ1
10
+ OGU4ZWFkNzljZTJhNmViYjhkZjFmMmRmZTdmOTY4NDM0OGU5OTQ3NTk3MjVj
11
+ NjFiZTk5YTMyY2I0YTc3ODZiYTFmYjEwZDZiNmJhYjUzMDU3MWQ=
12
12
  data.tar.gz: !binary |-
13
- NTIxNTFlMTdlMjRlMGRjZGUzYWRmYjhkODRiOTRlYjJjOTQyMGNjNjk5NWIy
14
- YWZhN2FmNmI1YTlhOWM1NjMwMDI5MzNhZGViMmVkM2IwMDFkYThiYTZlMTg3
15
- ZjE4MzQ3ZjgyODc5OTFhMjRkYWI4MGY1NWUwODY3OTkwNmZlYzQ=
13
+ ZGQ4NjFmYjVmZDZlMWUwYjM4ZDM5ODA2NDljOGU1MjlhNjI2YWE2NzM3MDlk
14
+ OWM2NzE3ZWZmNTg5MzhlMmNkYzUyZWU3ZDJhODQ3MjVjYzJlNjgzZjU2MzRj
15
+ MTVkNWJlNjA3ODFlOWVmYmQzMjlmZjM4ODk3ZDQ4MzdkNzM3OTE=
@@ -18,13 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "awesome_print"
21
+ spec.add_dependency "awesome_print", '~> 1.2', '>= 1.2.0'
22
22
  spec.add_dependency "psych"
23
23
  spec.add_dependency "json"
24
- spec.add_dependency 'aws-cfn-compiler', '>= 0.3.1', '~> 0.2'
25
24
  spec.add_dependency "slop"
25
+ spec.add_dependency 'aws-cfn-compiler', '>= 0.5.0', '~> 0.5'
26
26
 
27
- spec.add_development_dependency "json_pure"
28
- spec.add_development_dependency 'bundler', "~> 1.6"
29
- spec.add_development_dependency 'rake'
30
27
  end
@@ -3,24 +3,12 @@
3
3
  <component name="CompassSettings">
4
4
  <option name="compassSupportEnabled" value="true" />
5
5
  </component>
6
- <component name="FacetManager">
7
- <facet type="gem" name="Ruby Gem">
8
- <configuration>
9
- <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
10
- <option name="GEM_APP_TEST_PATH" value="$MODULE_DIR$/test" />
11
- <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
12
- </configuration>
13
- </facet>
14
- </component>
15
6
  <component name="NewModuleRootManager" inherit-compiler-output="true">
16
7
  <exclude-output />
17
- <content url="file://$MODULE_DIR$">
18
- <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
19
- </content>
8
+ <content url="file://$MODULE_DIR$" />
20
9
  <orderEntry type="jdk" jdkName="RVM: ruby-1.9.3-p547 [aws-cfn-decompiler]" jdkType="RUBY_SDK" />
21
10
  <orderEntry type="sourceFolder" forTests="false" />
22
11
  <orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.2.0, RVM: ruby-1.9.3-p547 [aws-cfn-decompiler]) [gem]" level="application" />
23
- <orderEntry type="library" scope="PROVIDED" name="aws-cfn-compiler (v0.3.0, RVM: ruby-1.9.3-p547 [aws-cfn-decompiler]) [gem]" level="application" />
24
12
  <orderEntry type="library" scope="PROVIDED" name="aws-cfn-dsl (v0.0.4, RVM: ruby-1.9.3-p547 [aws-cfn-decompiler]) [gem]" level="application" />
25
13
  <orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.2, RVM: ruby-1.9.3-p547 [aws-cfn-decompiler]) [gem]" level="application" />
26
14
  <orderEntry type="library" scope="PROVIDED" name="cloudformation-ruby-dsl (v0.4.3, RVM: ruby-1.9.3-p547 [aws-cfn-decompiler]) [gem]" level="application" />
@@ -2,27 +2,30 @@
2
2
 
3
3
  require 'rubygems'
4
4
 
5
- # require 'safe_yaml'
6
- # SafeYAML::OPTIONS[:default_mode] = :safe
7
-
5
+ path = File.dirname(__FILE__)
6
+ if File.exists?("#{path}/../.gitignore")
7
+ %w(aws-cfn-dsl aws-cfn-compiler cloudformation-ruby-dsl).each do |mod|
8
+ add_path = File.expand_path(File.join(path, "../../#{mod}", "lib"))
9
+ $:.unshift(add_path)
10
+ end
11
+ else
8
12
  # Borrowing from "whiches" gem ...
9
- cmd = File.basename(__FILE__, '.rb')
10
- exes = []
11
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
12
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
13
- exts.each { |ext|
14
- exe = File.join(path, "#{cmd}#{ext}")
15
- exes << exe if File.executable? exe
16
- }
17
- end
18
- path = if exes.size > 0
19
- File.dirname(exes[0])
20
- else
21
- File.dirname(__FILE__)
22
- end
13
+ cmd = File.basename(__FILE__, '.rb')
14
+ exes = []
15
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
16
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
17
+ exts.each { |ext|
18
+ exe = File.join(path, "#{cmd}#{ext}")
19
+ exes << exe if File.executable? exe
20
+ }
21
+ end
22
+ if exes.size > 0
23
+ path = File.dirname(exes[0])
24
+ end
23
25
 
26
+ end
24
27
  add_path = File.expand_path(File.join(path, "..", "lib"))
25
28
  $:.unshift(add_path)
26
29
 
27
30
  require 'aws/cfn/decompiler'
28
- Aws::Cfn::DeCompiler::Main.new().run
31
+ Aws::Cfn::DeCompiler::Main.new.run
@@ -1,142 +1,4 @@
1
1
  require "aws/cfn/decompiler/version"
2
- require "aws/cfn/compiler"
2
+ require "aws/cfn/decompiler/base"
3
+ require "aws/cfn/decompiler/main"
3
4
 
4
- require 'json'
5
- require 'ap'
6
- require 'yaml'
7
- require 'slop'
8
-
9
- module Aws
10
- module Cfn
11
- module DeCompiler
12
- class Main < Aws::Cfn::Compiler::Main
13
- attr_accessor :template
14
-
15
- def run
16
-
17
- @opts = Slop.parse(help: true, strict: true) do
18
- on :j, :template=, 'The template to decompile', as: String
19
- on :o, :output=, 'The directory to output the components to.', as: String
20
- on :f, :format=, 'The output format of the components. [JSON|YAML]', as: String, match: %r/yaml|json/i
21
- on :s, :specification=, 'The specification file to create.', as: String
22
- end
23
-
24
- unless @opts[:template]
25
- puts @opts
26
- exit
27
- end
28
- unless @opts[:output].nil?
29
- unless File.directory?(@opts[:output])
30
- puts @opts
31
- exit
32
- end
33
- end
34
-
35
- load @opts[:template]
36
-
37
- puts
38
- puts 'Validating decompiled file...'
39
-
40
- validate(@items)
41
-
42
- output_dir = @opts[:output] || Dir.pwd
43
- puts
44
- puts "Writing decompiled parts to #{output_dir}..."
45
- save(output_dir)
46
-
47
- puts
48
- puts '*** Decompiled Successfully ***'
49
- end
50
-
51
- def save(output_dir)
52
-
53
- specification = {}
54
- format = @opts[:format] rescue 'yaml'
55
- @items.each do |section, section_items|
56
- case section
57
- when /Mappings|Parameters|Resources|Outputs/
58
- specification[section] = []
59
- section_items.each do |name,value|
60
- dir = File.join(output_dir,section.to_s)
61
- unless File.directory?(dir)
62
- Dir.mkdir(dir)
63
- end
64
- file = "#{name}.#{format}"
65
- hash = { name => value }
66
-
67
- save_section(dir, file, format, section, hash)
68
- specification[section] << name
69
- end
70
- when /AWSTemplateFormatVersion|Description/
71
- specification[section] = section_items
72
- else
73
- raise "ERROR: Unsupported section '#{section}' in template"
74
- end
75
-
76
- end
77
-
78
- # Save specification
79
- unless @opts[:specification].nil?
80
- dir = File.dirname(@opts[:specification])
81
- dir = output_dir unless dir
82
- save_section(dir, File.basename(@opts[:specification]), format, '', specification, "Specification to #{dir}/")
83
- end
84
-
85
- end
86
-
87
- def save_section(dir, file, format, section, hash, join='/')
88
- path = File.join(dir, file)
89
-
90
- begin
91
- # File.delete path if File.exists? path
92
- File.open path, File::CREAT|File::TRUNC|File::RDWR, 0644 do |f|
93
- case format
94
- when /json/
95
- f.write JSON.pretty_generate(compiled)
96
- when /yaml/
97
- f.write hash.to_yaml line_width: 1024, indentation: 4, canonical: false
98
- else
99
- raise "Unsupported format #{format}. Should have noticed this earlier!"
100
- end
101
- f.close
102
- end
103
- puts " decompiled #{section}#{join}#{file}."
104
- rescue
105
- puts "!!! Could not write compiled file #{path}: #{$!}"
106
- abort!
107
- end
108
- end
109
-
110
- def load(file=nil)
111
- if file
112
- begin
113
- abs = File.absolute_path(File.expand_path(file))
114
- unless File.exists?(abs) or @opts[:output].nil?
115
- abs = File.absolute_path(File.expand_path(File.join(@opts[:output],file)))
116
- end
117
- rescue
118
- # pass
119
- end
120
- if File.exists?(abs)
121
- case File.extname(File.basename(abs)).downcase
122
- when /json/
123
- template = JSON.parse(File.read(abs))
124
- when /yaml/
125
- template = YAML.load(File.read(abs))
126
- else
127
- raise "Unsupported file type for specification: #{file}"
128
- end
129
- @items = template
130
- else
131
- raise "Unable to open template: #{abs}"
132
- end
133
- end
134
- end
135
-
136
- protected
137
-
138
-
139
- end
140
- end
141
- end
142
- end
@@ -0,0 +1,114 @@
1
+ require "aws/cfn/decompiler/version"
2
+ require "aws/cfn/compiler"
3
+
4
+ require 'json'
5
+ require 'ap'
6
+ require 'yaml'
7
+
8
+ module Aws
9
+ module Cfn
10
+ module DeCompiler
11
+ class Base < ::Aws::Cfn::Compiler::Base
12
+ attr_accessor :template
13
+
14
+ def save(output_dir)
15
+
16
+ specification = {}
17
+ format = @opts[:format] rescue 'yaml'
18
+ @items.each do |section, section_items|
19
+ case section
20
+ when /Mappings|Parameters|Resources|Outputs/
21
+ specification[section] = []
22
+ section_items.each do |name,value|
23
+ dir = File.join(output_dir,section.to_s)
24
+ unless File.directory?(dir)
25
+ Dir.mkdir(dir)
26
+ end
27
+ file = "#{name}.#{format}"
28
+ hash = { name => value }
29
+
30
+ save_section(dir, file, format, section, hash)
31
+ specification[section] << name
32
+ end
33
+ when /AWSTemplateFormatVersion|Description/
34
+ specification[section] = section_items
35
+ else
36
+ raise "ERROR: Unsupported section '#{section}' in template"
37
+ end
38
+
39
+ end
40
+
41
+ # Save specification
42
+ unless @opts[:specification].nil?
43
+ dir = File.dirname(@opts[:specification])
44
+ dir = output_dir unless dir
45
+ save_section(dir, File.basename(@opts[:specification]), format, '', specification, "Specification to #{dir}/")
46
+ end
47
+
48
+ end
49
+
50
+ def save_section(dir, file, format, section, hash, join='/')
51
+ path = File.join(dir, file)
52
+
53
+ begin
54
+ # File.delete path if File.exists? path
55
+ File.open path, File::CREAT|File::TRUNC|File::RDWR, 0644 do |f|
56
+ case format
57
+ when /json/
58
+ f.write JSON.pretty_generate(compiled)
59
+ when /yaml/
60
+ f.write hash.to_yaml line_width: 1024, indentation: 4, canonical: false
61
+ else
62
+ raise "Unsupported format #{format}. Should have noticed this earlier!"
63
+ end
64
+ f.close
65
+ end
66
+ puts " decompiled #{section}#{join}#{file}."
67
+ rescue
68
+ puts "!!! Could not write compiled file #{path}: #{$!}"
69
+ abort!
70
+ end
71
+ end
72
+
73
+ def decompile(file=nil)
74
+ load file
75
+
76
+ puts
77
+ puts 'Validating decompiled file...'
78
+
79
+ validate(@items)
80
+
81
+ end
82
+
83
+ def load(file=nil)
84
+ if 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/
96
+ template = JSON.parse(File.read(abs))
97
+ when /yaml/
98
+ template = YAML.load(File.read(abs))
99
+ else
100
+ raise "Unsupported file type for specification: #{file}"
101
+ end
102
+ @items = template
103
+ else
104
+ raise "Unable to open template: #{abs}"
105
+ end
106
+ end
107
+ end
108
+
109
+ protected
110
+
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,49 @@
1
+ require "aws/cfn/decompiler/version"
2
+ require "aws/cfn/decompiler/base"
3
+
4
+ require 'slop'
5
+
6
+ module Aws
7
+ module Cfn
8
+ module DeCompiler
9
+ class Main < Base
10
+ attr_accessor :template
11
+
12
+ def run
13
+
14
+ @opts = Slop.parse(help: true, strict: true) do
15
+ on :j, :template=, 'The template to decompile', as: String
16
+ on :o, :output=, 'The directory to output the components to.', as: String
17
+ on :f, :format=, 'The output format of the components. [JSON|YAML|Ruby]', as: String, match: %r/yaml|json|ruby/i
18
+ on :s, :specification=, 'The specification file to create.', as: String
19
+ end
20
+
21
+ unless @opts[:template]
22
+ puts @opts
23
+ exit
24
+ end
25
+ unless @opts[:output].nil?
26
+ unless File.directory?(@opts[:output])
27
+ puts @opts
28
+ exit
29
+ end
30
+ end
31
+
32
+ decompile @opts[:template]
33
+
34
+ output_dir = @opts[:output] || Dir.pwd
35
+ puts
36
+ puts "Writing decompiled parts to #{output_dir}..."
37
+ save(output_dir)
38
+
39
+ puts
40
+ puts '*** Decompiled Successfully ***'
41
+ end
42
+
43
+ protected
44
+
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,7 +1,7 @@
1
1
  module Aws
2
2
  module Cfn
3
3
  module DeCompiler
4
- VERSION = "0.2.5"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-cfn-decompiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christo De Lange
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2014-06-27 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
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
17
20
  - - ! '>='
18
21
  - !ruby/object:Gem::Version
19
- version: '0'
22
+ version: 1.2.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
24
30
  - - ! '>='
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 1.2.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: psych
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -52,26 +58,6 @@ dependencies:
52
58
  - - ! '>='
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: aws-cfn-compiler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: 0.3.1
62
- - - ~>
63
- - !ruby/object:Gem::Version
64
- version: '0.2'
65
- type: :runtime
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - ! '>='
70
- - !ruby/object:Gem::Version
71
- version: 0.3.1
72
- - - ~>
73
- - !ruby/object:Gem::Version
74
- version: '0.2'
75
61
  - !ruby/object:Gem::Dependency
76
62
  name: slop
77
63
  requirement: !ruby/object:Gem::Requirement
@@ -87,47 +73,25 @@ dependencies:
87
73
  - !ruby/object:Gem::Version
88
74
  version: '0'
89
75
  - !ruby/object:Gem::Dependency
90
- name: json_pure
76
+ name: aws-cfn-compiler
91
77
  requirement: !ruby/object:Gem::Requirement
92
78
  requirements:
93
79
  - - ! '>='
94
80
  - !ruby/object:Gem::Version
95
- version: '0'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ! '>='
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- - !ruby/object:Gem::Dependency
104
- name: bundler
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
81
+ version: 0.5.0
107
82
  - - ~>
108
83
  - !ruby/object:Gem::Version
109
- version: '1.6'
110
- type: :development
84
+ version: '0.5'
85
+ type: :runtime
111
86
  prerelease: false
112
87
  version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ~>
115
- - !ruby/object:Gem::Version
116
- version: '1.6'
117
- - !ruby/object:Gem::Dependency
118
- name: rake
119
- requirement: !ruby/object:Gem::Requirement
120
88
  requirements:
121
89
  - - ! '>='
122
90
  - !ruby/object:Gem::Version
123
- version: '0'
124
- type: :development
125
- prerelease: false
126
- version_requirements: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - ! '>='
91
+ version: 0.5.0
92
+ - - ~>
129
93
  - !ruby/object:Gem::Version
130
- version: '0'
94
+ version: '0.5'
131
95
  description: The idea is to extract a big CloudFormation template into a folder structure
132
96
  to better manage pieces of a CloudFormation deployment. Additionally, writing in
133
97
  JSON is hard, so the decompiler can create YAML files as well.
@@ -163,6 +127,8 @@ files:
163
127
  - example/resources/subnets.json
164
128
  - example/resources/vpc.json
165
129
  - lib/aws/cfn/decompiler.rb
130
+ - lib/aws/cfn/decompiler/base.rb
131
+ - lib/aws/cfn/decompiler/main.rb
166
132
  - lib/aws/cfn/decompiler/version.rb
167
133
  homepage: https://github.com/dldinternet/aws-cfn-decompiler
168
134
  licenses: