module SparkleFormation::SparkleAttribute::Azure

Azure specific helper implementations

Constants

AZURE_FUNCTIONS

Valid azure builtin functions

Public Class Methods

included(klass) click to toggle source

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

# 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) click to toggle source

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

@param hash [Hash] template dump @return [Hash]

# 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

Public Instance Methods

_azure_dump() click to toggle source
# File lib/sparkle_formation/sparkle_attribute/azure.rb, line 35
def _azure_dump
  result = _attribute_struct_dump
  if _parent.nil?
    result = ::SparkleFormation::SparkleAttribute::Azure.resources_formatter(result)
  end
  result
end
_depends_on(*args) click to toggle source

Resource dependency generator @overload _depends_on(resource_name)

@param resource_name [String, Symbol] logical resource name

@overload _depends_on(resource_names)

@param resource_names [Array<String, Symbol>] list of logical resource names

@overload _depends_on(*resource_names)

@param resource_names [Array<String, Symbol>] list of logical resource names

@return [Array<String>] @note this will directly modify the struct at its current context to inject depends on structure

# File lib/sparkle_formation/sparkle_attribute/azure.rb, line 156
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
Also aliased as: depends_on!
_fn_format(*args) click to toggle source

Generate a builtin azure function

@return [SparkleFormation::FunctionStruct]

# File lib/sparkle_formation/sparkle_attribute/azure.rb, line 86
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) click to toggle source

@overload _resource_id(resource_name)

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

@return [FunctionStruct]

# File lib/sparkle_formation/sparkle_attribute/azure.rb, line 123
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
Also aliased as: resource_id!
_stack_output(stack_name, output_name) click to toggle source

Reference output value from nested stack

@param stack_name [String, Symbol] logical resource name of stack @param output_name [String, Symbol] stack output name @return [Hash]

# File lib/sparkle_formation/sparkle_attribute/azure.rb, line 180
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
Also aliased as: stack_output!
_variables(*args) click to toggle source

Variables generator

@return [SparkleFormation::AzureVariableStruct]

# File lib/sparkle_formation/sparkle_attribute/azure.rb, line 109
def _variables(*args)
  x = ::SparkleFormation::AzureVariableStruct.new("variables", *args)
  x._fn_context = self
  x
end
Also aliased as: variables!
depends_on!(*args)
Alias for: _depends_on
resource_id!(*args)
Alias for: _resource_id
stack_output!(stack_name, output_name)
Alias for: _stack_output
variables!(*args)
Alias for: _variables