http

package module
v0.0.0-...-2be5f50 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

credits to https://github.com/koron-go/dialsrv for original source, but vendoring into baseplate as this appears to be unmainted

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth0JWTMiddleware

func Auth0JWTMiddleware(issuerURL string, audience []string, opts ...jwtmiddleware.Option) func(http.Handler) http.Handler

func CorsMiddleware

func CorsMiddleware(next http.Handler) http.Handler

func ErrorHandler

func ErrorHandler(w http.ResponseWriter, r *http.Request, err error)

func HlogHandler

func HlogHandler(h http.Handler) http.Handler

Setup github.com/rs/zerolog/hlog(https://github.com/rs/zerolog#integration-with-nethttp) integration. Must be called after 'OTLPHandler'.

func JWTClaimsValueFromCtx

func JWTClaimsValueFromCtx(ctx context.Context) (*validator.ValidatedClaims, bool)

JWTClaimsValueFromCtx gets the parsed claims from the JWT provided in the request. Requires running hte JWTValidatorMiddleware. Can then be used to extra 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

func NewClient() *http.Client

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 NomadJWTMiddleware(nomadURL string, audience []string, opts ...jwtmiddleware.Option) func(http.Handler) http.Handler

func OTLPHandler

func OTLPHandler(serviceName string) func(http.Handler) http.Handler

func RatelimiterMiddleware

func RatelimiterMiddleware(opts ...RatelimiterOption) func(http.Handler) http.Handler

func TraceIDHandler

func TraceIDHandler(fieldKey string) func(next http.Handler) http.Handler

RequestHandler adds the trace id as a field to the context's logger using fieldKey as field key.

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

func NewSRVDialer(d *net.Dialer) *Dialer

New creates a new Dialer with base *net.Dialer.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial connects to the address on the named network.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects to the address on the named network using the provided context.

type FlavoredAddr

type FlavoredAddr struct {
	Network string
	Service string
	Proto   string
	Name    string
}

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)

func (NomadCustomClaims) Validate

func (c NomadCustomClaims) Validate(ctx context.Context) 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

func (StratosOAuth2CustomClaims) Validate

Jump to

Keyboard shortcuts

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