Sha256: ef834d42570285773a9a7cf72f8c57bda0b061217f8bb4ac5ecd866a31ffb242

Contents?: true

Size: 1.58 KB

Versions: 863

Compression:

Stored size: 1.58 KB

Contents

require 'aws-sigv4'

module Aws
  module Plugins

    # This plugin auto populates the following request params for the
    # CopySnapshot API:
    #
    # * `:destination_region`
    # * `:presigned_url`
    #
    # These params are required by EC2 when copying an encrypted snapshot.
    class EC2CopyEncryptedSnapshot < Seahorse::Client::Plugin

      # @api private
      class Handler < Seahorse::Client::Handler

        def call(context)
          params = context.params
          params[:destination_region] = context.config.region
          params[:presigned_url] = presigned_url(context, params)
          @handler.call(context)
        end

        private

        def presigned_url(context, params)
          param_list = Aws::Query::ParamList.new
          param_list.set('Action', 'CopySnapshot')
          param_list.set('DestinationRegion', context.config.region)
          param_list.set('Version', context.config.api.metadata['apiVersion'])
          Aws::Query::EC2ParamBuilder.new(param_list).apply(context.operation.input, params)

          signer = Aws::Sigv4::Signer.new(
            service: 'ec2',
            region: params[:source_region],
            credentials_provider: context.config.credentials
          )
          url = Aws::EndpointProvider.resolve(signer.region, 'ec2')
          url += "?#{param_list.to_s}"

          signer.presign_url(
            http_method: 'GET',
            url: url,
            body: '',
            expires_in: 3600
          ).to_s
        end

      end

      handler(Handler, step: :initialize, operations: [:copy_snapshot])

    end
  end
end

Version data entries

863 entries across 863 versions & 1 rubygems

Version Path
aws-sdk-core-2.11.632 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.631 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.630 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.629 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.628 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.627 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.626 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.625 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.624 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.623 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.622 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.621 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.620 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.619 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.618 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.617 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.616 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.615 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.614 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb
aws-sdk-core-2.11.613 lib/aws-sdk-core/plugins/ec2_copy_encrypted_snapshot.rb