cfhighlander 0.2.1 → 0.3.0.alpha.1528936037

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,243 +0,0 @@
1
- require_relative './highlander.helper'
2
- require_relative './highlander.dsl.base'
3
- require_relative './highlander.factory'
4
-
5
- module Highlander
6
-
7
- module Dsl
8
-
9
- class SubcomponentParameter
10
- attr_accessor :name, :cfndsl_value
11
-
12
- def initialize
13
-
14
- end
15
-
16
- end
17
-
18
-
19
- class Component < DslBase
20
-
21
- attr_accessor :name,
22
- :template,
23
- :template_version,
24
- :distribution_format,
25
- :distribution_location,
26
- :distribution_url,
27
- :distribution_format,
28
- :component_loaded,
29
- :parameters,
30
- :param_values,
31
- :parent,
32
- :component_config_override,
33
- :export_config
34
-
35
- def initialize(parent,
36
- name,
37
- template,
38
- param_values,
39
- component_sources = [],
40
- config = {},
41
- export_config = {},
42
- distribution_format = 'yaml')
43
-
44
- @parent = parent
45
- @config = config
46
- @export_config = export_config
47
- @component_sources = component_sources
48
-
49
- template_name = template
50
- template_version = 'latest'
51
- if template.include?('@') and not (template.start_with? 'git')
52
- template_name = template.split('@')[0]
53
- template_version = template.split('@')[1]
54
- end
55
-
56
- @template = template_name
57
- @template_version = template_version
58
- @name = name
59
- @param_values = param_values
60
-
61
- # distribution settings
62
- @distribution_format = distribution_format
63
- # by default components located at same location as master stack
64
- @distribution_location = '.'
65
- build_distribution_url
66
-
67
- # load component
68
- factory = Highlander::Factory::ComponentFactory.new(@component_sources)
69
- @component_loaded = factory.findComponent(
70
- @template,
71
- @template_version
72
- )
73
- @component_loaded.config.extend @config
74
-
75
- @parameters = []
76
- # load_parameters
77
- end
78
-
79
- def version=(value)
80
- @component_loaded.version = value
81
- end
82
-
83
- def distribute_bucket=(value)
84
- @component_loaded.distribution_bucket = value
85
- end
86
-
87
- def distribute_prefix=(value)
88
- @component_loaded.distribution_prefix = value
89
- end
90
-
91
- def distribution_format=(value)
92
- @distribution_format = value
93
- build_distribution_url
94
- end
95
-
96
- def build_distribution_url
97
- @distribution_location = @parent.distribute_url unless @parent.distribute_url.nil?
98
- @distribution_url = "#{@distribution_location}/#{@name}.compiled.#{@distribution_format}"
99
- end
100
-
101
- def load(component_config_override = {})
102
- # check for component config on parent
103
- parent = @parent
104
-
105
- # Highest priority is DSL defined configuration
106
- component_config_override.extend @config
107
-
108
- @component_config_override = component_config_override
109
-
110
- @component_loaded.load @component_config_override
111
- end
112
-
113
- # Parameters should be lazy loaded, that is late-binding should happen once
114
- # all parameters and mappings are known
115
- def load_parameters
116
- component_dsl = @component_loaded.highlander_dsl
117
- component_dsl.parameters.param_list.each do |component_param|
118
- param = Highlander::Dsl::SubcomponentParameter.new
119
- param.name = component_param.name
120
- param.cfndsl_value = SubcomponentParamValueResolver.resolveValue(
121
- @parent,
122
- self,
123
- component_param)
124
- @parameters << param
125
- end
126
- end
127
-
128
- end
129
-
130
- class SubcomponentParamValueResolver
131
- def self.resolveValue(component, sub_component, param)
132
-
133
- puts("Resolving parameter #{component.name} -> #{sub_component.name}.#{param.name}")
134
-
135
- # check if there are values defined on component itself
136
- if sub_component.param_values.key?(param.name)
137
- return Highlander::Helper.parameter_cfndsl_value(sub_component.param_values[param.name])
138
- end
139
-
140
- if param.class == Highlander::Dsl::StackParam
141
- return self.resolveStackParamValue(component, sub_component, param)
142
- elsif param.class == Highlander::Dsl::ComponentParam
143
- return self.resolveComponentParamValue(component, sub_component, param)
144
- elsif param.class == Highlander::Dsl::MappingParam
145
- return self.resolveMappingParamValue(component, sub_component, param)
146
- elsif param.class == Highlander::Dsl::OutputParam
147
- return self.resolveOutputParamValue(component, sub_component, param)
148
- else
149
- raise "#{param.class} not resolvable to parameter value"
150
- end
151
- end
152
-
153
- def self.resolveStackParamValue(component, sub_component, param)
154
- param_name = param.is_global ? param.name : "#{sub_component.name}#{param.name}"
155
- return "Ref('#{param_name}')"
156
- end
157
-
158
- def self.resolveComponentParamValue(component, sub_component, param)
159
- # check component config for param value
160
- # TODO
161
- # check stack config for param value
162
- # TODO
163
- # return default value
164
- return "'#{param.default_value}'"
165
- end
166
-
167
- def self.resolveMappingParamValue(component, sub_component, param)
168
-
169
- # determine map name
170
-
171
- provider = nil
172
-
173
- mappings_name = param.mapName
174
- actual_map_name = mappings_name
175
-
176
- key_name = nil
177
-
178
- # priority 0: stack-level parameter of map name
179
- stack_param_mapname = component.parameters.param_list.find { |p| p.name == mappings_name }
180
- unless stack_param_mapname.nil?
181
- key_name = "Ref('#{mappings_name}')"
182
- end
183
-
184
- # priority 1 mapping provider keyName - used as lowest priority
185
- if key_name.nil?
186
- provider = mappings_provider(mappings_name)
187
- if ((not provider.nil?) and (provider.respond_to?('getDefaultKey')))
188
- key_name = provider.getDefaultKey
189
- end
190
- end
191
-
192
- # priority 2: dsl defined key name
193
- if key_name.nil?
194
- key_name = param.mapKey
195
- # could still be nil after this line
196
- end
197
-
198
- value = mapping_value(component: component,
199
- provider_name: mappings_name,
200
- value_name: param.mapAttribute,
201
- key_name: key_name
202
- )
203
-
204
- if value.nil?
205
- return "'#{param.default_value}'" unless param.default_value.empty?
206
- return "''"
207
- end
208
-
209
- return value
210
-
211
-
212
- return value
213
- end
214
-
215
- def self.resolveOutputParamValue(component, sub_component, param)
216
- component_name = param.component
217
- resource_name = nil
218
- if not sub_component.export_config.nil?
219
- if sub_component.export_config.key? component_name
220
- resource_name = sub_component.export_config[component_name]
221
- end
222
- end
223
-
224
- if resource_name.nil?
225
- # find by component
226
- resource = component.components.find { |c| c.name == component_name }
227
- resource_name = resource.name unless resource.nil?
228
- if resource_name.nil?
229
- resource = component.components.find { |c| c.template == component_name }
230
- resource_name = resource.name unless resource.nil?
231
- end
232
- end
233
-
234
- if resource_name.nil?
235
- raise "#{sub_component.name}.Params.#{param.name}: Failed to resolve OutputParam '#{param.name}' with source '#{component_name}'. Component not found!"
236
- end
237
-
238
- return "FnGetAtt('#{resource_name}','Outputs.#{param.name}')"
239
- end
240
- end
241
-
242
- end
243
- end
@@ -1,113 +0,0 @@
1
- require_relative './highlander.dsl.base'
2
-
3
- module Highlander
4
-
5
- module Dsl
6
- class Parameters < DslBase
7
-
8
- attr_accessor :param_list
9
-
10
- def initialize()
11
- @param_list = []
12
- end
13
-
14
- def addParam(param)
15
- existing_param = @param_list.find { |p| p.name == param.name }
16
- if not existing_param.nil?
17
- puts "Parameter being overwritten. Updating parameter #{param.name} with new definition..."
18
- @param_list[@param_list.index(existing_param)] = param
19
- else
20
- @param_list << param
21
- end
22
- end
23
-
24
- def StackParam(name, defaultValue='', isGlobal: false, noEcho: false)
25
- param = StackParam.new(name, 'String', defaultValue)
26
- param.is_global = isGlobal
27
- param.config = @config
28
- param.no_echo = noEcho
29
- addParam param
30
- end
31
-
32
- def ComponentParam(name, defaultValue='')
33
- param = ComponentParam.new(name, 'String', defaultValue)
34
- param.config = @config
35
- addParam param
36
- end
37
-
38
- def MappingParam(name, defaultValue='', &block)
39
- param = MappingParam.new(name, 'String', defaultValue)
40
- param.config = @config
41
- param.instance_eval(&block)
42
- addParam param
43
- end
44
-
45
- def OutputParam(component:, name:, default: '')
46
- param = OutputParam.new(component, name, default)
47
- param.config = @config
48
- addParam param
49
- end
50
- end
51
-
52
- class Parameter < DslBase
53
- attr_accessor :name, :type, :default_value, :no_echo
54
-
55
- def initialize(name, type, defaultValue, noEcho = false)
56
- @no_echo = noEcho
57
- @name = name
58
- @type = type
59
- @default_value = defaultValue
60
- end
61
- end
62
-
63
- class StackParam < Parameter
64
- attr_accessor :is_global
65
- end
66
-
67
- class ComponentParam < Parameter
68
-
69
- end
70
-
71
- class OutputParam < Parameter
72
- attr_accessor :component
73
-
74
- def initialize(component, name, default)
75
- @component = component
76
- @name = name
77
- @default_value = default
78
- @type = 'String'
79
- end
80
- end
81
-
82
- class MappingParam < Parameter
83
-
84
- attr_accessor :mapName, :mapKey, :mapAttribute
85
-
86
- def method_missing(method, *args)
87
- smethod = "#{method}"
88
- if smethod.start_with?('Map')
89
- puts smethod
90
- end
91
-
92
- super.method_missing(method)
93
- end
94
-
95
- def key(map_key)
96
- @mapKey = map_key
97
- end
98
-
99
- def attribute(key)
100
- @mapAttribute = key
101
- end
102
-
103
- def map(mapName)
104
- @mapName = mapName
105
- end
106
-
107
- def mapProvider
108
- mappings_provider(@mapName)
109
- end
110
-
111
- end
112
- end
113
- end