awsmiddleware

package module
v0.0.0-...-b7481e4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 15 Imported by: 6

README

AWS Middleware

An AWS middleware extension provides request and/or response handlers that can be configured on AWS SDK v1/v2 clients. Other components can configure their AWS SDK clients using awsmiddleware.GetConfigurer and passing the SDKv1 or SDKv2 options into the Configure function available on the Configurer.

The awsmiddleware.Extension interface extends component.Extension by adding the following method:

Handlers() ([]RequestHandler, []ResponseHandler)

The awsmiddleware.RequestHandler interface contains the following methods:

ID() string
Position() HandlerPosition
HandleRequest(ctx context.Context, r *http.Request)

The awsmiddleware.ResponseHandler interface contains the following methods:

ID() string
Position() HandlerPosition
HandleResponse(ctx context.Context, r *http.Response)
  • ID uniquely identifies a handler. Middleware will fail if there is clashing
  • Position determines whether the handler is appended to the front or back of the existing list. Insertion is done in the order of the handlers provided.
  • HandleRequest/Response provides a hook to handle the request/response before and after they've been sent along with the context.

There are a functions available that can be used to extract metadata from the context.

Documentation

Overview

Package awsmiddleware defines an extension interface providing request and response handlers that can be configured on AWS SDK clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOperationName

func GetOperationName(ctx context.Context) string

GetOperationName retrieves the service operation metadata from the context.

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID retrieves the generated request ID from the context.

func TryConfigure

func TryConfigure(logger *zap.Logger, host component.Host, middlewareID component.ID, sdkVersion SDKVersion)

TryConfigure is a helper function that will try to get the extension and configure the provided AWS SDK with it.

Types

type Configurer

type Configurer struct {
	// contains filtered or unexported fields
}

Configurer provides functions for applying request/response handlers to the AWS SDKs.

func GetConfigurer

func GetConfigurer(extensions map[component.ID]component.Component, middlewareID component.ID) (*Configurer, error)

GetConfigurer retrieves the extension implementing Middleware based on the middlewareID and wraps it in a Configurer.

func NewConfigurer

func NewConfigurer(requestHandlers []RequestHandler, responseHandlers []ResponseHandler) *Configurer

NewConfigurer sets the request/response handlers.

func (Configurer) Configure

func (c Configurer) Configure(sdkVersion SDKVersion) error

Configure configures the handlers on the provided AWS SDK.

type Extension

type Extension interface {
	extension.Extension
	Middleware
}

Extension is an extension that implements Middleware.

type HandlerPosition

type HandlerPosition int

HandlerPosition is the relative position of a handler used during insertion.

const (
	After HandlerPosition = iota
	Before
)

func (HandlerPosition) MarshalText

func (h HandlerPosition) MarshalText() (text []byte, err error)

MarshalText converts the position into a byte slice. Returns an error if unsupported.

func (HandlerPosition) String

func (h HandlerPosition) String() string

String returns the string representation of the position. Returns an empty string if position is unsupported.

func (*HandlerPosition) UnmarshalText

func (h *HandlerPosition) UnmarshalText(text []byte) error

UnmarshalText converts the string into a position. Returns an error if unsupported.

type Middleware

type Middleware interface {
	Handlers() ([]RequestHandler, []ResponseHandler)
}

Middleware defines the request and response handlers to be configured on AWS Clients.

type MockExtensionsHost

type MockExtensionsHost struct {
	component.Host
	mock.Mock
}

MockExtensionsHost only mocks the GetExtensions function. All other functions are ignored and will panic if called.

func (*MockExtensionsHost) GetExtensions

func (m *MockExtensionsHost) GetExtensions() map[component.ID]component.Component

type MockHandler

type MockHandler struct {
	mock.Mock
}

MockHandler mocks the functions for both RequestHandler and ResponseHandler.

func (*MockHandler) HandleRequest

func (m *MockHandler) HandleRequest(ctx context.Context, r *http.Request)

func (*MockHandler) HandleResponse

func (m *MockHandler) HandleResponse(ctx context.Context, r *http.Response)

func (*MockHandler) ID

func (m *MockHandler) ID() string

func (*MockHandler) Position

func (m *MockHandler) Position() HandlerPosition

type MockMiddlewareExtension

type MockMiddlewareExtension struct {
	component.StartFunc
	component.ShutdownFunc
	mock.Mock
}

MockMiddlewareExtension mocks the Extension interface.

func (*MockMiddlewareExtension) Handlers

type RequestHandler

type RequestHandler interface {
	HandleRequest(ctx context.Context, r *http.Request)
	// contains filtered or unexported methods
}

RequestHandler allows for custom processing of requests.

type ResponseHandler

type ResponseHandler interface {
	HandleResponse(ctx context.Context, r *http.Response)
	// contains filtered or unexported methods
}

ResponseHandler allows for custom processing of responses.

type SDKVersion

type SDKVersion interface {
	// contains filtered or unexported methods
}

func SDKv1

func SDKv1(handlers *request.Handlers) SDKVersion

SDKv1 takes in AWS SDKv1 client request handlers.

func SDKv2

func SDKv2(cfg *aws.Config) SDKVersion

SDKv2 takes in an AWS SDKv2 config.

Jump to

Keyboard shortcuts

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