Module: SparkleFormation::SparkleAttribute::Azure

Included in:
SparkleFormation::SparkleStruct::Azure
Defined in:
lib/sparkle_formation/sparkle_attribute/azure.rb

Overview

Azure specific helper implementations

Constant Summary

AZURE_FUNCTIONS =

Valid azure builtin functions

[
  'add',
  'copyIndex',
  'div',
  'int',
  'length',
  'mod',
  'mul',
  'sub',
  'base64',
  'concat',
  'padLeft',
  'replace',
  'split',
  'string',
  'substring',
  'toLower',
  'toUpper',
  'trim',
  'uniqueString',
  'uri',
  'deployment',
  'parameters',
  'listKeys',
  'providers',
  'reference',
  'resourceGroup',
  'subscription'
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Inject camel style on module inclusion Add custom dump functionality to properly set resources



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 31

def self.included(klass)
  klass.const_set(:CAMEL_STYLE, :no_leading)

  klass.class_eval do
    def _azure_dump
      result = _attribute_struct_dump
      if(_parent.nil?)
        result = ::SparkleFormation::SparkleAttribute::Azure.resources_formatter(result)
      end
      result
    end
    alias_method :_attribute_struct_dump, :_dump
    alias_method :_dump, :_azure_dump
    alias_method :dump!, :_azure_dump
  end
end

.resources_formatter(hash) ⇒ Hash

Extract resources Hash from template dump and transform to Array type expected by the ARM API

Parameters:

  • hash (Hash)

    template dump

Returns:

  • (Hash)


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 16

def self.resources_formatter(hash)
  if(hash.key?('resources') && !hash['resources'].is_a?(Array))
    resources = hash.delete('resources')
    hash['resources'] = Array.new
    resources.each do |r_name, r_contents|
      hash['resources'].push(
        r_contents.merge('name' => r_name)
      )
    end
  end
  hash
end

Instance Method Details

#_depends_on(resource_name) ⇒ Array<String> #_depends_on(resource_names) ⇒ Array<String> #_depends_on(*resource_names) ⇒ Array<String> Also known as: depends_on!

Note:

this will directly modify the struct at its current context to inject depends on structure

Resource dependency generator

Overloads:

  • #_depends_on(resource_name) ⇒ Array<String>

    Parameters:

    • resource_name (String, Symbol)

      logical resource name

  • #_depends_on(resource_names) ⇒ Array<String>

    Parameters:

    • resource_names (Array<String, Symbol>)

      list of logical resource names

  • #_depends_on(*resource_names) ⇒ Array<String>

    Parameters:

    • resource_names (Array<String, Symbol>)

      list of logical resource names

Returns:

  • (Array<String>)


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 153

def _depends_on(*args)
  args = args.map do |item|
    case item
    when ::Symbol
      resource = _root.resources.set!(item)
      if(resource.nil?)
        ::Kernel.raise ::SparkleFormation::Error::NotFound::Resource.new(:name => item)
      else
        [resource.type, resource.resource_name!].join('/')
      end
    else
      item
    end
  end
  set!(:depends_on, args)
end

#_fn_format(*args) ⇒ SparkleFormation::FunctionStruct

Generate a builtin azure function



85
86
87
88
89
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 85

def _fn_format(*args)
  src = ::Kernel.__callee__.to_s
  src = ::Bogo::Utility.camel(src.sub(/(^_|\!$)/, ''), false)
  ::SparkleFormation::FunctionStruct.new(src, *args)
end

#_resource_id(resource_name) ⇒ FunctionStruct Also known as: resource_id!

Customized resourceId generator that will perform automatic lookup on defined resources for building the function if Symbol type is provided @param [String, Symbol] name of resource

Returns:



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 121

def _resource_id(*args)
  if(args.size > 1)
    ::SparkleFormation::FunctionStruct.new('resourceId', *args)
  else
    r_name = args.first
    resource = _root.resources.set!(r_name)
    if(resource.nil?)
      ::Kernel.raise ::SparkleFormation::Error::NotFound::Resource.new(:name => r_name)
    elsif(resource.type.nil?)
      ::Kernel.raise ::SparkleFormation::Error::InvalidResource.new(
        "Resource `#{r_name}` provides no type information."
      )
    else
      ::SparkleFormation::FunctionStruct.new(
        'resourceId',
        resource.type,
        resource.resource_name!
      )
    end
  end
end

#_stack_output(stack_name, output_name) ⇒ Hash Also known as: stack_output!

Reference output value from nested stack

Parameters:

  • stack_name (String, Symbol)

    logical resource name of stack

  • output_name (String, Symbol)

    stack output name

Returns:

  • (Hash)


176
177
178
179
180
181
182
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 176

def _stack_output(stack_name, output_name)
  stack_name = __attribute_key(stack_name)
  output_name = __attribute_key(output_name)
  o_root = _reference(stack_name)
  o_root.outputs.set!(output_name).value
  o_root
end

#_variables(*args) ⇒ SparkleFormation::AzureVariableStruct Also known as: variables!

Variables generator



108
109
110
111
112
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 108

def _variables(*args)
  x = ::SparkleFormation::AzureVariableStruct.new('variables', *args)
  x._fn_context = self
  x
end