Sha256: 7bc68a134f68332b46e49aa95d4c19847b69d9a9827eadc5b5764aafffa78ef2
Contents?: true
Size: 1.8 KB
Versions: 24
Compression:
Stored size: 1.8 KB
Contents
module Lono::Output class Template extend Memoist def initialize(blueprint, template) @blueprint, @template = blueprint, template end def required_parameters parameters.select { |logical_id, p| p["Default"].nil? } end def optional_parameters parameters.reject { |logical_id, p| p["Default"].nil? } end def parameters list = data["Parameters"] || [] # Not using sort_parameter_group because structure is different list.sort_by do |name, data| optional = !data["Default"].nil? [optional, name].join('-') end.to_h end def parameter_groups interface = data.dig("Metadata", "AWS::CloudFormation::Interface") return unless interface pgs = interface["ParameterGroups"] pgs.inject({}) do |result, pg| label = pg["Label"]["default"] parameters = sort_parameter_group(pg["Parameters"]) result.merge(label => parameters) end end def data template_path = "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml" check_template_exists!(template_path) YAML.load(IO.read(template_path)) end memoize :data private def sort_parameter_group(list) list.sort_by do |name| raw_parameters = data["Parameters"] || [] param = raw_parameters[name] optional = !param["Default"].nil? [optional, name].join('-') end end # Check if the template exists and print friendly error message. Exits if it # does not exist. def check_template_exists!(template_path) return if File.exist?(template_path) puts "The template #{template_path} does not exist. Are you sure you use the right template name? The template name does not require the extension.".color(:red) exit 1 end end end
Version data entries
24 entries across 24 versions & 1 rubygems