routegen

package
v0.0.0-...-da93f2a Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package routegen provides individual Route Generators to generate RDS config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeSnakeToJsonMapping

func ComputeSnakeToJsonMapping(serviceConfig *servicepb.Service) (map[string]map[string]string, error)

ComputeSnakeToJsonMapping computes a mapping from snake_case to camelCase for variable field bindings. It is keyed by selector -> snake -> json.

func ComputeTypesByTypeName

func ComputeTypesByTypeName(serviceConfig *servicepb.Service) map[string]*typepb.Type

func HTTPRuleToHTTPPattern

func HTTPRuleToHTTPPattern(rule *annotationspb.HttpRule, snakeToJSON map[string]string) (*httppattern.Pattern, error)

HTTPRuleToHTTPPattern converts an HTTP rule to an internal HTTP pattern representation, to be used while parsing the service config for HTTP patterns.

func ParseBackendClusterBySelectorFromOPConfig

func ParseBackendClusterBySelectorFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) (map[string]*BackendClusterSpecifier, error)

ParseBackendClusterBySelectorFromOPConfig parses the service config into a map of selector to the backend cluster to route to.

Forks `service_info.go: processBackendRule()`

func ParseDeadlineSelectorFromOPConfig

func ParseDeadlineSelectorFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) map[string]*DeadlineSpecifier

ParseDeadlineSelectorFromOPConfig parses deadline by selector. Only contains selectors that have backend rules.

Forked from service_info.go::ruleToBackendInfo()

func ParseHTTPPatternsBySelectorFromOPConfig

func ParseHTTPPatternsBySelectorFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) (map[string][]*httppattern.Pattern, error)

ParseHTTPPatternsBySelectorFromOPConfig parses the service config into a list of internal HTTP pattern representations, keyed by OP selector.

Note: HTTP here refers to pattern serving as a route on the HTTP protocol. It does not differentiation between HTTP vs gRPC backend. By default, this function will generate HTTP patterns for gRPC backends.

Forked from `service_info.go: processHttpRule()` and `service_info.go: addGrpcHttpRules()`

func ParseMethodBySelectorFromOPConfig

func ParseMethodBySelectorFromOPConfig(serviceConfig *servicepb.Service) map[string]*apipb.Method

ParseMethodBySelectorFromOPConfig returns a map of selector to the API method.

func ParseSelectorsFromOPConfig

func ParseSelectorsFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) []string

ParseSelectorsFromOPConfig returns a list of selectors in the config. Preserves original order of APIs in the service config.

func PrecomputeBackendRuleBySelectorFromOPConfig

func PrecomputeBackendRuleBySelectorFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) map[string]*servicepb.BackendRule

PrecomputeBackendRuleBySelectorFromOPConfig pre-processes the service config to return a map of selector to the corresponding backend rule.

func PrecomputeHTTPRuleBySelectorFromOPConfig

func PrecomputeHTTPRuleBySelectorFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) map[string]*annotationspb.HttpRule

PrecomputeHTTPRuleBySelectorFromOPConfig pre-processes the service config to return a map of selector to the corresponding HTTP rule.

Types

type BackendClusterSpecifier

type BackendClusterSpecifier struct {
	Name     string
	HostName string

	// HTTPBackend is filled in if the backend rule has an associated HTTP backend.
	// In this case, all HTTP routes must redirect to this backend.
	HTTPBackend *BackendClusterSpecifier
}

BackendClusterSpecifier specifies a local or remote backend cluster. If remote cluster, then HostRewrite will also be set.

type DeadlineSpecifier

type DeadlineSpecifier struct {
	Deadline            time.Duration
	HTTPBackendDeadline time.Duration
}

type DenyAllGenerator

type DenyAllGenerator struct {
	*NoopRouteGenerator
}

DenyAllGenerator is a RouteGenerator that denies all requests.

func (*DenyAllGenerator) GenRouteConfig

func (g *DenyAllGenerator) GenRouteConfig([]filtergen.FilterGenerator) ([]*routepb.Route, error)

GenRouteConfig implements interface RouteGenerator.

func (*DenyAllGenerator) RouteType

func (g *DenyAllGenerator) RouteType() string

RouteType implements interface RouteGenerator.

type DenyInvalidMethodGenerator

type DenyInvalidMethodGenerator struct {
	WrappedGens []RouteGenerator

	DisallowColonInWildcardPathSegment bool

	*NoopRouteGenerator
}

DenyInvalidMethodGenerator is a RouteGenerator that creates "method not allowed" matchers for the RouteGenerators that it wraps.

We allow this configurability because some products (Istio/ASM) do not require generation of these deny routes.

func (*DenyInvalidMethodGenerator) GenRouteConfig

GenRouteConfig implements interface RouteGenerator.

func (*DenyInvalidMethodGenerator) RouteType

func (g *DenyInvalidMethodGenerator) RouteType() string

RouteType implements interface RouteGenerator.

type DirectResponseCORSGenerator

type DirectResponseCORSGenerator struct {
	Preset string
	// AllowOrigin should only be set if preset=basic
	AllowOrigin string
	// AllowOriginRegex should only be set if preset=cors_with_regex
	AllowOriginRegex string

	// LocalBackendClusterName is the name of the local backend cluster to apply
	// CORS policies to.
	LocalBackendClusterName string

	*NoopRouteGenerator
}

DirectResponseCORSGenerator is a RouteGenerator to configure CORS routes.

func (*DirectResponseCORSGenerator) GenRouteConfig

GenRouteConfig implements interface RouteGenerator.

Forked from `route_generator.go: makeRouteCors()

func (*DirectResponseCORSGenerator) RouteType

func (g *DirectResponseCORSGenerator) RouteType() string

RouteType implements interface RouteGenerator.

type DirectResponseHealthCheckGenerator

type DirectResponseHealthCheckGenerator struct {
	AutogeneratedOperationPrefix string
	ESPOperationAPI              string
	HTTPPattern                  *httppattern.Pattern

	// Technically these health checks should be handled directly by Envoy and never
	// reach the backend. However, the routes configs must contain the backend
	// cluster info in order for health check to be preformed.
	LocalBackendClusterName string
	BackendRouteGen         *helpers.BackendRouteGenerator

	*NoopRouteGenerator
}

DirectResponseHealthCheckGenerator is a RouteGenerator that creates routes for Envoy health checks.

func (*DirectResponseHealthCheckGenerator) AffectedHTTPPatterns

AffectedHTTPPatterns implements interface RouteGenerator.

func (*DirectResponseHealthCheckGenerator) GenRouteConfig

func (g *DirectResponseHealthCheckGenerator) GenRouteConfig(filterGens []filtergen.FilterGenerator) ([]*routepb.Route, error)

GenRouteConfig implements interface RouteGenerator.

Forked from `service_info.go: processHttpRule()`.

func (*DirectResponseHealthCheckGenerator) RouteType

RouteType implements interface RouteGenerator.

type NoopRouteGenerator

type NoopRouteGenerator struct{}

NoopRouteGenerator is a RouteGenerator that provides empty implementation for all optional methods.

func (*NoopRouteGenerator) AffectedHTTPPatterns

func (g *NoopRouteGenerator) AffectedHTTPPatterns() httppattern.MethodSlice

type ProxyBackendGenerator

type ProxyBackendGenerator struct {
	HTTPPatterns             httppattern.MethodSlice
	BackendClusterBySelector map[string]*BackendClusterSpecifier
	DeadlineBySelector       map[string]*DeadlineSpecifier
	MethodBySelector         map[string]*apipb.Method
	BackendRouteGen          *helpers.BackendRouteGenerator

	*NoopRouteGenerator
}

ProxyBackendGenerator is a RouteGenerator to configure routes to the local or remote backend service.

func (*ProxyBackendGenerator) AffectedHTTPPatterns

func (g *ProxyBackendGenerator) AffectedHTTPPatterns() httppattern.MethodSlice

AffectedHTTPPatterns implements interface RouteGenerator.

func (*ProxyBackendGenerator) CloneConfigsBySelector

func (g *ProxyBackendGenerator) CloneConfigsBySelector(from string, to string)

CloneConfigsBySelector clones all configs that apply to selector `from` so that the same configs apply to selector `to`.

func (*ProxyBackendGenerator) GenRouteConfig

func (g *ProxyBackendGenerator) GenRouteConfig(filterGens []filtergen.FilterGenerator) ([]*routepb.Route, error)

GenRouteConfig implements interface RouteGenerator.

func (*ProxyBackendGenerator) RouteType

func (g *ProxyBackendGenerator) RouteType() string

RouteType implements interface RouteGenerator.

type ProxyCORSGenerator

type ProxyCORSGenerator struct {
	DisallowColonInWildcardPathSegment      bool
	HealthCheckAutogeneratedOperationPrefix string

	// ProxyCORSGenerator wraps ProxyBackendGenerator directly.
	*ProxyBackendGenerator
}

ProxyCORSGenerator is a RouteGenerator to autogenerate CORS routes that are proxied to the backend.

func (*ProxyCORSGenerator) GenRouteConfig

func (g *ProxyCORSGenerator) GenRouteConfig(filterGens []filtergen.FilterGenerator) ([]*routepb.Route, error)

GenRouteConfig implements interface RouteGenerator.

func (*ProxyCORSGenerator) RouteType

func (g *ProxyCORSGenerator) RouteType() string

RouteType implements interface RouteGenerator.

type RouteGenerator

type RouteGenerator interface {
	// RouteType returns the debug name of the route generator.
	RouteType() string

	// GenRouteConfig generates all routes (ordered) for the config.
	//
	// If any FilterGenerators are provided, the per-route config for each filter
	// gen is also attached to each outputted route.
	GenRouteConfig([]filtergen.FilterGenerator) ([]*routepb.Route, error)

	// AffectedHTTPPatterns returns a list of HTTP patterns that this
	// RouteGenerator operates on.
	//
	// Useful for other RouteGenerators to wrap the patterns and output more
	// (aggregated) routes.
	AffectedHTTPPatterns() httppattern.MethodSlice
}

RouteGenerator is an interface for objects that generate Envoy routes.

func NewDenyAllRouteGenFromOPConfig

func NewDenyAllRouteGenFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) (RouteGenerator, error)

NewDenyAllRouteGenFromOPConfig creates DenyAllGenerator from OP service config + ESPv2 options. It is a RouteGeneratorOPFactory.

func NewDenyInvalidMethodRouteGenFromOPConfig

func NewDenyInvalidMethodRouteGenFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions, wrappedGenFactories []RouteGeneratorOPFactory) (RouteGenerator, error)

NewDenyInvalidMethodRouteGenFromOPConfig creates DenyInvalidMethodGenerator from OP service config + ESPv2 options. It is a RouteGeneratorOPFactory.

func NewDirectResponseCORSRouteGenFromOPConfig

func NewDirectResponseCORSRouteGenFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) (RouteGenerator, error)

NewDirectResponseCORSRouteGenFromOPConfig creates DirectResponseCORSGenerator from OP service config + ESPv2 options. It is a RouteGeneratorOPFactory.

func NewDirectResponseHealthCheckRouteGenFromOPConfig

func NewDirectResponseHealthCheckRouteGenFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) (RouteGenerator, error)

NewDirectResponseHealthCheckRouteGenFromOPConfig creates DirectResponseHealthCheckGenerator from OP service config + ESPv2 options. It is a RouteGeneratorOPFactory.

func NewProxyBackendRouteGenFromOPConfig

func NewProxyBackendRouteGenFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) (RouteGenerator, error)

NewProxyBackendRouteGenFromOPConfig creates ProxyBackendGenerator from OP service config + ESPv2 options. It is a RouteGeneratorOPFactory.

func NewProxyCORSRouteGenFromOPConfig

func NewProxyCORSRouteGenFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) (RouteGenerator, error)

NewProxyCORSRouteGenFromOPConfig creates ProxyCORSGenerator from OP service config + ESPv2 options. It is a RouteGeneratorOPFactory.

func NewRouteGeneratorsFromOPConfig

func NewRouteGeneratorsFromOPConfig(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions, factories []RouteGeneratorOPFactory) ([]RouteGenerator, error)

NewRouteGeneratorsFromOPConfig creates all required RouteGenerators from OP service config + descriptor + ESPv2 options.

type RouteGeneratorOPFactory

type RouteGeneratorOPFactory func(serviceConfig *servicepb.Service, opts options.ConfigGeneratorOptions) (RouteGenerator, error)

RouteGeneratorOPFactory is the factory function to create an ordered slice of RouteGenerator from One Platform config.

Directories

Path Synopsis
Package helpers provides building blocks for routegen configs.
Package helpers provides building blocks for routegen configs.
Package routegentest contains test helpers to test route generators.
Package routegentest contains test helpers to test route generators.

Jump to

Keyboard shortcuts

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