Sha256: ffd1e06628fdd45a915097b78e1d72bc5ed2d4fd0e1f713a915d11829a200d73

Contents?: true

Size: 1.68 KB

Versions: 64

Compression:

Stored size: 1.68 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

64 entries across 64 versions & 1 rubygems

Version Path
aws-crt-0.4.0-x86_64-linux lib/aws-crt/auth/signer.rb
aws-crt-0.4.0-x86_64-darwin lib/aws-crt/auth/signer.rb
aws-crt-0.4.0-universal-java lib/aws-crt/auth/signer.rb
aws-crt-0.4.0-arm64-darwin lib/aws-crt/auth/signer.rb
aws-crt-0.4.0-aarch64-linux lib/aws-crt/auth/signer.rb
aws-crt-0.4.0 lib/aws-crt/auth/signer.rb
aws-crt-0.3.0 lib/aws-crt/auth/signer.rb
aws-crt-0.3.0-x86_64-linux lib/aws-crt/auth/signer.rb
aws-crt-0.3.0-x86_64-darwin lib/aws-crt/auth/signer.rb
aws-crt-0.3.0-universal-java lib/aws-crt/auth/signer.rb
aws-crt-0.3.0-arm64-darwin lib/aws-crt/auth/signer.rb
aws-crt-0.3.0-aarch64-linux lib/aws-crt/auth/signer.rb
aws-crt-0.2.1-aarch64-linux lib/aws-crt/auth/signer.rb
aws-crt-0.2.1-arm64-darwin lib/aws-crt/auth/signer.rb
aws-crt-0.2.1-universal-java lib/aws-crt/auth/signer.rb
aws-crt-0.2.1-x86_64-darwin lib/aws-crt/auth/signer.rb
aws-crt-0.2.1-x86_64-linux lib/aws-crt/auth/signer.rb
aws-crt-0.2.1 lib/aws-crt/auth/signer.rb
aws-crt-0.2.0-x86_64-linux lib/aws-crt/auth/signer.rb
aws-crt-0.2.0-x86_64-darwin lib/aws-crt/auth/signer.rb