awsv4

package
v1.11.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package awsv4 implements signing for AWS V4 signer with static credentials, and is based on and modified from code in the package aws-sdk-go. The modifications remove non-static credentials, support for non-sts services, and the options for v4.Signer. They also reduce the number of non-Go library dependencies.

Index

Constants

View Source
const StaticProviderName = "StaticProvider"

StaticProviderName provides a name of Static provider

Variables

View Source
var (
	// ErrStaticCredentialsEmpty is emitted when static credentials are empty.
	ErrStaticCredentialsEmpty = errors.New("EmptyStaticCreds: static credentials are empty")
)

Functions

func EscapePath

func EscapePath(path string, encodeSep bool) string

EscapePath escapes part of a URL path in Amazon style

func GetSignedRequestSignature

func GetSignedRequestSignature(r *http.Request) ([]byte, error)

GetSignedRequestSignature attempts to extract the signature of the request. Returning an error if the request is unsigned, or unable to extract the signature.

Types

type Signer

type Signer struct {
	Credentials *StaticProvider
}

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

func NewSigner

func NewSigner(credentials *StaticProvider) *Signer

NewSigner returns a Signer pointer configured with the credentials and optional option values provided. If not options are provided the Signer will use its default configuration.

func (Signer) Sign

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.

type StaticProvider

type StaticProvider struct {
	Value
}

A StaticProvider is a set of credentials which are set programmatically, and will never expire.

func (*StaticProvider) Retrieve

func (s *StaticProvider) Retrieve() (Value, error)

Retrieve returns the credentials or error if the credentials are invalid.

type Value

type Value struct {
	// AWS Access key ID
	AccessKeyID string

	// AWS Secret Access Key
	SecretAccessKey string

	// AWS Session Token
	SessionToken string

	// Provider used to get credentials
	ProviderName string
}

A Value is the AWS credentials value for individual credential fields.

func (Value) HasKeys

func (v Value) HasKeys() bool

HasKeys returns if the credentials Value has both AccessKeyID and SecretAccessKey value set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL