Class: Cfhighlander::Dsl::SubcomponentParamValueResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/cfhighlander.dsl.subcomponent.rb

Class Method Summary collapse

Class Method Details

.resolveMappingParamValue(component, sub_component, param) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/cfhighlander.dsl.subcomponent.rb', line 299

def self.resolveMappingParamValue(component, sub_component, param)

  # determine map name

  provider = nil

  mappings_name = param.mapName
  actual_map_name = mappings_name

  key_name = nil

  # priority 0: stack-level parameter of map name
  stack_param_mapname = component.parameters.param_list.find {|p| p.name == mappings_name}
  unless stack_param_mapname.nil?
    key_name = "Ref('#{mappings_name}')"
  end

  # priority 1 mapping provider keyName - used as lowest priority
  if key_name.nil?
    provider = mappings_provider(mappings_name)
    if ((not provider.nil?) and (provider.respond_to?('getDefaultKey')))
      key_name = provider.getDefaultKey
    end
  end

  # priority 2: dsl defined key name
  if key_name.nil?
    key_name = param.mapKey
    # could still be nil after this line
  end

  value = mapping_value(component: component,
      provider_name: mappings_name,
      value_name: param.mapAttribute,
      key_name: key_name
  )

  return value
end

.resolveValue(component, sub_component, param, available_outputs) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/cfhighlander.dsl.subcomponent.rb', line 214

def self.resolveValue(component, sub_component, param, available_outputs)

  puts("INFO Resolving parameter #{component.name} -> #{sub_component.name}.#{param.name}: ")

  # rule 0: this rule is here for legacy reasons and OutputParam. It should be deprecated
  # once all hl-components- repos remove any references to OutputParam
  if not param.provided_value.nil?
    component_name = param.provided_value.split('.')[0]
    output_name = param.provided_value.split('.')[1]
    source_component = component.subcomponents.find {|c| c.name == component_name}
    if source_component.nil?
      source_component = component.subcomponents.find {|c| c.component_loaded.template.template_name == component_name}
    end
    return CfnDsl::Fn.new('GetAtt', [
        source_component.name,
        "Outputs.#{output_name}"
    ]).to_json
  end

  # rule 1: check if there are values defined on component itself
  if sub_component.param_values.key?(param.name)
    puts " parameter value provided "

    param_value = sub_component.param_values[param.name]
    if param_value.is_a? String and param_value.include? '.'
      source_component_name = param_value.split('.')[0]
      source_output = param_value.split('.')[1]
      source_component = component.subcomponents.find {|sc| sc.name == source_component_name}
      # if source component exists
      if not source_component.nil?
        if source_component_name == sub_component.name
          STDERR.puts "WARNING: Parameter value on component #{source_component_name} references component itself: #{param_value}"
        else
          return CfnDsl::Fn.new('GetAtt', [
              source_component_name,
              "Outputs.#{source_output}"
          ]).to_json
        end
      else
        return Cfhighlander::Helper.parameter_cfndsl_value(param_value)
      end
    else
      return Cfhighlander::Helper.parameter_cfndsl_value(sub_component.param_values[param.name])
    end
  end

  # rule 1.1 mapping parameters are handled differently.
  # TODO wire mapping parameters outside of component
  if param.class == Cfhighlander::Dsl::MappingParam
    puts " mapping parameter"
    mapping_param_value = self.resolveMappingParamValue(component, sub_component, param)

    # if mapping param is not resolved, e.g. mapping not provided
    # parameters will bubble to parent component if not matched by outputs from
    # other components
    return mapping_param_value unless mapping_param_value.nil?
  end

  # rule #2: match output values from other components
  #          by parameter name
  if available_outputs.key? param.name
    component_name = available_outputs[param.name].component.name
    puts " resolved as output of #{component_name}"
    return CfnDsl::Fn.new('GetAtt', [
        component_name,
        "Outputs.#{param.name}"
    ]).to_json
  end

  # by default bubble parameter and resolve as reference on upper level
  propagated_param = param.clone
  propagated_param.name = "#{sub_component.cfn_name}#{param.name}" unless param.is_global
  component.parameters.addParam propagated_param
  puts " no autowiring candidates, propagate parameter to parent"
  
  if param.type == 'CommaDelimitedList'
    return CfnDsl::Fn.new('Join', [',',
      CfnDsl::RefDefinition.new(propagated_param.name)
    ]).to_json
  end
  
  return CfnDsl::RefDefinition.new(propagated_param.name).to_json

end