middleware

package
v1.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const AccountID string = "Account-Id"

AccountID serves as key for the account uuid in the context

View Source
const RoleIDs string = "Role-Ids"

RoleIDs serves as key for the roles in the context

Variables

This section is empty.

Functions

func Cors

func Cors(opts ...cors.Option) func(http.Handler) http.Handler

Cors writes required cors headers to all requests.

func ExtractAccountUUID

func ExtractAccountUUID(opts ...account.Option) func(http.Handler) http.Handler

ExtractAccountUUID provides a middleware to extract the account uuid from the x-access-token header value and write it to the context. If there is no x-access-token the middleware is omitted.

func Logger

func Logger(logger log.Logger) func(http.Handler) http.Handler

Logger is a middleware to log http requests. It uses debug level logging and should be used by all services save the proxy (which uses info level logging).

func NoCache

func NoCache(next http.Handler) http.Handler

NoCache writes required cache headers to all requests.

func OidcAuth

func OidcAuth(opts ...Option) func(http.Handler) http.Handler

OidcAuth provides a middleware to authenticate a bearer auth with an OpenID Connect identity provider It will put all claims provided by the userinfo endpoint in the context

func Static

func Static(root string, fs http.FileSystem, ttl int) func(http.Handler) http.Handler

Static is a middleware that serves static assets.

func Throttle

func Throttle(limit int) func(http.Handler) http.Handler

Throttle limits the number of concurrent requests.

func TraceContext

func TraceContext(next http.Handler) http.Handler

TraceContext unpacks the request context looking for an existing trace id.

func Version

func Version(name, version string) func(http.Handler) http.Handler

Version writes the current version to the headers.

Types

type OIDCProvider

type OIDCProvider interface {
	UserInfo(ctx context.Context, ts oauth2.TokenSource) (*goidc.UserInfo, error)
}

OIDCProvider used to mock the oidc provider during tests

type Option

type Option func(o *Options)

Option defines a single option function.

func WithGatewayAPIClient

func WithGatewayAPIClient(val gatewayv1beta1.GatewayAPIClient) Option

WithGatewayAPIClient provides a function to set the reva gateway client option.

func WithHttpClient

func WithHttpClient(val http.Client) Option

HttpClient provides a function to set the http client option.

func WithLogger

func WithLogger(val log.Logger) Option

WithLogger provides a function to set the logger option.

func WithOidcIssuer

func WithOidcIssuer(val string) Option

WithLogger provides a function to set the openid connect issuer option.

type Options

type Options struct {
	// Logger to use for logging, must be set
	Logger log.Logger
	// The OpenID Connect Issuer URL
	OidcIssuer string
	// GatewayAPIClient is a reva gateway client
	GatewayAPIClient gatewayv1beta1.GatewayAPIClient
	// HttpClient is a http client
	HttpClient http.Client
}

Options defines the available options for this package.

Jump to

Keyboard shortcuts

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