Sha256: bb1a7ff022170cafd9704c6b3ae87114dd3f80e26631983364278a816aa413f1

Contents?: true

Size: 1.37 KB

Versions: 997

Compression:

Stored size: 1.37 KB

Contents

module Aws
  module Signers
    class V2 < Base

      # @param [Http::Request] http_request
      def sign(http_request)
        params = http_request.body.param_list
        params.set('AWSAccessKeyId', @credentials.access_key_id)
        params.set('SecurityToken', @credentials.session_token) if
          @credentials.session_token
        params.set('Timestamp', Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ'))
        params.set('SignatureVersion', '2')
        params.set('SignatureMethod', 'HmacSHA256')
        params.delete('Signature')
        params.set('Signature', signature(http_request, params))
        http_request.body = params.to_io
      end

      private

      def signature(http_request, params)
        sha256_hmac(string_to_sign(http_request, params))
      end

      def string_to_sign(http_request, params)
        [
          http_request.http_method,
          host(http_request.endpoint),
          path(http_request.endpoint),
          params.to_s,
        ].join("\n")
      end

      def host(endpoint)
        host = endpoint.host.downcase
        if
          (endpoint.scheme == 'http' && endpoint.port != 80) ||
          (endpoint.scheme == 'https' && endpoint.port != 443)
        then
          host += ":#{endpoint.port}"
        end
        host
      end

      def path(endpoint)
        endpoint.path == '' ? '/' : endpoint.path
      end

    end
  end
end

Version data entries

997 entries across 997 versions & 2 rubygems

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