Documentation
¶
Overview ¶
Package httpmiddleware contains HTTP middlewares.
Index ¶
Constants ¶
const ProfileHeader = "X-Oteldb-Profile"
ProfileHeader, when set to a truthy value ("1", "true", "yes", "on") on a request, turns on EXPLAIN ANALYZE for that query: the storage fetch operators record a profiled tree with per-node timing and I/O counters. This matches the X-Oteldb-Profile convention the storage cluster read path uses between peers.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthVerdict ¶
AuthVerdict represents the result of an authentication attempt.
func Authenticated ¶
func Authenticated() AuthVerdict
Authenticated creates a successful AuthVerdict.
func Unauthenticated ¶
func Unauthenticated(msg string) AuthVerdict
Unauthenticated creates an AuthVerdict with a message.
type Authenticator ¶
type Authenticator interface {
Authenticate(r *http.Request) AuthVerdict
}
Authenticator provides an interface for authentication mechanisms.
func BasicAuth ¶
func BasicAuth(users []UserCredentials) (Authenticator, error)
BasicAuth provides an Authenticator that checks for HTTP Basic Auth.
func BearerToken ¶
func BearerToken(tokens []Token) (Authenticator, error)
BearerToken provides an Authenticator that checks for Bearer tokens.
type AuthenticatorFunc ¶
type AuthenticatorFunc func(r *http.Request) AuthVerdict
AuthenticatorFunc provides a function wrapper for Authenticator interface.
func (AuthenticatorFunc) Authenticate ¶
func (f AuthenticatorFunc) Authenticate(r *http.Request) AuthVerdict
Authenticate implements Authenticator interface.
type Metrics ¶
type Metrics interface {
TracerProvider() trace.TracerProvider
MeterProvider() metric.MeterProvider
TextMapPropagator() propagation.TextMapPropagator
}
Metrics wraps TracerProvider and MeterProvider.
type Middleware ¶
Middleware is a net/http middleware.
func Auth ¶
func Auth(sets []Authenticator, onError func(w http.ResponseWriter, req *http.Request, msg string)) Middleware
Auth provides a middleware that tries multiple authenticators in sequence.
func Explain ¶ added in v0.43.0
func Explain() Middleware
Explain enables EXPLAIN ANALYZE for requests carrying the X-Oteldb-Profile header. It installs a storage profile collector into the request context and, after the handler runs, renders the fetch-operator tree to the context logger.
It is zero-overhead for requests without the header: the storage operators' profile.Begin is a no-op when no collector is in the context, so the normal query path makes no extra timing reads or allocations. Install it after InjectLogger so the rendered tree reaches the request logger.
func InjectLogger ¶
func InjectLogger(lg *zap.Logger) Middleware
InjectLogger injects logger into request context.
func Instrument ¶
func Instrument(endpoint, serviceName string, find RouteFinder, m Metrics) Middleware
Instrument setups otelhttp.
func LogRequests ¶
func LogRequests(find RouteFinder) Middleware
LogRequests logs incoming requests using context logger.
type OgenServer ¶
OgenServer is a generic ogen server type.
type RouteFinder ¶
RouteFinder finds Route by given URL.
func MakeRouteFinder ¶
func MakeRouteFinder[R OgenRoute, S OgenServer[R]](server S) RouteFinder
MakeRouteFinder creates RouteFinder from given server.
type Token ¶
type Token struct {
Token string `json:"token" yaml:"token"`
TokenFile string `json:"token_file" yaml:"token_file"`
}
Token defines token config.
type UserCredentials ¶
type UserCredentials struct {
User string `json:"user" yaml:"user"`
Password string `json:"password" yaml:"password"`
PasswordFile string `json:"password_file" yaml:"password_file"`
}
UserCredentials holds username and password.
func (UserCredentials) GetPassword ¶
func (u UserCredentials) GetPassword() (string, error)
GetPassword returns password value.