Module: AwsCftTools::Template::Properties
- Included in:
- AwsCftTools::Template
- Defined in:
- lib/aws_cft_tools/template/properties.rb
Overview
Simple properties of templates.
Instance Method Summary collapse
-
#allowed_environments ⇒ Array<String>
Returns the list of environments allowed for the
Environment
parameter. - #allowed_environments_regex ⇒ Object
-
#allowed_regions ⇒ Array<String>
Returns the list of regions in which the template is allowed.
-
#default_parameters ⇒ Object
Returns the parameter defaults for the template.
- #environment?(value) ⇒ Boolean
-
#inputs ⇒ Array<String>
lists the imports expected by the template.
-
#outputs ⇒ Array<String>
lists the exported values from the template.
- #region?(region) ⇒ Boolean
-
#role ⇒ String
Returns the role of the template as specified in the template metadata.
- #role?(value) ⇒ Boolean
-
#template_dependencies ⇒ Object
Returns any templates on which this template has an explicit dependency.
Instance Method Details
#allowed_environments ⇒ Array<String>
Returns the list of environments allowed for the Environment
parameter.
14 15 16 |
# File 'lib/aws_cft_tools/template/properties.rb', line 14 def allowed_environments template.dig('Parameters', 'Environment', 'AllowedValues') || [] end |
#allowed_environments_regex ⇒ Object
18 19 20 21 |
# File 'lib/aws_cft_tools/template/properties.rb', line 18 def allowed_environments_regex source = template.dig('Parameters', 'Environment', 'AllowedPattern') Regexp.compile(source) if source end |
#allowed_regions ⇒ Array<String>
The region in which a template is deployed is available as the AWS::Region
pseudo-parameter.
Returns the list of regions in which the template is allowed.
58 59 60 |
# File 'lib/aws_cft_tools/template/properties.rb', line 58 def allowed_regions template.dig('Metadata', 'Region') || [] end |
#default_parameters ⇒ Object
Returns the parameter defaults for the template.
32 33 34 35 36 |
# File 'lib/aws_cft_tools/template/properties.rb', line 32 def default_parameters (template['Parameters'] || []).each_with_object({}) do |param, hash| hash[param.first] = param.last['Default'] end end |
#environment?(value) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/aws_cft_tools/template/properties.rb', line 23 def environment?(value) return allowed_environments.include?(value) if allowed_environments.any? regex = allowed_environments_regex return regex.match?(value) if regex end |
#inputs ⇒ Array<String>
lists the imports expected by the template
Note that this does substitutions of any references to template parameters.
95 96 97 98 99 100 101 |
# File 'lib/aws_cft_tools/template/properties.rb', line 95 def inputs (template['Resources'] || {}) .values .flat_map { |resource| pull_imports(resource['Properties'] || {}) } .uniq .map(&method(:with_substitutions)) end |
#outputs ⇒ Array<String>
lists the exported values from the template
Note that this does substitutions of any references to template parameters.
82 83 84 85 86 |
# File 'lib/aws_cft_tools/template/properties.rb', line 82 def outputs (template['Outputs'] || []).map do |_, output| with_substitutions(output_name(output.dig('Export', 'Name'))) end end |
#region?(region) ⇒ Boolean
62 63 64 |
# File 'lib/aws_cft_tools/template/properties.rb', line 62 def region?(region) !region || allowed_regions.empty? || allowed_regions.include?(region) end |
#role ⇒ String
Returns the role of the template as specified in the template metadata.
43 44 45 |
# File 'lib/aws_cft_tools/template/properties.rb', line 43 def role template.dig('Metadata', 'Role') end |
#role?(value) ⇒ Boolean
47 48 49 |
# File 'lib/aws_cft_tools/template/properties.rb', line 47 def role?(value) !value || role == value end |
#template_dependencies ⇒ Object
Returns any templates on which this template has an explicit dependency.
These explicit dependencies are combined with any dependencies implied by imported values.
71 72 73 |
# File 'lib/aws_cft_tools/template/properties.rb', line 71 def template_dependencies template.dig('Metadata', 'DependsOn', 'Templates') || [] end |