middleware

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 26 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 (
	ErrNoClientDataHeader     = 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")
	ErrDecodeClientData       = errors.New("failed to decode client data from header")
	ErrTriedToBeSystem        = errors.New("attempted to be system")
)
View Source
var ErrTenantNotFound = errors.New("tenant not found as path parameter")

ErrTenantNotFound is returned when the tenant ID is not found in the request.

Functions

func AuthzMiddleware

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

func ClientDataMiddleware

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

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

func InjectMultiTenancy

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

InjectMultiTenancy returns a middleware function that handles multi-tenancy based on path parameter.

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.

Types

type RoleGetter

type RoleGetter interface {
	GetRoleFromIAM(ctx context.Context, iamIdentifiers []string) (constants.Role, 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