Module: SparkleFormation::SparkleAttribute::Azure

Defined in:
lib/sparkle_formation/sparkle_attribute/azure.rb

Overview

Azure specific helper implementations

Constant Summary collapse

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',
  'variables',
  '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(*args) ⇒ Array<String> Also known as: depends_on!

Customized dependsOn generator. Will automatically build resource reference value using defined resources for Symbol type values. Sets directly into current context.

Parameters:

  • args (Object)

Returns:

  • (Array<String>)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 127

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



83
84
85
86
87
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 83

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

#_resource_id(*args) ⇒ 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

Parameters:

  • args (Object)

Returns:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 102

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)
    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)


150
151
152
153
154
155
156
# File 'lib/sparkle_formation/sparkle_attribute/azure.rb', line 150

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