middleware

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TenantPathParamName is the name of the path parameter used to extract the tenant ID.
	TenantPathParamName = "tenant"
)

Variables

View Source
var (
	ErrNoBusinessUserDataHeader = errors.New("no client data header found")
	ErrMissingSignatureHeader   = errors.New("missing client data signature header")
	ErrPublicKeyNotFound        = errors.New("public key not found or invalid")
	ErrVerifySignatureFailed    = errors.New("failed to verify client data signature")
	ErrDecodeBusinessUserData   = errors.New("failed to decode business data from header")
	ErrTriedToBeSystem          = errors.New("attempted to be system")
)

Functions

func AuthzMiddleware

func AuthzMiddleware(
	ctr *cmk.APIController,
) func(http.Handler) http.Handler

func BusinessUserDataMiddleware added in v0.9.0

func BusinessUserDataMiddleware(
	signingKeyStorage keyvalue.ReadOnlyStringToBytesStorage,
	authContextFields []string,
	roleGetter RoleGetter,
) func(http.Handler) http.Handler

BusinessUserDataMiddleware extracts client data from headers, verifies, and adds to context

func ExtractPatternForTest added in v0.9.0

func ExtractPatternForTest(pattern, basePath string) string

ExtractPatternForTest is a test helper that exposes extractPattern for unit testing

func InjectMultiTenancy

func InjectMultiTenancy() func(http.Handler) http.Handler

InjectMultiTenancy returns a middleware that extracts the tenant ID from the request path parameter and stores it in the request context.

func InjectRequestID

func InjectRequestID() func(http.Handler) http.Handler

InjectRequestID injects a RequestID into the context to be used by other middlewares

func LoggingMiddleware

func LoggingMiddleware() func(http.Handler) http.Handler

LoggingMiddleware logs the start and end of each request, along with the duration and status code.

func OAPIMiddleware

func OAPIMiddleware(swagger *openapi3.T) func(next http.Handler) http.Handler

OAPIMiddleware validates a Request against the OpenAPI Spec Also registers a decoder for merge-patch+json

func PanicRecoveryMiddleware

func PanicRecoveryMiddleware() func(http.Handler) http.Handler

PanicRecoveryMiddleware is a middleware that recovers from panics and logs them.

func TracingMiddleware added in v0.7.0

func TracingMiddleware(cfg *config.Config) func(http.Handler) http.Handler

Types

type RoleGetter

type RoleGetter interface {
	GetRoleFromIAM(ctx context.Context, iamIdentifiers []string) (constants.BusinessRole, error)
}

RoleGetter defines the interface for getting roles from group IAM identifiers for better unit testing

Jump to

Keyboard shortcuts

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