middleware

package
v0.0.0-...-6f43059 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultNooperation = Nooperation()

DefaultNooperation is a default instance for Nooperation middleware

View Source
var DefaultRequestResponseValidatorConfig = RequestResponseValidatorConfig{
	Skipper:          echo_middleware.DefaultSkipper,
	ValidateRequest:  true,
	ValidateResponse: false,
}

DefaultRequestResponseValidatorConfig is the default RequestResponseValidator middleware config.

Functions

func CreateContext

func CreateContext() func(echo.HandlerFunc) echo.HandlerFunc

CreateContext is a middleware that create the IDM context used for the rest of the chain of actions into the request. Return the middleware that create the context.

func CreateMetricsMiddleware

func CreateMetricsMiddleware(metrics *metrics.Metrics) echo.MiddlewareFunc

func EnforceIdentityWithConfig

func EnforceIdentityWithConfig(config *IdentityConfig) func(echo.HandlerFunc) echo.HandlerFunc

EnforceIdentityWithConfig instantiate a EnforceIdentity middleware for the configuration provided. This middleware depends on NewContext middleware. If the request pass the enforcement check, then the unmarshalled version of the identity is stored for the request context. config is the configuration with the skipper and predicates to be used for the middleware. Return an echo middleware function.

func EnforceSystemPredicate

func EnforceSystemPredicate(data *identity.XRHID) error

EnforceSystemPredicate is a predicate that enforce identity is a system and some additional checks for a user identity. data is the XRHID to enforce. Return nil if the enforce is passed, else details about the enforce process.

func EnforceUserPredicate

func EnforceUserPredicate(data *identity.XRHID) error

EnforceUserPredicate is a predicate that enforce identity is a user and some additional checks for a user identity. data is the XRHID to enforce. Return nil if the enforce is passed, else details about the enforce process.

func FakeIdentityWithConfig

func FakeIdentityWithConfig(config *FakeIdentityConfig) func(echo.HandlerFunc) echo.HandlerFunc

FakeIdentityWithConfig middleware copy the x-rh-fake-identity to the x-rh-identity header when no skipper return true; it is intended to be called before the EnforceIdentity middleware.

func IdentityAlwaysTrue

func IdentityAlwaysTrue(data *identity.XRHID) error

IdentityAlwaysTrue is a predicate that always return nil so everything was ok. data is the reference to the identity.Identity data. Return nil on success or an error with additional information about the predicate failure.

func InitOpenAPIFormats

func InitOpenAPIFormats()

InitOpenAPIFormats configure the admited formats in the openapi specification. This function must be called before receive any request. Suggested to call before instantiate the middleware.

func MatchedRoute

func MatchedRoute(ctx echo.Context) string

See: https://github.com/labstack/echo/pull/1502/files This method exist for v5 echo framework

func MetricsMiddlewareWithConfig

func MetricsMiddlewareWithConfig(config *MetricsConfig) echo.MiddlewareFunc

func Nooperation

func Nooperation() echo.MiddlewareFunc

Nooperation is a middleware that do nothing. This is useful to decouple middleware initialisation from middleware wiring, so if some middleware is option based on some configuration, we only have to assign this middleware instead of add middlewares in a conditional way.

func RBACWithConfig

func RBACWithConfig(rbacConfig *RBACConfig) echo.MiddlewareFunc

RBACWithConfig create a middleware for authorizing requests by using the intgration with rbac micro-service rbacConfig provide the skipper, prefix, permission map and client for the configuration. Return the initialized middleware or panic if some guard condition is matched.

func RequestResponseValidator

func RequestResponseValidator() echo.MiddlewareFunc

RequestResponseValidator returns a middleware which validates the HTTP response

func RequestResponseValidatorWithConfig

func RequestResponseValidatorWithConfig(config *RequestResponseValidatorConfig) echo.MiddlewareFunc

Types

type DomainContextInterface

type DomainContextInterface interface {
	echo.Context
	SetXRHID(iden *identity.XRHID)
	XRHID() *identity.XRHID
}

Define the interface for our custom context.

func NewContext

func NewContext(c echo.Context) DomainContextInterface

NewContext create our custom context Return an initialized

type FakeIdentityConfig

type FakeIdentityConfig struct {
	// Skipper function to skip for some request if necessary
	Skipper echo_middleware.Skipper
}

type IdentityConfig

type IdentityConfig struct {
	// Skipper function to skip for some request if necessary
	Skipper echo_middleware.Skipper
	// Map of predicates to be applied, all the predicates must
	// return true, if any of them fail, the enforcement will
	// return error for the request.
	Predicates []IdentityPredicateEntry
}

IdentityConfig Represent the configuration for this middleware enforcement.

type IdentityPredicate

type IdentityPredicate func(data *identity.XRHID) error

FIXME Refactor to use the signature: func(c echo.Context) Error

so that the predicate has information about the http Request
context

func NewEnforceOr

func NewEnforceOr(predicates ...IdentityPredicate) IdentityPredicate

NewEnforceOr allow to create new predicates by composing a logical OR with existing predicates.

type IdentityPredicateEntry

type IdentityPredicateEntry struct {
	Name      string
	Predicate IdentityPredicate
}

IdentityPredicateEntry represents a predicate in the chain of responsibility established.

type MetricsConfig

type MetricsConfig struct {
	Skipper echo_middleware.Skipper
	Metrics *metrics.Metrics
}

type RBACConfig

type RBACConfig struct {
	// Skipper function to skip for some request if necessary
	Skipper echo_middleware.Skipper
	// Prefix for the permission map
	Prefix string
	// PermissionMap has the mapping between {route,method}=>permission
	PermissionMap rbac_data.RBACMap
	// Client for rbac access
	Client rbac_client.Rbac
}

RBACConfig hold the skipper, route prefix, the rbac permissions mapping for each authorized public route, and the client to reach out the rbac micro-service.

type RequestResponseValidatorConfig

type RequestResponseValidatorConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper          echo_middleware.Skipper
	ValidateRequest  bool
	ValidateResponse bool
}

RequestResponseValidatorConfig defines the config for RequestResponseValidator middleware.

type ResponseRecorder

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

In order to validate a response, we need to have access to the bytes of the response. The following code allows us to get access to it.

func (*ResponseRecorder) Header

func (r *ResponseRecorder) Header() http.Header

Implements Header of http.ResponseWriter

func (*ResponseRecorder) Write

func (r *ResponseRecorder) Write(p []byte) (n int, err error)

Implements Write of http.ResponseWriter

func (*ResponseRecorder) WriteHeader

func (r *ResponseRecorder) WriteHeader(statusCode int)

Implements WriteHeader of http.ResponseWriter

type XRhIValidator

type XRhIValidator interface {
	ValidateXRhIdentity(xrhi *identity.XRHID) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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