Class: CfnDsl::OrchestrationTemplate
- Inherits:
-
JSONable
- Object
- JSONable
- CfnDsl::OrchestrationTemplate
show all
- Defined in:
- lib/cfndsl/orchestration_template.rb
Overview
Handles the overall template object rubocop:disable Metrics/ClassLength
Constant Summary
collapse
- GLOBAL_REFS =
{
'AWS::NotificationARNs' => 1,
'AWS::Region' => 1,
'AWS::StackId' => 1,
'AWS::StackName' => 1,
'AWS::AccountId' => 1,
'AWS::NoValue' => 1
}.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from JSONable
#as_json, #declare, #external_parameters, external_parameters, #ref_children, #to_json
Methods included from Functions
#FnAnd, #FnBase64, #FnCidr, #FnEquals, #FnFindInMap, #FnFormat, #FnGetAZs, #FnGetAtt, #FnIf, #FnImportValue, #FnJoin, #FnNot, #FnOr, #FnSelect, #FnSplit, #FnSub, #Ref
Methods included from RefCheck
#build_references, #ref_children
Constructor Details
Returns a new instance of OrchestrationTemplate.
115
116
117
|
# File 'lib/cfndsl/orchestration_template.rb', line 115
def initialize
@AWSTemplateFormatVersion = '2010-09-09'
end
|
Class Method Details
.create_array_property_def(resource, pname, pclass) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/cfndsl/orchestration_template.rb', line 78
def create_array_property_def(resource, pname, pclass)
create_property_def(resource, pname, Array)
sname = CfnDsl::Plurals.singularize pname
return if sname == pname
resource.class_eval do
CfnDsl.method_names(sname) do |method|
define_method(method) do |value = nil, &block|
@Properties ||= {}
@Properties[pname] ||= PropertyDefinition.new([])
value ||= pclass.new
@Properties[pname].value.push value
value.instance_eval(&block) if block
value
end
end
end
end
|
.create_property_def(resource, pname, pclass) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/cfndsl/orchestration_template.rb', line 64
def create_property_def(resource, pname, pclass)
resource.class_eval do
CfnDsl.method_names(pname) do |method|
define_method(method) do |*values, &block|
values.push pclass.new if values.empty?
@Properties ||= {}
@Properties[pname] = PropertyDefinition.new(*values)
@Properties[pname].value.instance_eval(&block) if block
@Properties[pname].value
end
end
end
end
|
.create_resource_accessor(accessor, resource, type) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/cfndsl/orchestration_template.rb', line 99
def create_resource_accessor(accessor, resource, type)
class_eval do
CfnDsl.method_names(accessor) do |method|
define_method(method) do |name, *values, &block|
name = name.to_s
@Resources ||= {}
@Resources[name] ||= resource.new(*values)
@Resources[name].instance_eval(&block) if block
@Resources[name].instance_variable_set('@Type', type)
@Resources[name]
end
end
end
end
|
.create_resource_def(name, info) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/cfndsl/orchestration_template.rb', line 48
def create_resource_def(name, info)
resource = Class.new ResourceDefinition
resource_name = name.gsub(/::/, '_')
type_module.const_set(resource_name, resource)
info['Properties'].each_pair do |pname, ptype|
if ptype.is_a? Array
pclass = type_module.const_get ptype.first
create_array_property_def(resource, pname, pclass)
else
pclass = type_module.const_get ptype
create_property_def(resource, pname, pclass)
end
end
resource_name
end
|
.create_types ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/cfndsl/orchestration_template.rb', line 26
def create_types
accessors = {}
types_mapping = {}
template_types['Resources'].each_pair do |resource, info|
resource_name = create_resource_def(resource, info)
parts = resource.split('::')
until parts.empty?
break if CfnDsl.reserved_items.include? parts.first
abreve_name = parts.join('_')
if accessors.key? abreve_name
accessors.delete abreve_name else
accessors[abreve_name] = type_module.const_get resource_name
types_mapping[abreve_name] = resource
end
parts.shift
end
end
accessors.each_pair { |acc, res| create_resource_accessor(acc, res, types_mapping[acc]) }
end
|
Instance Method Details
#check_output_refs ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/cfndsl/orchestration_template.rb', line 155
def check_output_refs
invalids = []
output_refs = {}
if @Outputs
@Outputs.each_key do |resource|
output_refs[resource.to_s] = @Outputs[resource].build_references({})
end
output_refs.each_key do |origin|
output_refs[origin].each_key do |ref|
invalids.push "Invalid Reference: Output #{origin} refers to #{ref}" unless valid_ref?(ref)
end
end
end
invalids
end
|
#check_refs ⇒ Object
rubocop:enable Metrics/PerceivedComplexity
134
135
136
137
|
# File 'lib/cfndsl/orchestration_template.rb', line 134
def check_refs
invalids = check_resource_refs + check_output_refs + check_rule_refs
invalids unless invalids.empty?
end
|
#check_resource_refs ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/cfndsl/orchestration_template.rb', line 139
def check_resource_refs
invalids = []
@_resource_refs = {}
if @Resources
@Resources.each_key do |resource|
@_resource_refs[resource.to_s] = @Resources[resource].build_references({})
end
@_resource_refs.each_key do |origin|
@_resource_refs[origin].each_key do |ref|
invalids.push "Invalid Reference: Resource #{origin} refers to #{ref}" unless valid_ref?(ref, origin)
end
end
end
invalids
end
|
#check_rule_refs ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/cfndsl/orchestration_template.rb', line 171
def check_rule_refs
invalids = []
@_rule_refs = {}
if @Rules
@Rules.each_key do |rule|
@_rule_refs[resource.to_s] = @Rules[rule].build_references({})
end
@_rule_refs.each_key do |origin|
@_rule_refs[origin].each_key do |ref|
invalids.push "Invalid Reference: Rule #{origin} refers to #{ref}" unless valid_ref?(ref, origin)
end
end
end
invalids
end
|
#valid_ref?(ref, origin = nil) ⇒ Boolean
rubocop:disable Metrics/PerceivedComplexity
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/cfndsl/orchestration_template.rb', line 120
def valid_ref?(ref, origin = nil)
ref = ref.to_s
origin = origin.to_s if origin
return true if GLOBAL_REFS.key?(ref)
return true if @Parameters&.key?(ref)
return !origin || !@_resource_refs || !@_resource_refs[ref] || !@_resource_refs[ref].key?(origin) if @Resources.key?(ref)
false
end
|