cfn-model 0.0.4 → 0.0.5

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: 451716e29e7e206640c634316e54d9e125a8621b
4
- data.tar.gz: b563f6974c0f6dc5875749d9cd05b7cbccce931a
3
+ metadata.gz: 8359965fbd16f4f35a8a964cac9099103f804807
4
+ data.tar.gz: ca74df177c111002208e3761c91bc894db4e76c9
5
5
  SHA512:
6
- metadata.gz: 5e3570273abb584a20fdb65bac3a589fdc0b96bab3ffccf2102f3a1811ffe5bdebd2dc2381d268d3f23deeaeb8c05f58b35360e8874b8b2b190489280dff874f
7
- data.tar.gz: dd7756be55aecf0313cd1472b24aa1c6b89778d5d02c0bf7aafdc00b15d63a02ea0218c6d32068fac68651fbe75ebc8b846777b6ea5d75a69bbe1a5dac6ca3e8
6
+ metadata.gz: 97b76b6ca51d85a5f2e26ce1adbfff298c5ae324f89dec122598c8856e0e71a100c44b264567a8643ff8da124bb5b197415e099d20ea8c629e8fd581f266826d
7
+ data.tar.gz: 0c22a703224333c092f5bc0d3dee14a75980a4daa200f15c60b0351ea124f453c68d8a89c0a3a533077fd416a8c4994e2ae35fae4b1b4df42c0dc6afaa691a88
data/bin/cfn_parse ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require 'cfn-model'
3
+
4
+ puts '======'
5
+ puts ARGV[0]
6
+ puts '======'
7
+ cfn_model = CfnParser.new.parse IO.read(ARGV[0])
8
+ puts cfn_model
@@ -39,4 +39,8 @@ class CfnModel
39
39
  def resources_by_type(resource_type)
40
40
  @resources.values.select { |resource| resource.resource_type == resource_type }
41
41
  end
42
+
43
+ def to_s
44
+ @resources.to_s
45
+ end
42
46
  end
@@ -37,6 +37,10 @@ module AWS
37
37
  end
38
38
  end
39
39
 
40
+ module Custom
41
+
42
+ end
43
+
40
44
  class ModelElement
41
45
  attr_accessor :logical_resource_id, :resource_type
42
46
 
@@ -12,9 +12,12 @@ Dir["#{__dir__}/../model/*.rb"].each { |model| require "cfn-model/model/#{File.b
12
12
  #
13
13
  class CfnParser
14
14
  # this will convert any !Ref or !GetAtt into tranditional hash like in json
15
- YAML.add_domain_type('', 'GetAtt') { |type, val| { 'Fn::GetAtt' => val } }
16
15
  YAML.add_domain_type('', 'Ref') { |type, val| { 'Ref' => val } }
17
16
 
17
+ %w(GetAtt Join Base64 Sub Split Select ImportValue GetAZs FindInMap And Or If Not).each do |function_name|
18
+ YAML.add_domain_type('', function_name) { |type, val| { "Fn::#{function_name}" => val } }
19
+ end
20
+
18
21
  ##
19
22
  # Given raw json/yml CloudFormation template, returns a CfnModel object
20
23
  # or raise ParserErrors if something is amiss with the format
@@ -92,21 +95,32 @@ class CfnParser
92
95
  resource_class = Object.const_get type_name, inherit=false
93
96
  rescue NameError
94
97
  # puts "Never seen class: #{type_name} so going dynamic"
95
- resource_class = Class.new(DynamicModelElement)
98
+ resource_class = generate_resource_class_from_type type_name
99
+ end
100
+ resource_class
101
+ end
96
102
 
103
+ def initial_lower(str)
104
+ str.slice(0).downcase + str[1..(str.length)]
105
+ end
106
+
107
+ def generate_resource_class_from_type(type_name)
108
+ resource_class = Class.new(DynamicModelElement)
109
+
110
+ module_names = type_name.split('::')
111
+ if module_names.first == 'Custom'
112
+ Object.const_set(module_names[1], resource_class)
113
+ elsif module_names.first == 'AWS'
97
114
  begin
98
- module_constant = AWS.const_get(type_name.split('::')[1])
115
+ module_constant = AWS.const_get(module_names[1])
99
116
  rescue NameError
100
117
  module_constant = Module.new
101
- module_constant.const_set(type_name.split('::')[1], module_constant)
118
+ module_constant.const_set(module_names[1], module_constant)
102
119
  end
103
-
104
- module_constant.const_set(type_name.split('::')[2], resource_class)
120
+ module_constant.const_set(module_names[2], resource_class)
121
+ else
122
+ raise "Unknown namespace in resource type: #{module_names.first}"
105
123
  end
106
124
  resource_class
107
125
  end
108
-
109
- def initial_lower(str)
110
- str.slice(0).downcase + str[1..(str.length)]
111
- end
112
126
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfn-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2017-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kwalify
@@ -26,10 +26,12 @@ dependencies:
26
26
  version: 0.7.2
27
27
  description: An object model for CloudFormation templates
28
28
  email:
29
- executables: []
29
+ executables:
30
+ - cfn_parse
30
31
  extensions: []
31
32
  extra_rdoc_files: []
32
33
  files:
34
+ - bin/cfn_parse
33
35
  - lib/cfn-model.rb
34
36
  - lib/cfn-model/model/bucket_policy.rb
35
37
  - lib/cfn-model/model/cfn_model.rb