Sha256: 146fb3f5a86d2cb202192563c2a605efbf890dda64643d613df3990beb6ee4d0

Contents?: true

Size: 1.77 KB

Versions: 9

Compression:

Stored size: 1.77 KB

Contents

module Humidifier
  module AwsAdapters
    # The adapter for v1 of aws-sdk
    class SDKV1 < Base
      # Cannot create change sets in V1
      def create_change_set(*)
        unsupported('create change set')
      end

      # Cannot deploy change sets in V1
      def deploy_change_set(*)
        unsupported('deploy change set')
      end

      # True if the stack exists in CFN
      def exists?(payload)
        base_module::CloudFormation::Stack.new(payload.identifier).exists?
      end

      private

      def base_module
        AWS
      end

      def handle_failure(payload)
        reasons = []
        client.describe_stack_events(stack_name: payload.identifier).stack_events.each do |event|
          next unless event.resource_status.include?('FAILED') && event.key?(:resource_status_reason)
          reasons.unshift(event.resource_status_reason)
        end
        raise "#{payload.name} stack failed:\n#{reasons.join("\n")}"
      end

      def perform_and_wait(method, payload)
        response = public_send(method, payload)

        aws_stack = nil
        Sleeper.new(payload.max_wait) do
          aws_stack = client.describe_stacks(stack_name: payload.identifier).stacks.first
          !aws_stack.stack_status.end_with?('IN_PROGRESS')
        end

        handle_failure(payload) if aws_stack.stack_status =~ /(FAILED|ROLLBACK)/
        response
      end

      def upload_object(payload, key)
        base_module.config(region: AwsShim::REGION)
        @s3 ||= base_module::S3.new
        @s3.buckets[Humidifier.config.s3_bucket].objects.create(key, payload.template_body).url_for(:read)
      end

      def unsupported(method)
        puts "WARNING: Cannot #{method} because that functionality is not supported in V1 of aws-sdk."
        false
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
humidifier-1.8.0 lib/humidifier/aws_adapters/sdkv1.rb
humidifier-1.7.0 lib/humidifier/aws_adapters/sdkv1.rb
humidifier-1.6.1 lib/humidifier/aws_adapters/sdkv1.rb
humidifier-1.6.0 lib/humidifier/aws_adapters/sdkv1.rb
humidifier-1.4.2 lib/humidifier/aws_adapters/sdkv1.rb
humidifier-1.4.1 lib/humidifier/aws_adapters/sdkv1.rb
humidifier-1.4.0 lib/humidifier/aws_adapters/sdkv1.rb
humidifier-1.3.1 lib/humidifier/aws_adapters/sdkv1.rb
humidifier-1.2.1 lib/humidifier/aws_adapters/sdkv1.rb