Sha256: 6fbc379f442f5183e3e35aa2239dcfadaafc96086613ad146b8e0a20de8322af

Contents?: true

Size: 1.73 KB

Versions: 106

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require 'aws-sigv4'

module Aws
  module EC2
    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.
      # @api private
      class CopyEncryptedSnapshot < 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.version)
            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::Partitions::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
end

Version data entries

106 entries across 106 versions & 1 rubygems

Version Path
aws-sdk-ec2-1.235.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.234.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.233.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.232.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.231.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.230.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.229.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.228.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.227.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.226.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.225.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.224.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.223.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.222.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.221.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.220.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.219.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.218.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.217.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb
aws-sdk-ec2-1.216.0 lib/aws-sdk-ec2/plugins/copy_encrypted_snapshot.rb