Sha256: 64c90538a73806ab16ed64327841be6f51d0cead50834122a1f7ab263b2b42c1

Contents?: true

Size: 1.73 KB

Versions: 11

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module Aws
  module Crt
    # High level Ruby abstractions for CRT Auth functionality
    module Auth
      # Ruby interface to CRT signing functions
      module Signer
        # Sign a request
        # @param [SigningConfig] - SigningConfig to apply to this signature
        # @param [Signable] - Signable object (request) to sign.
        #
        # @return [Hash] Return a hash with keys:
        #   * signature[String] - the computed signature
        #   * headers[Hash] - signed headers, including the `Authorization`
        #      header.
        def self.sign_request(
          signing_config, signable, method = 'default', path = 'default'
        )
          out = {}
          callback = proc do |result, status, _userdata|
            Aws::Crt::Errors.raise_last_error unless status.zero?
            http_request = Http::Message.new(method, path)
            Aws::Crt::Native.signing_result_apply_to_http_request(
              result,
              http_request.native
            )
            out[:path] = http_request.path
            out[:headers] = http_request.headers
            if (auth = out[:headers]['Authorization']) &&
               (match = /Signature=([a-f0-9]+)/.match(auth))
              out[:signature] = match[1]
            end
            out[:http_request] = http_request

            nil
          end

          # Currently this will always be synchronous
          # (because we are resolving credentials) - so do not need to
          # sync threads/callbacks
          Aws::Crt::Native.sign_request_aws(
            signable.native, signing_config.native, callback, nil
          )
          out
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
aws-crt-0.4.0-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.3.0-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.2.1-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.2.0-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.1.9-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.1.8-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.1.7-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.1.6-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.1.5-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.1.4-x64-mingw32 lib/aws-crt/auth/signer.rb
aws-crt-0.1.2-x86_64-mingw32 lib/aws-crt/auth/signer.rb