Struct: v4.Signer

import "../ibm-cos-sdk-go/aws/signer/v4"

Overview

Signer applies AWS v4 signing to given request. Use this to sign requests that need to be signed with AWS V4 Signatures.

Implemented Interfaces

s3crypto.Cipher, s3manager.ReadSeekerWriteTo, s3manager.WriterReadFrom

Structure Field Summary collapse

Method Summary collapse

Structure Field Details

Credentials *credentials.Credentials

The authentication credentials the request will be signed against. This value must be set to sign requests.

Debug aws.LogLevelType

Sets the log level the signer should use when reporting information to the logger. If the logger is nil nothing will be logged. See aws.LogLevelType for more information on available logging levels

By default nothing will be logged.

DisableHeaderHoisting bool

Disables the Signer's moving HTTP header key/value pairs from the HTTP request header to the request's query string. This is most commonly used with pre-signed requests preventing headers from being added to the request's query string.

DisableRequestBodyOverwrite bool

Disables the automatical setting of the HTTP request's Body field with the io.ReadSeeker passed in to the signer. This is useful if you're using a custom wrapper around the body for the io.ReadSeeker and want to preserve the Body value on the Request.Body.

This does run the risk of signing a request with a body that will not be sent in the request. Need to ensure that the underlying data of the Body values are the same.

DisableURIPathEscaping bool

Disables the automatic escaping of the URI path of the request for the siganture's canonical string's path. For services that do not need additional escaping then use this to disable the signer escaping the path.

S3 is an example of a service that does not need additional escaping.

docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

Logger aws.Logger

The logger loging information will be written to. If there the logger is nil, nothing will be logged.

UnsignedPayload bool

UnsignedPayload will prevent signing of the payload. This will only work for services that have support for this.

Method Details

func (v4 Signer) Presign(r *http.Request, body io.ReadSeeker, service, region string, exp time.Duration, signTime time.Time) (http.Header, error)

Presign signs AWS v4 requests with the provided body, service name, region the request is made to, and time the request is signed at. The signTime allows you to specify that a request is signed for the future, and cannot be used until then.

Returns a list of HTTP headers that were included in the signature or an error if signing the request failed. For presigned requests these headers and their values must be included on the HTTP request when it is made. This is helpful to know what header values need to be shared with the party the presigned request will be distributed to.

Presign differs from Sign in that it will sign the request using query string instead of header values. This allows you to share the Presigned Request's URL with third parties, or distribute it throughout your system with minimal dependencies.

Presign also takes an exp value which is the duration the signed request will be valid after the signing time. This is allows you to set when the request will expire.

The requests body is an io.ReadSeeker so the SHA256 of the body can be generated. To bypass the signer computing the hash you can set the “X-Amz-Content-Sha256” header with a precomputed value. The signer will only compute the hash if the request header value is empty.

Presigning a S3 request will not compute the body's SHA256 hash by default. This is done due to the general use case for S3 presigned URLs is to share PUT/GET capabilities. If you would like to include the body's SHA256 in the presigned request's signature you can set the “X-Amz-Content-Sha256” HTTP header and that will be included in the request's signature.



311
312
313
// File 'aws/signer/v4/v4.go', line 311

func (v4 Signer) Presign(r *http.Request, body io.ReadSeeker, service, region string, exp time.Duration, signTime time.Time) (http.Header, error) { return v4.signWithBody(r, body, service, region, exp, true, signTime) }

func (v4 Signer) Sign(r *http.Request, body io.ReadSeeker, service, region string, signTime time.Time) (http.Header, error)

Sign signs AWS v4 requests with the provided body, service name, region the request is made to, and time the request is signed at. The signTime allows you to specify that a request is signed for the future, and cannot be used until then.

Returns a list of HTTP headers that were included in the signature or an error if signing the request failed. Generally for signed requests this value is not needed as the full request context will be captured by the http.Request value. It is included for reference though.

Sign will set the request's Body to be the body parameter passed in. If the body is not already an io.ReadCloser, it will be wrapped within one. If a nil body parameter passed to Sign, the request's Body field will be also set to nil. Its important to note that this functionality will not change the request's ContentLength of the request.

Sign differs from Presign in that it will sign the request using HTTP header values. This type of signing is intended for http.Request values that will not be shared, or are shared in a way the header values on the request will not be lost.

The requests body is an io.ReadSeeker so the SHA256 of the body can be generated. To bypass the signer computing the hash you can set the “X-Amz-Content-Sha256” header with a precomputed value. The signer will only compute the hash if the request header value is empty.



277
278
279
// File 'aws/signer/v4/v4.go', line 277

func (v4 Signer) Sign(r *http.Request, body io.ReadSeeker, service, region string, signTime time.Time) (http.Header, error) { return v4.signWithBody(r, body, service, region, 0, false, signTime) }