module Sfn::CommandModule::Base::InstanceMethods

Instance methods for cloudformation command classes

Public Instance Methods

_debug(e, *args) click to toggle source

Write exception information if debug is enabled

@param e [Exception] @param args [String] extra strings to output

# File lib/sfn/command_module/base.rb, line 70
def _debug(e, *args)
  if config[:verbose] || config[:debug]
    ui.fatal "Exception information: #{e.class}: #{e.message}"
    if ENV["DEBUG"] || config[:debug]
      puts "#{e.backtrace.join("\n")}\n"
      if e.is_a?(Miasma::Error::ApiError)
        ui.fatal "Response body: #{e.response.body.to_s.inspect}"
      end
    end
    args.each do |string|
      ui.fatal string
    end
  end
end
allowed_attributes() click to toggle source

@return [Array<String>] attributes to display

# File lib/sfn/command_module/base.rb, line 103
def allowed_attributes
  opts.fetch(:attributes, config.fetch(:attributes, default_attributes))
end
as_title(string) click to toggle source

Format snake cased key to title

@param string [String, Symbol] @return [String

# File lib/sfn/command_module/base.rb, line 89
def as_title(string)
  string.to_s.split("_").map(&:capitalize).join(" ")
end
attribute_allowed?(attr) click to toggle source

Check if attribute is allowed for display

@param attr [String] @return [TrueClass, FalseClass]

# File lib/sfn/command_module/base.rb, line 116
def attribute_allowed?(attr)
  opts.fetch(:all_attributes, config[:all_attributes], allowed_attributes.include?(attr))
end
config() click to toggle source

Override config method to memoize the result allowing for modifications to the configuration during runtime

@return [Smash] @note callback requires are also loaded here

Calls superclass method
# File lib/sfn/command_module/base.rb, line 159
def config
  memoize(:config) do
    result = super
    result.fetch(:callbacks, :require, []).each do |c_loader|
      require c_loader
    end
    result
  end
end
custom_stack_types() click to toggle source

@return [Array<String>]

# File lib/sfn/command_module/base.rb, line 17
def custom_stack_types
  [config.fetch(:stack_types, [])].flatten.compact
end
default_attributes() click to toggle source

@return [Array<String>] default attributes to display

# File lib/sfn/command_module/base.rb, line 108
def default_attributes
  %w(timestamp stack_name id)
end
get_things(stack = nil, message = nil) { || ... } click to toggle source

Wrapper for information retrieval. Provides consistent error message for failures

@param stack [String] stack name @param message [String] failure message @yield block to wrap error handling @return [Object] result of yield

# File lib/sfn/command_module/base.rb, line 136
def get_things(stack = nil, message = nil)
  begin
    yield
  rescue => e
    ui.fatal "#{message || "Failed to retrieve information"}#{" for requested stack: #{stack}" if stack}"
    ui.fatal "Reason: #{e}"
    _debug(e)
    exit 1
  end
end
name_args() click to toggle source

Simple compat proxy method

@return [Array<String>]

# File lib/sfn/command_module/base.rb, line 150
def name_args
  arguments
end
name_required!() click to toggle source

Force error exception when no name is provided

@return [NilClass] @raise [ArgumentError]

# File lib/sfn/command_module/base.rb, line 173
def name_required!
  if name_args.empty?
    ui.error "Name argument must be provided!"
    raise ArgumentError.new "Missing required name argument"
  end
end
poll_stack(name) click to toggle source

Poll events on stack

@param name [String] name of stack

# File lib/sfn/command_module/base.rb, line 123
def poll_stack(name)
  provider.connection.stacks.reload
  retry_attempts = 0
  events = Sfn::Command::Events.new({:poll => true}, [name]).execute!
end
provider(location = nil)
Alias for: provider_for
provider_for(location = nil) click to toggle source

Build provider connection for given location

@param location [Symbol, String] name of location @return [Sfn::Provider]

# File lib/sfn/command_module/base.rb, line 25
def provider_for(location = nil)
  key = ["provider", location].compact.map(&:to_s).join("_")
  if location
    credentials = config.get(:locations, location)
    unless credentials
      raise ArgumentError.new "Failed to locate provider credentials for location `#{location}`!"
    end
  else
    credentials = config[:credentials]
  end
  begin
    memoize(key) do
      result = Sfn::Provider.new(
        :miasma => credentials,
        :async => false,
        :fetch => false,
      )
      result.connection.data[:stack_types] = ([
        (result.connection.class.const_get(:RESOURCE_MAPPING).detect do |klass, info|
          info[:api] == :orchestration
        end || []).first,
      ] + custom_stack_types).compact.uniq
      retry_config = config.fetch(:retry,
                                  config.fetch(:retries, {}))
      result.connection.data[:retry_ui] = ui
      result.connection.data[:location] = location.to_s
      result.connection.data[:locations] = config.fetch(:locations, {})
      result.connection.data[:retry_type] = retry_config.fetch(:type, :exponential)
      result.connection.data[:retry_interval] = retry_config.fetch(:interval, 5)
      result.connection.data[:retry_max] = retry_config.fetch(:max_attempts, 20)
      result
    end
  rescue => e
    ui.error "Failed to create remote API connection. Please validate configuration!"
    ui.error "Connection failure reason - #{e.class} - #{e}"
    raise
  end
end
Also aliased as: provider
stack(name = nil) click to toggle source

Get stack

@param name [String] name of stack @return [Miasma::Models::Orchestration::Stack]

# File lib/sfn/command_module/base.rb, line 97
def stack(name = nil)
  name = name_args.first unless name
  provider.stacks.get(name)
end
valid_stack_types() click to toggle source

@return [Array<String>]

# File lib/sfn/command_module/base.rb, line 12
def valid_stack_types
  provider.connection.data[:stack_types]
end