Documentation ¶
Index ¶
- Variables
- func Authenticate(v XRhIValidator, ctx context.Context, ...) error
- func ContextLogConfig(cfg *LogConfig) echo.MiddlewareFunc
- func CreateContext() func(echo.HandlerFunc) echo.HandlerFunc
- func CreateMetricsMiddleware(metrics *metrics.Metrics) echo.MiddlewareFunc
- func EnforceIdentityWithConfig(config *IdentityConfig) func(echo.HandlerFunc) echo.HandlerFunc
- func EnforceServiceAccountPredicate(data *identity.XRHID) error
- func EnforceSystemPredicate(data *identity.XRHID) error
- func EnforceUserPredicate(data *identity.XRHID) error
- func FakeIdentityWithConfig(config *FakeIdentityConfig) func(echo.HandlerFunc) echo.HandlerFunc
- func InitOpenAPIFormats()
- func MatchedRoute(ctx echo.Context) string
- func MetricsMiddlewareWithConfig(config *MetricsConfig) echo.MiddlewareFunc
- func NewAuthenticator(v XRhIValidator) openapi3filter.AuthenticationFunc
- func Nooperation() echo.MiddlewareFunc
- func ParseXRHIDMiddlewareWithConfig(config *ParseXRHIDMiddlewareConfig) func(echo.HandlerFunc) echo.HandlerFunc
- func RBACWithConfig(rbacConfig *RBACConfig) echo.MiddlewareFunc
- func RequestResponseValidator() echo.MiddlewareFunc
- func RequestResponseValidatorWithConfig(config *RequestResponseValidatorConfig) echo.MiddlewareFunc
- type DomainContextInterface
- type FakeIdentityConfig
- type IdentityConfig
- type IdentityPredicate
- type IdentityPredicateEntry
- type LogConfig
- type MetricsConfig
- type ParseXRHIDMiddlewareConfig
- type RBACConfig
- type RequestResponseValidatorConfig
- type ResponseRecorder
- type XRhIValidator
Constants ¶
This section is empty.
Variables ¶
var DefaultNooperation = Nooperation()
DefaultNooperation is a default instance for Nooperation middleware
var DefaultRequestResponseValidatorConfig = RequestResponseValidatorConfig{ Skipper: echo_middleware.DefaultSkipper, ValidateRequest: true, ValidateResponse: false, }
DefaultRequestResponseValidatorConfig is the default RequestResponseValidator middleware config.
Functions ¶
func Authenticate ¶
func Authenticate(v XRhIValidator, ctx context.Context, input *openapi3filter.AuthenticationInput) error
func ContextLogConfig ¶
func ContextLogConfig(cfg *LogConfig) echo.MiddlewareFunc
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 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 EnforceServiceAccountPredicate ¶
EnforceServiceAccountPredicate is a predicate that check fields for ServiceAccount identities. Return nil if the enforce is passed, else details about the enforce process.
func EnforceSystemPredicate ¶
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 ¶
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 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 NewAuthenticator ¶
func NewAuthenticator(v XRhIValidator) openapi3filter.AuthenticationFunc
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 ParseXRHIDMiddlewareWithConfig ¶
func ParseXRHIDMiddlewareWithConfig(config *ParseXRHIDMiddlewareConfig) func(echo.HandlerFunc) echo.HandlerFunc
Parse the X-RH-Identity header and set it into the request context. This must be called AFTER the "Fake Identity" middleware (if used), but BEFORE the EnforceIdentity middlewares.
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 ¶
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 LogConfig ¶
type LogConfig struct {
Skipper middleware.Skipper
}
type MetricsConfig ¶
type MetricsConfig struct { Skipper echo_middleware.Skipper Metrics *metrics.Metrics }
type ParseXRHIDMiddlewareConfig ¶
type ParseXRHIDMiddlewareConfig struct { // Skipper function to skip for some request if necessary Skipper echo_middleware.Skipper }
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