Module: Aws::Crt::Auth::Signer

Defined in:
lib/aws-crt/auth/signer.rb

Overview

Ruby interface to CRT signing functions

Class Method Summary collapse

Class Method Details

.sign_request(signing_config, signable, method = 'default', path = 'default') ⇒ Hash

Sign a request

Parameters:

  • - (SigningConfig)

    SigningConfig to apply to this signature

  • - (Signable)

    Signable object (request) to sign.

Returns:

  • (Hash)

    Return a hash with keys:

    • signature - the computed signature
    • headers - signed headers, including the Authorization header.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/aws-crt/auth/signer.rb', line 17

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