class AwsCftTools::Client::CFT

CloudFormation Client

All of the business logic behind direct interaction with the AWS API for CloudFormation templates and stacks.

Public Class Methods

aws_client_class() click to toggle source
# File lib/aws_cft_tools/client/cft.rb, line 29
def self.aws_client_class
  Aws::CloudFormation::Client
end
new(options) click to toggle source

@param options [Hash] client configuration @option options [String] :environment the operational environment in which to act @option options [String] :profile the AWS credential profile to use @option options [String] :region the AWS region in which to act

Calls superclass method AwsCftTools::Client::Base::new
# File lib/aws_cft_tools/client/cft.rb, line 25
def initialize(options)
  super(options)
end

Public Instance Methods

all_stacks() click to toggle source

List all of the stacks in CloudFormation.

@return [Array<OpenStruct>]

# File lib/aws_cft_tools/client/cft.rb, line 61
def all_stacks
  @all_stacks ||= AWSEnumerator.new(aws_client, :describe_stacks, &method(:map_stacks)).to_a
end
exports() click to toggle source

Lists all exports from stacks in CloudFormation.

@return [Array<Aws::CloudFormation::Types::Export>]

# File lib/aws_cft_tools/client/cft.rb, line 38
def exports
  @exports ||= AWSEnumerator.new(aws_client, :list_exports, {}, &:exports).to_a
end
stacks() click to toggle source

Lists all of the stacks in CloudFormation that are specific to the selected environment.

@return [Array<OpenStruct>]

# File lib/aws_cft_tools/client/cft.rb, line 47
def stacks
  @stacks ||= all_stacks.select do |stack|
    tags = stack.tags
    satisfies_environment(tags) &&
      satisfies_role(tags) &&
      satisfies_tags(tags)
  end
end

Private Instance Methods

map_stacks(resp) click to toggle source
# File lib/aws_cft_tools/client/cft.rb, line 67
def map_stacks(resp)
  resp.stacks.map { |stack| Stack.new(stack, aws_client) }
end
satisfies_environment(tag_set) click to toggle source
# File lib/aws_cft_tools/client/cft.rb, line 71
def satisfies_environment(tag_set)
  env = options[:environment]
  !env || tag_set['Environment'] == env
end
satisfies_role(tag_set) click to toggle source
# File lib/aws_cft_tools/client/cft.rb, line 76
def satisfies_role(tag_set)
  role = options[:role]
  !role || tag_set['Role'] == role
end
satisfies_tag(tags, key, value) click to toggle source
# File lib/aws_cft_tools/client/cft.rb, line 87
def satisfies_tag(tags, key, value)
  tag = tags[key]
  !tag || tag == value
end
satisfies_tags(tag_set) click to toggle source
# File lib/aws_cft_tools/client/cft.rb, line 81
def satisfies_tags(tag_set)
  tags = options[:tags]
  return true unless tags
  tag_set.all? { |key, value| satisfies_tag(tags, key, value) }
end