Documentation
¶
Overview ¶
credits to https://github.com/koron-go/dialsrv for original source, but vendoring into baseplate as this appears to be unmainted
Index ¶
- func Auth0JWTMiddleware(issuerURL string, audience []string, opts ...jwtmiddleware.Option) func(http.Handler) http.Handler
- func CorsMiddleware(next http.Handler) http.Handler
- func CreateWebsocketTransport(v validator.Validator, ...) transport.Websocket
- func ErrorHandler(w http.ResponseWriter, r *http.Request, err error)
- func JWTClaimsValueFromCtx(ctx context.Context) (*validator.ValidatedClaims, bool)
- func NewClient() *http.Client
- func NomadJWTMiddleware(nomadURL string, audience []string, opts ...jwtmiddleware.Option) func(http.Handler) http.Handler
- func OTLPHandler(serviceName string, options ...otelhttp.Option) func(http.Handler) http.Handler
- func RatelimiterMiddleware(opts ...RatelimiterOption) func(http.Handler) http.Handler
- func SlogHandler(logger *slog.Logger) func(http.Handler) http.Handler
- type Config
- type Dialer
- type FlavoredAddr
- type NomadCustomClaims
- type RatelimiterOption
- type StratosOAuth2CustomClaims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Auth0JWTMiddleware ¶
func ErrorHandler ¶
func ErrorHandler(w http.ResponseWriter, r *http.Request, err error)
func JWTClaimsValueFromCtx ¶
func JWTClaimsValueFromCtx(ctx context.Context) (*validator.ValidatedClaims, bool)
JWTClaimsValueFromCtx gets the parsed claims from the JWT provided in the request. Requires running the JWTValidatorMiddleware. Can then be used to extract custom claims via ``` validatedClaims, ok := JWTClaimsValueFromCtx(ctx)
if !ok {
return "", errors.New("failed to decode JWT claims from context")
}
claims, ok := validatedClaims.CustomClaims.(*YourCustomClaims)
if !ok {
return "", errors.New("failed to decode custom claims from the validated claim")
}
```
func NewClient ¶
Create new http.Client with sensible defaults including 1. SRV lookups with the '.consul' suffix with automatic protocol detection. For example, https://tip.service.consul will do an SRV lookup
func NomadJWTMiddleware ¶
func OTLPHandler ¶
func RatelimiterMiddleware ¶
func RatelimiterMiddleware(opts ...RatelimiterOption) func(http.Handler) http.Handler
func SlogHandler ¶
SlogHandler replaces HlogHandler. It stores an enriched logger (with ip, user_agent, referer) in the request context via slogger.NewContext, and logs an access line after the request completes.
Must be called after OTLPHandler so that trace context is available.
Types ¶
type Config ¶
type Config struct {
KeyFunc httplimit.KeyFunc
MemoryStoreConfig *memorystore.Config
}
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer wraps net.Dialer with SRV lookup.
func NewSRVDialer ¶
New creates a new Dialer with base *net.Dialer.
type FlavoredAddr ¶
FlavoredAddr represents SRV flavored address.
func (*FlavoredAddr) String ¶
func (fa *FlavoredAddr) String() string
String returns FlavoredAddr's string representation.
type NomadCustomClaims ¶
type NomadCustomClaims struct {
AllocationID string `json:"nomad_allocation_id"`
JobID string `json:"nomad_job_id"`
Namespace string `json:"nomad_namespace"`
Task string `json:"nomad_task"`
Sub string `json:"sub"`
}
func NomadCustomClaimsFromCtx ¶
func NomadCustomClaimsFromCtx(ctx context.Context) (*NomadCustomClaims, error)
type RatelimiterOption ¶
type RatelimiterOption func(*Config)
Option is how options for the JWTMiddleware are set up.
func WithInterval ¶
func WithInterval(value time.Duration) RatelimiterOption
WithInterval sets the interval the ratelimiter token bucket refreshes
Default value: time.Second.
func WithKeyFunc ¶
func WithKeyFunc(value httplimit.KeyFunc) RatelimiterOption
func WithTokens ¶
func WithTokens(value uint64) RatelimiterOption
type StratosOAuth2CustomClaims ¶
type StratosOAuth2CustomClaims struct {
Scope string `json:"scope"`
UserID string `json:"https://stratos.host/user_id"`
Permissions []string `json:"permissions"`
}
CustomClaims contains custom data we want from the token.
func Auth0CustomClaimsFromCtx ¶
func Auth0CustomClaimsFromCtx(ctx context.Context) (*StratosOAuth2CustomClaims, error)
func (*StratosOAuth2CustomClaims) HasPermission ¶
func (c *StratosOAuth2CustomClaims) HasPermission(requestedPermission string) bool
func (*StratosOAuth2CustomClaims) HasScope ¶
func (c *StratosOAuth2CustomClaims) HasScope(requestedScope string) bool