Sha256: 41398620a327d7cd50bc89b12fbc6a806a35ff497410eb272b0dd4956fde744c

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require 'cloud_formation/bridge/exception_notifier'
require 'cloud_formation/bridge/names'
require 'cloud_formation/bridge/resources/subscribe_queue_to_topic'
require 'cloud_formation/bridge/resources/cloud_formation_outputs'

module CloudFormation
  module Bridge
    class Executor

      include CloudFormation::Bridge::Names

      DEFAULT_REGISTRY = {
        "Custom::SubscribeSQSQueueToSNSTopic" =>
          CloudFormation::Bridge::Resources::SubscribeQueueToTopic.new,
        "Custom::CloudFormationOutputs" =>
          CloudFormation::Bridge::Resources::CloudFormationOutputs.new,
      }

      attr_reader :registry

      def initialize(registry = DEFAULT_REGISTRY)
        @registry = registry
      end

      def execute(request)

        begin
          if resource = registry[request.resource_type]
            response = if request.create?
              resource.create(request)
            elsif request.update?
              resource.update(request)
            else
              resource.delete(request)
            end

            request.succeed!(response)
          else
            request.fail!("Don't know what to do with resource #{request.resource_type}")
          end
        rescue Exception => ex
          ExceptionNotifier.report_exception(ex, request.request)
          request.fail!(ex.message)
        end

      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cfn-bridge-0.0.9 lib/cloud_formation/bridge/executor.rb
cfn-bridge-0.0.8 lib/cloud_formation/bridge/executor.rb
cfn-bridge-0.0.7 lib/cloud_formation/bridge/executor.rb
cfn-bridge-0.0.6 lib/cloud_formation/bridge/executor.rb