injectproxy

package
v0.0.0-...-b18b4f9 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRoutes

func NewRoutes(upstream *url.URL, extractLabeler ExtractLabeler, opts ...Option) (*routes, error)

func WithLabelMap

func WithLabelMap(ctx context.Context, labels LabelMap) context.Context

WithLabelMap stores labels in the given context.

Types

type Enforcer

type Enforcer struct {
	// contains filtered or unexported fields
}

func NewEnforcer

func NewEnforcer(ms ...*labels.Matcher) *Enforcer

func (Enforcer) EnforceMatchers

func (ms Enforcer) EnforceMatchers(targets []*labels.Matcher) ([]*labels.Matcher, error)

EnforceMatchers appends the configured label matcher if not present. If the label matcher that is to be injected is present (by labelname) it will be preserved.

func (Enforcer) EnforceNode

func (ms Enforcer) EnforceNode(node parser.Node) error

EnforceNode walks the given node recursively and enforces the given label enforcer on it.

Whenever a parser.MatrixSelector or parser.VectorSelector AST node is found, their label enforcer is being potentially modified. If a node's label matcher has the same name as a label matcher of the given enforcer, then it will be replaced.

type ExtractLabeler

type ExtractLabeler interface {
	ExtractLabel(next http.HandlerFunc) http.Handler
}

ExtractLabeler is an HTTP handler that extract the label value to be enforced from the HTTP request. If a valid label value is found, it should store it in the request's context. Otherwise it should return an error in the HTTP response (usually 400 or 500).

type HTTPFormEnforcer

type HTTPFormEnforcer struct {
	ParameterName string
	LabelName     string
}

HTTPFormEnforcer enforces a label value extracted from the HTTP form and query parameters.

func (HTTPFormEnforcer) ExtractLabel

func (hff HTTPFormEnforcer) ExtractLabel(next http.HandlerFunc) http.Handler

ExtractLabel implements the ExtractLabeler interface.

type HTTPHeaderEnforcer

type HTTPHeaderEnforcer struct {
	Name      string
	LabelName string
}

HTTPHeaderEnforcer enforces a label value extracted from the HTTP headers.

func (HTTPHeaderEnforcer) ExtractLabel

func (hhe HTTPHeaderEnforcer) ExtractLabel(next http.HandlerFunc) http.Handler

ExtractLabel implements the ExtractLabeler interface.

type LabelMap

type LabelMap map[string][]string

func MustLabelMap

func MustLabelMap(ctx context.Context) LabelMap

MustLabelMap returns labels (previously stored using WithLabelValue()) from the given context. It will panic if no label is found or the value is empty.

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithEnabledLabelsAPI

func WithEnabledLabelsAPI() Option

WithEnabledLabelsAPI enables proxying to labels API. If false, "501 Not implemented" will be return for those.

func WithModifyProxyRequest

func WithModifyProxyRequest(f func(*http.Request)) Option

WithModifyProxyRequest allows to modify the proxy request before it is sent to the upstream. can be used to add custom headers, like basic auth.

func WithPassthroughPaths

func WithPassthroughPaths(paths []string) Option

WithPassthroughPaths configures routes to register given paths as passthrough handlers for all HTTP methods. that, if requested, will be forwarded without enforcing label. Use with care. NOTE: Passthrough "all" paths like "/" or "" and regex are not allowed.

func WithPathPrefix

func WithPathPrefix(pathPrefix string) Option

func WithPrometheusRegistry

func WithPrometheusRegistry(reg prometheus.Registerer) Option

WithPrometheusRegistry configures the proxy to use the given registerer.

type StaticLabelEnforcer

type StaticLabelEnforcer struct {
	Values    []string
	LabelName string
}

StaticLabelEnforcer enforces a static label value.

func (StaticLabelEnforcer) ExtractLabel

func (sle StaticLabelEnforcer) ExtractLabel(next http.HandlerFunc) http.Handler

ExtractLabel implements the ExtractLabeler interface.

Jump to

Keyboard shortcuts

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