Module: CfnDsl

Defined in:
lib/cfndsl/names.rb,
lib/cfndsl/rules.rb,
lib/cfndsl/types.rb,
lib/cfndsl/runner.rb,
lib/cfndsl/globals.rb,
lib/cfndsl/outputs.rb,
lib/cfndsl/plurals.rb,
lib/cfndsl/version.rb,
lib/cfndsl/jsonable.rb,
lib/cfndsl/mappings.rb,
lib/cfndsl/aws/types.rb,
lib/cfndsl/rake_task.rb,
lib/cfndsl/resources.rb,
lib/cfndsl/conditions.rb,
lib/cfndsl/parameters.rb,
lib/cfndsl/properties.rb,
lib/cfndsl/specification.rb,
lib/cfndsl/update_policy.rb,
lib/cfndsl/cloudformation.rb,
lib/cfndsl/creation_policy.rb,
lib/cfndsl/external_parameters.rb,
lib/cfndsl/orchestration_template.rb,
lib/cfndsl/json_serialisable_object.rb,
lib/cfndsl/aws/cloud_formation_template.rb

Overview

CfnDsl

Defined Under Namespace

Modules: AWS, CloudFormation, Functions, JSONSerialisableObject, Plurals, Types Classes: CloudFormationTemplate, ConditionDefinition, CreationPolicyDefinition, Error, ExternalParameters, Fn, JSONable, MappingDefinition, OrchestrationTemplate, OutputDefinition, ParameterDefinition, PropertyDefinition, RakeTask, RefDefinition, ResourceDefinition, RuleDefinition, Runner, Specification, UpdatePolicyDefinition

Constant Summary collapse

AWS_SPECIFICATION_URL =
'https://d1uauaxba7bl26.cloudfront.net/%<version>s/gzip/CloudFormationResourceSpecification.json'
LOCAL_SPEC_FILE =
File.expand_path('aws/resource_specification.json', __dir__)
VERSION =
'1.6.0'

Class Method Summary collapse

Class Method Details

.additional_specs(*specs) ⇒ Object



58
59
60
61
# File 'lib/cfndsl/globals.rb', line 58

def additional_specs(*specs)
  @additional_specs ||= Dir[File.expand_path('aws/patches/*.spec.json', __dir__)]
  @additional_specs.concat(specs.flatten)
end

.disable_deep_mergeObject



16
17
18
# File 'lib/cfndsl/globals.rb', line 16

def disable_deep_merge
  @disable_deep_merge = true
end

.disable_deep_merge?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/cfndsl/globals.rb', line 20

def disable_deep_merge?
  @disable_deep_merge
end

.eval_file_with_extras(filename, extras = [], logstream = nil) ⇒ Object

This function handles the eval of the template file and returns the results. It does this with a ruby “eval”, but it builds up a customized binding environment before it calls eval. The environment can be customized by passing a list of customizations in the extras parameter.

These customizations are expressed as an array of pairs of (type,filename). They are evaluated in the order they appear in the extras array. The types are as follows

:yaml - the second element is treated as a file name, which is loaded

as a yaml file. The yaml file should contain a top level
dictionary. Each of the keys of the top level dictionary is
used as a local variable in the evalation context.

:json - the second element is treated as a file name, which is loaded

as a json file. The yaml file should contain a top level
dictionary. Each of the keys of the top level dictionary is
used as a local variable in the evalation context.

:raw - the second element is treated as a ruby statement and is

evaluated in the binding context, similar to the contents of
a ruby file.

Note that the order is important, as later extra sections can overwrite or even undo things that were done by earlier sections.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cfndsl/cloudformation.rb', line 35

def self.eval_file_with_extras(filename, extras = [], logstream = nil)
  b = binding
  params = CfnDsl::ExternalParameters.refresh!
  extras.each do |type, file|
    case type
    when :yaml, :json
      klass_name = type.to_s.upcase
      logstream.puts("Loading #{klass_name} file #{file}") if logstream
      params.load_file file
    when :raw
      file_parts = file.split('=')
      case file_parts[1].downcase
      when 'true'
        params.set_param(file_parts[0], true)
      when 'false'
        params.set_param(file_parts[0], false)
      else
        params.set_param(*file.split('='))
      end
    end
  end

  logstream.puts("Loading template file #{filename}") if logstream
  b.eval(File.read(filename), filename)
end

.method_names(name) ⇒ Object

iterates through the the valid case-insensitive names for “name”



9
10
11
12
13
# File 'lib/cfndsl/names.rb', line 9

def method_names(name)
  name_str = name.to_s.dup
  names = [name_str, name_str.gsub(/^\w/, &:swapcase)]
  block_given? ? names.each { |n| yield n.to_sym } : names
end

.reserved_itemsObject



69
70
71
# File 'lib/cfndsl/globals.rb', line 69

def reserved_items
  %w[Resource Rule Parameter Output].freeze
end

.specification_fileString .specification_file(file) ⇒ String

Deprecated.

Use specification_file= to override the specification file

Returns the specification file name.

Returns:

  • (String)

    the specification file name



34
35
36
37
38
39
# File 'lib/cfndsl/globals.rb', line 34

def specification_file(file = nil)
  self.specification_file = file if file
  @specification_file ||= user_specification_file
  @specification_file = LOCAL_SPEC_FILE unless File.exist?(@specification_file)
  @specification_file
end

.specification_file=(file) ⇒ Object

Raises:



24
25
26
27
28
# File 'lib/cfndsl/globals.rb', line 24

def specification_file=(file)
  raise Error, "Specification #{file} does not exist" unless File.exist?(file)

  @specification_file = file
end

.specification_patches(*patches) ⇒ Object



63
64
65
66
67
# File 'lib/cfndsl/globals.rb', line 63

def specification_patches(*patches)
  # TODO: This is not capturing all the files in patches dir!
  @patches ||= Dir[File.expand_path('aws/patches/*patch.json', __dir__)]
  @patches.concat(patches.flatten)
end

.update_specification_file(file: user_specification_file, version: nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cfndsl/globals.rb', line 45

def update_specification_file(file: user_specification_file, version: nil)
  require 'open-uri'
  version ||= 'latest'
  FileUtils.mkdir_p File.dirname(file)
  url = format(AWS_SPECIFICATION_URL, version: version)
  content = URI.parse(url).open.read
  version = JSON.parse(content)['ResourceSpecificationVersion'] if version == 'latest'
  File.open(file, 'w') { |f| f.puts content }
  { file: file, version: version, url: url }
rescue StandardError
  raise "Failed updating specification file #{file} from #{url}"
end

.user_specification_fileObject



41
42
43
# File 'lib/cfndsl/globals.rb', line 41

def user_specification_file
  File.join(ENV['HOME'], '.cfndsl/resource_specification.json')
end