aws-cfn-compiler 0.0.3 → 0.0.4

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,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e475a82e8e4ec0c15474b19670a80d0248cdb438
4
- data.tar.gz: 68511f24b75c51d805292ca3a3843944d064c0d0
3
+ metadata.gz: 673fc4ca1fb32bdf4d0cd901c871f90ac7ad5190
4
+ data.tar.gz: 279e4d973d987754067c8cd953bacb94a692d220
5
5
  SHA512:
6
- metadata.gz: 9f34e56e832af14e2153713f10d2e2b7193aa68f75b416100141c40214f59ae4fc48fdd1a1cca06996e9a51f43118594055baebbb964740ae22e466bd86757b6
7
- data.tar.gz: 46dfbb1fde0098468d40778996324c8a5b7a734ad94be1d3e8044784f33e65c72bd12599978eea50943ee91fe145803cc0b146da3ee7239591f0ef5d2b5d6ec4
6
+ metadata.gz: 7b2f4148f025221973449b2023b47288245ac36628cc67cc87a83f2fbd618f06668184813d868b515ce52c2094817ef8552f797f7b73bc3f357d9508839fa09a
7
+ data.tar.gz: 824819dad7a1c603df967fd082eb1e8d58a6a1d8f4bbba95ff3c0d4b98bfaef87ddaccff7487aa3bfa7b4787cc992ae21a30d0de2411e81d4add7db6bcc74b08
data/aws-cfn-compiler.iml CHANGED
@@ -6,20 +6,23 @@
6
6
  <component name="FacetManager">
7
7
  <facet type="gem" name="Ruby Gem">
8
8
  <configuration>
9
- <option name="GEM_APP_ROOT_PATH" value="" />
9
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
10
10
  <option name="GEM_APP_TEST_PATH" value="" />
11
- <option name="GEM_APP_LIB_PATH" value="" />
11
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
12
12
  </configuration>
13
13
  </facet>
14
14
  </component>
15
15
  <component name="NewModuleRootManager" inherit-compiler-output="true">
16
16
  <exclude-output />
17
17
  <content url="file://$MODULE_DIR$" />
18
- <orderEntry type="jdk" jdkName="RVM: ruby-2.1.2" jdkType="RUBY_SDK" />
18
+ <orderEntry type="jdk" jdkName="RVM: ruby-1.9.3-p547 [aws-cfn-compile]" jdkType="RUBY_SDK" />
19
19
  <orderEntry type="sourceFolder" forTests="false" />
20
- <orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.2.0, RVM: ruby-2.1.2) [gem]" level="application" />
21
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.2, RVM: ruby-2.1.2) [gem]" level="application" />
22
- <orderEntry type="library" scope="PROVIDED" name="slop (v3.5.0, RVM: ruby-2.1.2) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="awesome_print (v1.2.0, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.2, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="json (v1.8.1, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="psych (v2.0.5, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.1.0, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="slop (v3.5.0, RVM: ruby-1.9.3-p547 [aws-cfn-compile]) [gem]" level="application" />
23
26
  </component>
24
27
  </module>
25
28
 
@@ -1,7 +1,7 @@
1
1
  module Aws
2
2
  module Cfn
3
3
  module Compiler
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
6
6
  end
7
7
  end
@@ -11,6 +11,7 @@ module Aws
11
11
  class Main
12
12
  attr_accessor :items
13
13
  attr_accessor :opts
14
+ attr_accessor :spec
14
15
 
15
16
  def initialize
16
17
  @items = {}
@@ -21,6 +22,7 @@ module Aws
21
22
  @opts = Slop.parse(help: true) do
22
23
  on :d, :directory=, 'The directory to look in', as: String
23
24
  on :o, :output=, 'The JSON file to output', as: String
25
+ on :s, :specification=, 'The specification to use when selecting components. A JSON or YAML file or JSON object', as: String
24
26
  end
25
27
 
26
28
  unless @opts[:directory]
@@ -28,43 +30,45 @@ module Aws
28
30
  exit
29
31
  end
30
32
 
31
- load
33
+ load @opts[:specification]
32
34
 
33
35
  compiled = {
34
- AWSTemplateFormatVersion: "2010-09-09",
35
- Description: "Description goes here",
36
+ AWSTemplateFormatVersion: '2010-09-09',
37
+ Description: 'Description goes here',
36
38
  Parameters: @items['params'],
37
39
  Mappings: @items['mappings'],
38
40
  Resources: @items['resources'],
39
41
  Outputs: @items['outputs'],
40
42
  }
41
43
 
42
- output_file = @opts[:output] || "compiled.json"
44
+ output_file = @opts[:output] || 'compiled.json'
43
45
  puts
44
46
  puts "Writing compiled file to #{output_file}..."
45
47
  save(compiled, output_file)
46
48
 
47
49
  puts
48
- puts "Validating compiled file..."
50
+ puts 'Validating compiled file...'
49
51
 
50
52
  validate(compiled)
51
53
 
52
54
  puts
53
- puts "*** Compiled Successfully ***"
55
+ puts '*** Compiled Successfully ***'
54
56
  end
55
57
 
56
58
  def validate(compiled)
57
- names = compiled["Resources"].keys + compiled["Parameters"].keys
59
+ raise 'No resources!?' unless compiled[:Resources]
60
+ raise 'No parameters!?' unless compiled[:Parameters]
61
+ names = compiled[:Resources].keys + compiled[:Parameters].keys
58
62
  refs = find_refs(compiled).select { |a| !(a =~ /^AWS::/) }
59
63
 
60
64
  unless (refs-names).empty?
61
- puts "!!! Unknown references !!!"
65
+ puts '!!! Unknown references !!!'
62
66
  (refs-names).each do |name|
63
67
  puts " #{name}"
64
68
  end
65
69
  abort!
66
70
  end
67
- puts " References validated"
71
+ puts ' References validated'
68
72
  end
69
73
 
70
74
  def save(compiled, output_file)
@@ -72,23 +76,50 @@ module Aws
72
76
  File.open output_file, 'w' do |f|
73
77
  f.write JSON.pretty_generate(compiled)
74
78
  end
75
- puts " Compiled file written."
79
+ puts ' Compiled file written.'
76
80
  rescue
77
81
  puts "!!! Could not write compiled file: #{$!}"
78
82
  abort!
79
83
  end
80
84
  end
81
85
 
82
- def load
86
+ def load(spec=nil)
87
+ if spec
88
+ begin
89
+ abs = File.absolute_path(File.expand_path(spec))
90
+ unless File.exists?(abs)
91
+ abs = File.absolute_path(File.expand_path(File.join(@opts[:directory],spec)))
92
+ end
93
+ rescue
94
+ # pass
95
+ end
96
+ if File.exists?(abs)
97
+ raise "Unsupported specification file type" unless abs =~ /\.(json|ya?ml)\z/i
98
+
99
+ puts "Loading specification #{abs}..."
100
+ spec = File.read(abs)
101
+
102
+ case File.extname(File.basename(abs)).downcase
103
+ when /json/
104
+ spec = JSON.parse(spec)
105
+ when /yaml/
106
+ spec = YAML.load(spec)
107
+ else
108
+ raise "Unsupported file type for specification: #{spec}"
109
+ end
110
+ else
111
+ raise "Unable to open specification: #{abs}"
112
+ end
113
+ end
83
114
  %w{params mappings resources outputs}.each do |dir|
84
- load_dir(dir)
115
+ load_dir(dir,spec)
85
116
  end
86
117
  end
87
118
 
88
119
  protected
89
120
 
90
121
  def abort!
91
- puts "!!! Aborting !!!"
122
+ puts '!!! Aborting !!!'
92
123
  exit
93
124
  end
94
125
 
@@ -98,7 +129,7 @@ module Aws
98
129
  hash.keys.collect do |key|
99
130
  if %w{Ref SourceSecurityGroupName CacheSecurityGroupNames SecurityGroupNames}.include? key
100
131
  hash[key]
101
- elsif "Fn::GetAtt" == key
132
+ elsif 'Fn::GetAtt' == key
102
133
  hash[key].first
103
134
  else
104
135
  find_refs(hash[key])
@@ -109,11 +140,17 @@ module Aws
109
140
  end
110
141
  end
111
142
 
112
- def load_dir(dir)
143
+ def load_dir(dir,spec=nil)
113
144
  puts "Loading #{dir}..."
114
145
  @items[dir] = {}
146
+ raise "No such directory: #{@opts[:directory]}" unless File.directory?(@opts[:directory])
115
147
  (Dir[File.join(@opts[:directory], "#{dir}.*")] | Dir[File.join(@opts[:directory], dir, "**", "*")]).collect do |filename|
116
148
  next unless filename =~ /\.(json|ya?ml)\z/i
149
+ if spec and spec[dir]
150
+ base = File.basename(filename).gsub(%r/\.(rb|yaml)/, '')
151
+ next unless spec[dir].include?(base)
152
+ puts "\tUsing #{dir}/#{base}"
153
+ end
117
154
  begin
118
155
  puts " reading #{filename}"
119
156
  content = File.read(filename)
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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - PKinney