gems/aws-sigv4/lib/aws-sigv4/signer.rb
def sign_request(request)

        creds = get_credentials

        http_method = extract_http_method(request)
        url = extract_url(request)
        headers = downcase_headers(request[:headers])

        datetime = headers['x-amz-date']
        datetime ||= Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
        date = datetime[0,8]

        content_sha256 = headers['x-amz-content-sha256']
        content_sha256 ||= sha256_hexdigest(request[:body] || '')

        sigv4_headers = {}
        sigv4_headers['host'] = host(url)
        sigv4_headers['x-amz-date'] = datetime
        sigv4_headers['x-amz-security-token'] = creds.session_token if creds.session_token
        sigv4_headers['x-amz-content-sha256'] ||= content_sha256 if @apply_checksum_header

        headers = headers.merge(sigv4_headers) # merge so we do not modify given headers hash

        # compute signature parts
        creq = canonical_request(http_method, url, headers, content_sha256)
        sts = string_to_sign(datetime, creq)
        sig = signature(creds.secret_access_key, date, sts)

        # apply signature
        sigv4_headers['authorization'] = [
          "AWS4-HMAC-SHA256 Credential=#{credential(creds, date)}",
          "SignedHeaders=#{signed_headers(headers)}",
          "Signature=#{sig}",
        ].join(', ')

        # Returning the signature components.
        Signature.new(
          headers: sigv4_headers,
          string_to_sign: sts,
          canonical_request: creq,
          content_sha256: content_sha256
        )
      end
# Computes a version 4 signature signature. Returns the resultant
# signature as a hash of headers to apply to your HTTP request. The given
# request is not modified.
#
#     signature = signer.sign_request(
#       http_method: 'PUT',
#       url: 'https://domain.com',
#       headers: {
#         'Abc' => 'xyz',
#       },
#       body: 'body' # String or IO object
#     )
#
#     # Apply the following hash of headers to your HTTP request
#     signature.headers['host']
#     signature.headers['x-amz-date']
#     signature.headers['x-amz-security-token']
#     signature.headers['x-amz-content-sha256']
#     signature.headers['authorization']
#
# In addition to computing the signature headers, the canonicalized
# request, string to sign and content sha256 checksum are also available.
# These values are useful for debugging signature errors returned by AWS.
#
#     signature.canonical_request #=> "..."
#     signature.string_to_sign #=> "..."
#     signature.content_sha256 #=> "..."
#
# @param [Hash] request
#
# @option request [required, String] :http_method One of
#   'GET', 'HEAD', 'PUT', 'POST', 'PATCH', or 'DELETE'
#
# @option request [required, String, URI::HTTPS, URI::HTTP] :url
#   The request URI. Must be a valid HTTP or HTTPS URI.
#
# @option request [optional, Hash] :headers ({}) A hash of headers
#   to sign. If the 'X-Amz-Content-Sha256' header is set, the `:body`
#   is optional and will not be read.
#
# @option request [optional, String, IO] :body ('') The HTTP request body.
#   A sha256 checksum is computed of the body unless the
#   'X-Amz-Content-Sha256' header is set.
#
# @return [Signature] Return an instance of {Signature} that has
#   a `#headers` method. The headers must be applied to your request.
#
Computes a version 4 signature signature. Returns the resultant
signature as a hash of headers to apply to your HTTP request. The given
request is not modified.





In addition to computing the signature headers, the canonicalized
request, string to sign and content sha256 checksum are also available.
These values are useful for debugging signature errors returned by AWS.


Computes a version 4 signature signature . Returns the resultant signature as a hash of headers to apply to your HTTP request . The given request is not modified . In addition to computing the signature headers the canonicalized request string to sign and content sha256 checksum are also available . These values are useful for debugging signature errors returned by AWS .
def sign_request(request)
        creds = get_credentials
        http_method = extract_http_method(request)
        url = extract_url(request)
        headers = downcase_headers(request[:headers])
        datetime = headers['x-amz-date']
        datetime ||= Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
        date = datetime[0,8]
        content_sha256 = headers['x-amz-content-sha256']
        content_sha256 ||= sha256_hexdigest(request[:body] || '')
        sigv4_headers = {}
        sigv4_headers['host'] = host(url)
        sigv4_headers['x-amz-date'] = datetime
        sigv4_headers['x-amz-security-token'] = creds.session_token if creds.session_token
        sigv4_headers['x-amz-content-sha256'] ||= content_sha256 if @apply_checksum_header
        headers = headers.merge(sigv4_headers) 
        creq = canonical_request(http_method, url, headers, content_sha256)
        sts = string_to_sign(datetime, creq)
        sig = signature(creds.secret_access_key, date, sts)
        sigv4_headers['authorization'] = [
          "AWS4-HMAC-SHA256 Credential=#{credential(creds, date)}",
          "SignedHeaders=#{signed_headers(headers)}",
          "Signature=#{sig}",
        ].join(', ')
        Signature.new(
          headers: sigv4_headers,
          string_to_sign: sts,
          canonical_request: creq,
          content_sha256: content_sha256
        )
      end
def sign_request ( request ) creds = get_credentials http_method = extract_http_method ( request ) url = extract_url ( request ) headers = downcase_headers ( request [ :headers ] ) datetime = headers [ 'x-amz-date' ] datetime ||= Time . now . utc . strftime ( "%Y%m%dT%H%M%SZ" ) date = datetime [ 0 , 8 ] content_sha256 = headers [ 'x-amz-content-sha256' ] content_sha256 ||= sha256_hexdigest ( request [ :body ] || '' ) sigv4_headers = { } sigv4_headers [ 'host' ] = host ( url ) sigv4_headers [ 'x-amz-date' ] = datetime sigv4_headers [ 'x-amz-security-token' ] = creds . session_token if creds . session_token sigv4_headers [ 'x-amz-content-sha256' ] ||= content_sha256 if @apply_checksum_header headers = headers . merge ( sigv4_headers ) creq = canonical_request ( http_method , url , headers , content_sha256 ) sts = string_to_sign ( datetime , creq ) sig = signature ( creds . secret_access_key , date , sts ) sigv4_headers [ 'authorization' ] = [ "AWS4-HMAC-SHA256 Credential=#{credential(creds, date)}" , "SignedHeaders=#{signed_headers(headers)}" , "Signature=#{sig}" , ] . join ( ', ' ) Signature . new ( headers : sigv4_headers , string_to_sign : sts , canonical_request : creq , content_sha256 : content_sha256 ) end
Computes a version 4 signature signature.
Computes a version 4 signature signature .
# merge so we do not modify given headers hash # compute signature parts # apply signature # Returning the signature components.
Return an instance of {Signature} that has a `#headers` method. The headers must be applied to your request.
Return an instance of { Signature } that has a ` #headers ` method . The headers must be applied to your request .
Signature
request
:body ('') The HTTP request body. A sha256 checksum is computed of the body unless the 'X-Amz-Content-Sha256' header is set.
: body ( ' ' ) The HTTP request body . A sha256 checksum is computed of the body unless the ' X - Amz - Content - Sha256 ' header is set .
None