class Cfhighlander::Dsl::SubcomponentParamValueResolver

Public Class Methods

resolveMappingParamValue(component, sub_component, param) click to toggle source
# 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) click to toggle source
# 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