Sha256: 455df6152a6f18b53dd7ecf1ddb6789048ad60f1625aed847204da63e4ac9708

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

module OpenStax::Aws
  class ResourceFactory
    # All classes listed here should implement the self.physical_resource_id method
    ALL_TYPES = {
      'AWS::AutoScaling::AutoScalingGroup' => OpenStax::Aws::AutoScalingGroup,
      'AWS::CloudWatch::Alarm' => OpenStax::Aws::Alarm,
      'AWS::Events::Rule' => OpenStax::Aws::EventRule,
      'AWS::RDS::DBInstance' => OpenStax::Aws::RdsInstance,
      'AWS::MSK::Cluster' => OpenStax::Aws::MskCluster
    }

    attr_reader :region, :types

    def initialize(region:, types: nil)
      @region = region
      @types = types.nil? ? ALL_TYPES : ALL_TYPES.select { |type, _| types.include? type }
    end

    def from_stack_resource_or_summary(stack_resource)
      klass = types[stack_resource.resource_type]
      return if klass.nil?

      klass.new(
        region: region,
        klass.physical_resource_id_attribute => stack_resource.physical_resource_id
      )
    end

    def from_stack_resource_or_summary!(stack_resource)
      from_stack_resource_or_summary(stack_resource).tap do |resource|
        raise "'#{stack_resource.resource_type}' is not yet implemented in `ResourceFactory`" \
          if resource.nil?
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
openstax_aws-2.1.0 lib/openstax/aws/resource_factory.rb
openstax_aws-2.0.1 lib/openstax/aws/resource_factory.rb
openstax_aws-2.0.0 lib/openstax/aws/resource_factory.rb
openstax_aws-1.6.1 lib/openstax/aws/resource_factory.rb
openstax_aws-1.6.0 lib/openstax/aws/resource_factory.rb
openstax_aws-1.5.0 lib/openstax/aws/resource_factory.rb