module CfnDsl
Global variables to adjust CfnDsl
behavior
Method name helper
Defer require of other capabilities (particularly loading dynamic Types
) until required
Constants
- AWS_SPECIFICATION_URL
- LOCAL_SPEC_FILE
- VERSION
Public Class Methods
Source
# 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
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.
Public Instance Methods
Source
# 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
Source
# File lib/cfndsl/globals.rb, line 16 def disable_deep_merge @disable_deep_merge = true end
Source
# File lib/cfndsl/globals.rb, line 20 def disable_deep_merge? @disable_deep_merge end
Source
# 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
iterates through the the valid case-insensitive names for “name”
Source
# File lib/cfndsl/globals.rb, line 69 def reserved_items %w[Resource Rule Parameter Output].freeze end
Source
# 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
@overload specification_file
() @return [String] the specification file name @overload specification_file
(file) @deprecated Use specification_file
= to override the specification file
Source
# 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
Source
# 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
Source
# 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
Source
# File lib/cfndsl/globals.rb, line 41 def user_specification_file File.join(ENV['HOME'], '.cfndsl/resource_specification.json') end