Documentation ¶
Index ¶
- Constants
- func Apply(handler http.Handler, ms ...HTTPMiddleware) http.Handler
- func BasicAuthentication(next http.Handler, store AuthStore) http.Handler
- type AllowList
- type AuthStore
- type Authentication
- type Authorization
- type AuthorizationAttributes
- type HTTPMiddleware
- type LimitRequest
- type Namespace
- type Pagination
- type RefreshToken
- type SimpleLogger
- type Stack
Constants ¶
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{})
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
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 { // in the case where an access token was not present. IgnoreUnauthorized bool }
Authentication is a HTTP middleware that enforces authentication
type Authorization ¶
type Authorization struct {
Authorizer authorization.Authorizer
}
Authorization is an HTTP middleware that enforces authorization
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 ¶
func (a AuthorizationAttributes) Then(next http.Handler) http.Handler
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
type Namespace ¶
type Namespace struct{}
Namespace retrieves the namespace passed as a query parameter and add it into the context of the request
type Pagination ¶
type Pagination struct{}
Pagination retrieves the "limit" and "continue" query parameters and add them to the request's context.
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