defaults

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package defaults is a collection of helpers to retrieve the SDK's default configuration and handlers.

Generally this package shouldn't be used directly, but external.Config instead. This package is useful when you need to reset the defaults of a service client to the SDK defaults before setting additional parameters.

Index

Constants

This section is empty.

Variables

View Source
var AddHostExecEnvUserAgentHander = aws.NamedHandler{
	Name: "core.AddHostExecEnvUserAgentHander",
	Fn: func(r *aws.Request) {
		v := os.Getenv(execEnvVar)
		if len(v) == 0 {
			return
		}

		aws.AddToUserAgent(r, execEnvUAKey+"/"+v)
	},
}

AddHostExecEnvUserAgentHander is a request handler appending the SDK's execution environment to the user agent.

If the environment variable AWS_EXECUTION_ENV is set, its value will be appended to the user agent string.

View Source
var AfterRetryHandler = aws.NamedHandler{Name: "core.AfterRetryHandler", Fn: func(r *aws.Request) {

	if r.Retryable == nil || r.Config.EnforceShouldRetryCheck {
		r.Retryable = aws.Bool(r.ShouldRetry(r))
	}

	if r.WillRetry() {
		r.RetryDelay = r.RetryRules(r)

		if err := sdk.SleepWithContext(r.Context(), r.RetryDelay); err != nil {
			r.Error = awserr.New(aws.ErrCodeRequestCanceled,
				"request context canceled", err)
			r.Retryable = aws.Bool(false)
			return
		}

		if p, ok := r.Config.Credentials.(sdk.Invalidator); ok && r.IsErrorExpired() {
			p.Invalidate()
		}

		r.RetryCount++
		r.Error = nil
	}
}}

AfterRetryHandler performs final checks to determine if the request should be retried and how long to delay.

View Source
var BuildContentLengthHandler = aws.NamedHandler{Name: "core.BuildContentLengthHandler", Fn: func(r *aws.Request) {
	var length int64

	if slength := r.HTTPRequest.Header.Get("Content-Length"); slength != "" {
		length, _ = strconv.ParseInt(slength, 10, 64)
	} else {
		switch body := r.Body.(type) {
		case nil:
			length = 0
		case lener:
			length = int64(body.Len())
		case io.Seeker:
			r.BodyStart, _ = body.Seek(0, 1)
			end, _ := body.Seek(0, 2)
			body.Seek(r.BodyStart, 0)
			length = end - r.BodyStart
		default:
			panic("Cannot get length of body, must provide `ContentLength`")
		}
	}

	if length > 0 {
		r.HTTPRequest.ContentLength = length
		r.HTTPRequest.Header.Set("Content-Length", fmt.Sprintf("%d", length))
	} else {
		r.HTTPRequest.ContentLength = 0
		r.HTTPRequest.Header.Del("Content-Length")
	}
}}

BuildContentLengthHandler builds the content length of a request based on the body, or will use the HTTPRequest.Header's "Content-Length" if defined. If unable to determine request body length and no "Content-Length" was specified it will panic.

The Content-Length will only be added to the request if the length of the body is greater than 0. If the body is empty or the current `Content-Length` header is <= 0, the header will also be stripped.

View Source
var SDKVersionUserAgentHandler = aws.NamedHandler{
	Name: "core.SDKVersionUserAgentHandler",
	Fn: aws.MakeAddToUserAgentHandler(aws.SDKName, aws.SDKVersion,
		runtime.Version(), runtime.GOOS, runtime.GOARCH),
}

SDKVersionUserAgentHandler is a request handler for adding the SDK Version to the user agent.

View Source
var SendHandler = aws.NamedHandler{
	Name: "core.SendHandler",
	Fn: func(r *aws.Request) {
		sender := sendFollowRedirects
		if r.DisableFollowRedirects {
			sender = sendWithoutFollowRedirects
		}

		if aws.NoBody == r.HTTPRequest.Body {

			reqOrig, reqCopy := r.HTTPRequest, *r.HTTPRequest
			reqCopy.Body = nil
			r.HTTPRequest = &reqCopy
			defer func() {
				r.HTTPRequest = reqOrig
			}()
		}

		var err error
		r.HTTPResponse, err = sender(r)
		if err != nil {
			handleSendError(r, err)
		}
	},
}

SendHandler is a request handler to send service request using HTTP client.

View Source
var ValidateEndpointHandler = aws.NamedHandler{Name: "core.ValidateEndpointHandler", Fn: func(r *aws.Request) {
	if r.Metadata.SigningRegion == "" && r.Config.Region == "" {
		r.Error = aws.ErrMissingRegion
	} else if r.Metadata.Endpoint == "" {
		r.Error = aws.ErrMissingEndpoint
	}
}}

ValidateEndpointHandler is a request handler to validate a request had the appropriate Region and Endpoint set. Will set r.Error if the endpoint or region is not valid.

View Source
var ValidateParametersHandler = aws.NamedHandler{Name: "core.ValidateParametersHandler", Fn: func(r *aws.Request) {
	if !r.ParamsFilled() {
		return
	}

	if v, ok := r.Params.(aws.Validator); ok {
		if err := v.Validate(); err != nil {
			r.Error = err
		}
	}
}}

ValidateParametersHandler is a request handler to validate the input parameters. Validating parameters only has meaning if done prior to the request being sent.

View Source
var ValidateReqSigHandler = aws.NamedHandler{
	Name: "core.ValidateReqSigHandler",
	Fn: func(r *aws.Request) {

		if r.Config.Credentials == aws.AnonymousCredentials {
			return
		}

		signedTime := r.Time
		if !r.LastSignedAt.IsZero() {
			signedTime = r.LastSignedAt
		}

		if signedTime.Add(10 * time.Minute).After(time.Now()) {
			return
		}

		r.Sign()
	},
}

ValidateReqSigHandler is a request handler to ensure that the request's signature doesn't expire before it is sent. This can happen when a request is built and signed significantly before it is sent. Or significant delays occur when retrying requests that would cause the signature to expire.

View Source
var ValidateResponseHandler = aws.NamedHandler{Name: "core.ValidateResponseHandler", Fn: func(r *aws.Request) {
	if r.HTTPResponse.StatusCode == 0 || r.HTTPResponse.StatusCode >= 300 {

		r.Error = awserr.New("UnknownError", "unknown error", nil)
	}
}}

ValidateResponseHandler is a request handler to validate service response.

Functions

func Config

func Config() aws.Config

Config returns the default configuration without credentials. To retrieve a config with credentials also included use `defaults.Get().Config` instead.

Generally you shouldn't need to use this method directly, but is available if you need to reset the configuration of an existing service client.

func HTTPClient

func HTTPClient() *http.Client

HTTPClient will return a new HTTP Client configured for the SDK.

Does not use http.DefaultClient nor http.DefaultTransport.

func Handlers

func Handlers() aws.Handlers

Handlers returns the default request handlers.

Generally you shouldn't need to use this method directly, but is available if you need to reset the request handlers of an existing service client.

func Logger

func Logger() aws.Logger

Logger returns a Logger which will write log messages to stdout, and use same formatting runes as the stdlib log.Logger

Types

This section is empty.

Jump to

Keyboard shortcuts

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