Module: Jackal::Stacks::StackCommon

Included in:
Builder, Wrecker
Defined in:
lib/jackal-stacks/stack_common.rb

Instance Method Summary collapse

Instance Method Details

#api_configHash

Returns API connection configuration.

Returns:

  • (Hash)

    API connection configuration



13
14
15
16
17
# File 'lib/jackal-stacks/stack_common.rb', line 13

def api_config
  config.fetch(:orchestration, :api, Smash.new).merge(
    :type => :orchestration
  )
end

#determine_namespace(payload) ⇒ String

Note:

if not match found, ‘default` will return

Determine namespace key to use for accessing parameters

Parameters:

  • payload (Smash)

Returns:

  • (String)


24
25
26
27
28
# File 'lib/jackal-stacks/stack_common.rb', line 24

def determine_namespace(payload)
  config.fetch(:mappings, Smash.new).map do |ns, glob|
    ns if File.fnmatch?(glob, payload.get(:data, :stacks, :reference).to_s)
  end.compact.first
end

#stack_name(payload) ⇒ String

Generate stack name based on payload

Parameters:

  • payload (Smash)

Returns:

  • (String)

    stack name



34
35
36
37
38
39
40
41
42
# File 'lib/jackal-stacks/stack_common.rb', line 34

def stack_name(payload)
  s_namespace = determine_namespace(payload)
  s_project = payload.fetch(:data, :stacks, :project, SecureRandom.urlsafe_base64)
  [
    s_namespace,
    s_project,
    payload.get(:data, :stacks, :template).sub(/\.[a-z]+$/, '')
  ].compact.join('-').gsub(/[^A-Za-z0-9\-]/, '-')
end

#stacks_apiMiasma::Models::Orchestration

Returns:

  • (Miasma::Models::Orchestration)


8
9
10
# File 'lib/jackal-stacks/stack_common.rb', line 8

def stacks_api
  Miasma.api(api_config)
end