Sha256: 3f0898f46182f87f8e3a411c51a7698cdfaf3d7a2b0dc0fdd714540298d74cc1

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

module Humidifier
  # A container module for all adapters for the SDK
  module AwsAdapters
    # The parent class for the adapters for both versions of the SDK
    class Base
      # Create a CFN stack
      def create(payload)
        try_valid do
          response = client.create_stack(payload.create_params)
          payload.id = response.stack_id
          response
        end
      end

      # Delete a CFN stack
      def delete(payload)
        client.delete_stack(payload.delete_params)
        true
      end

      # Update a CFN stack if it exists, otherwise create it
      def deploy(payload)
        exists?(payload) ? update(payload) : create(payload)
      end

      # Update a CFN stack
      def update(payload)
        try_valid { client.update_stack(payload.update_params) }
      end

      # Upload a CFN stack to S3 so that it can be referenced via template_url
      def upload(payload)
        Humidifier.config.ensure_upload_configured!(payload)
        upload_object(payload, "#{Humidifier.config.s3_prefix}#{payload.identifier}.json")
      end

      # Validate a template in CFN
      def valid?(payload)
        try_valid { client.validate_template(payload.validate_params) }
      end

      %i[create delete deploy update].each do |method|
        define_method(:"#{method}_and_wait") do |payload|
          perform_and_wait(method, payload)
        end
      end

      private

      def client
        @client ||= base_module::CloudFormation::Client.new(region: AwsShim::REGION)
      end

      def try_valid
        yield || true
      rescue base_module::CloudFormation::Errors::ValidationError => error
        $stderr.puts error.message
        $stderr.puts error.backtrace
        false
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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