Sha256: 95401b58aa947fb300021508a27286b71aec6be30ac875cea7ff5ffd3bcb324c

Contents?: true

Size: 1.36 KB

Versions: 22

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Aws
  module Plugins
    # @api private
    # Deprecated - does not look at new traits like `auth` and `unsignedPayload`
    # Necessary to exist after endpoints 2.0 for old service clients + new core
    class SignatureV2 < Seahorse::Client::Plugin

      option(:v2_signer) do |cfg|
        Aws::Sigv2::Signer.new(credentials_provider: cfg.credentials)
      end

      def add_handlers(handlers, _)
        handlers.add(Handler, step: :sign)
      end

      class Handler < Seahorse::Client::Handler

        def call(context)
          apply_signature(
            context.http_request,
            context.config.v2_signer
          )
          @handler.call(context)
        end

        private

        def apply_signature(req, signer)

          param_list = req.body.param_list
          param_list.delete('Timestamp') # in case of re-signing

          signature = signer.sign_request(
            http_method: req.http_method,
            url: req.endpoint,
            params: param_list.inject({}) do |hash, param|
              hash[param.name] = param.value
              hash
            end
          )

          # apply signature
          signature.each_pair do |param_name, param_value|
            param_list.set(param_name, param_value)
          end

          req.body = param_list.to_io

        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
aws-sdk-core-3.214.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.213.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.212.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.211.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.210.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.209.1 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.209.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.208.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.207.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.206.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.205.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.204.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.203.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.202.2 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.202.1 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.202.0 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.201.5 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.201.4 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.201.3 lib/aws-sdk-core/plugins/signature_v2.rb
aws-sdk-core-3.201.2 lib/aws-sdk-core/plugins/signature_v2.rb