middlewares

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT, MIT, + 1 more Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBytesLimit = 512000
)

MaxBytesLimit is the max http request size, in bytes (see https://github.com/sensu/sensu-alpha-documentation/blob/master/97-FAQ.md)

Variables

This section is empty.

Functions

func Apply

func Apply(handler http.Handler, ms ...HTTPMiddleware) http.Handler

Apply applies given middleware left to right returning new http.Handler.

// without apply
my_router := mux.Router{}
my_stack := Auth{}.Then(my_router)
my_stack = Logger{}.Then(my_stack)
my_stack = Instrumentation{}.Then(my_stack)

// with apply
my_router := mux.Router{}
my_stack := Apply(my_router, Instrumentation{}, Logger{}, Authentication{})

func BasicAuthentication

func BasicAuthentication(next http.Handler, store AuthStore) http.Handler

BasicAuthentication is HTTP middleware for basic authentication

Types

type AllowList

type AllowList struct {
	Store store.Store

	// IgnoreMissingClaims configures the middleware to continue the handler chain
	// in the case where an access token was not present.
	IgnoreMissingClaims bool
}

AllowList verifies that the access token provided is authorized

func (AllowList) Then

func (m AllowList) Then(next http.Handler) http.Handler

Then ...

type AuthStore

type AuthStore interface {
	// AuthenticateUser attempts to authenticate a user with the given username
	// and hashed password. An error is returned if the user does not exist, is
	// disabled or the given password does not match.
	AuthenticateUser(ctx context.Context, user, pass string) (*types.User, error)
}

AuthStore specifies the storage requirements for auth types.

type Authentication

type Authentication struct {
	// IgnoreUnauthorized configures the middleware to continue the handler chain
	// in the case where an access token was not present.
	IgnoreUnauthorized bool
}

Authentication is a HTTP middleware that enforces authentication

func (Authentication) Then

func (a Authentication) Then(next http.Handler) http.Handler

Then middleware

type Authorization

type Authorization struct {
	Authorizer authorization.Authorizer
}

Authorization is an HTTP middleware that enforces authorization

func (Authorization) Then

func (a Authorization) Then(next http.Handler) http.Handler

Then middleware

type AuthorizationAttributes

type AuthorizationAttributes struct{}

AuthorizationAttributes is an HTTP middleware that populates a context for the request, to be used by other middlewares. You probably want this middleware to be executed early in the middleware stack.

func (AuthorizationAttributes) Then

Then is the AuthorizationAttrs middleware's main logic, heavily inspired by Kubernetes' WithRequestInfo.

The general, expected format of a path is one of the following: /apis/{group}/{version}/namespaces /apis/{group}/{version}/namespaces/{namespace}/{resource} /apis/{group}/{version}/namespaces/{namespace}/{resource}/{name}

This middleware tries to fill in as many fields as it can in the authorization.Attributes struct added to the context, but there is no guarantee of any fields being filled in.

type HTTPMiddleware

type HTTPMiddleware interface {
	// Then returns new handler that wraps given handler
	Then(http.Handler) http.Handler
}

HTTPMiddleware interface serves as the building block for composing http middleware.

type LimitRequest

type LimitRequest struct{}

LimitRequest is an HTTP middleware that enforces request limits

func (LimitRequest) Then

func (l LimitRequest) Then(next http.Handler) http.Handler

Then middleware

type Namespace

type Namespace struct{}

Namespace retrieves the namespace passed as a query parameter and add it into the context of the request

func (Namespace) Then

func (n Namespace) Then(next http.Handler) http.Handler

Then middleware

type Pagination

type Pagination struct{}

Pagination retrieves the "limit" and "continue" query parameters and add them to the request's context.

func (Pagination) Then

func (p Pagination) Then(next http.Handler) http.Handler

type RefreshToken

type RefreshToken struct{}

RefreshToken middleware retrieves and validates a refresh token, provided in the body of a request, against an access token and the access list. Then, it adds the claims of both access and refresh tokens into the request context for easier consumption later

func (RefreshToken) Then

func (m RefreshToken) Then(next http.Handler) http.Handler

Then ...

type SimpleLogger

type SimpleLogger struct{}

SimpleLogger log request path and duration

func (SimpleLogger) Then

func (m SimpleLogger) Then(next http.Handler) http.Handler

Then middleware

type Stack

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

Stack of middleware; stack itself is middleware and can but composed along with other middleware / stacks.

eg. Apply(router, NewStack(Auth{}, BasicAuth{}, NewStack(Logger{})), ...)

func NewStack

func NewStack(ms []HTTPMiddleware) *Stack

NewStack returns new middleware stack

func (Stack) Then

func (m Stack) Then(next http.Handler) http.Handler

Then ...

Jump to

Keyboard shortcuts

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