Documentation
¶
Overview ¶
Package config loads and validates the proxy YAML configuration. Use Load to parse from an io.Reader or LoadFile to read from disk. Both expand ${VAR} references using the process environment before unmarshalling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConfigFileTag = fx.ResultTags(`name:"configFile"`)
var Module = fx.Option(fx.Provide(func(p ConfigParams) (*Config, error) { return LoadFile(p.File) }))
Module is an fx module that provides *Config by loading the file path supplied as the named value "configFile".
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Listen ListenConfig `yaml:",inline"`
Routing Routing `yaml:"routing"`
Upstreams []Upstream `yaml:"upstreams"`
}
Config is the top-level proxy configuration.
func Load ¶
Load reads and parses the YAML config specified in the Reader. Values of the form ${VAR} are replaced with the corresponding environment variable.
func LoadFile ¶
LoadFile reads and parses the YAML config file at path. Values of the form ${VAR} are replaced with the corresponding environment variable.
func (*Config) Validate ¶
Validate requires at least one upstream, checks the listen configuration and every upstream, requires upstream names to be unique, and checks that every routing reference names a configured upstream. A missing upstream surfaces on the "upstreams" field. Failures are stamped with the failing node's YAML path as the subject (e.g. "upstreams[0].namespaces.rules.overrides[1]"). A duplicate name surfaces on the "upstreams[name]" field, and an unknown routing reference on the "routing"/"routing.rules[i]" subject.
type ConfigParams ¶
ConfigParams holds the fx-injected dependencies for loading the config file.
type ListenConfig ¶
ListenConfig defines properties for an inbound listener.
func (*ListenConfig) Validate ¶
func (l *ListenConfig) Validate() error
Validate checks the host:port and, when present, the TLS configuration.
type NamespaceConfig ¶
type NamespaceConfig struct {
Rules NamespaceRules `yaml:"rules"`
}
NamespaceConfig groups the namespace translation rules for an upstream.
func (*NamespaceConfig) Validate ¶
func (c *NamespaceConfig) Validate() error
Validate checks the namespace translation rules.
type NamespaceMapping ¶
NamespaceMapping is one explicit local/remote namespace pair, used to short-circuit the prefix/suffix rule for namespaces whose names do not follow the convention.
func (*NamespaceMapping) Validate ¶
func (m *NamespaceMapping) Validate() error
Validate requires both the local and remote namespace names.
type NamespaceRules ¶
type NamespaceRules struct {
Prefix string `yaml:"prefix"`
Suffix string `yaml:"suffix"`
Overrides []NamespaceMapping `yaml:"overrides"`
// contains filtered or unexported fields
}
NamespaceRules translates namespace names between the local view that workers use and the remote names registered on the upstream cluster.
The default translation is to wrap or unwrap a Prefix and Suffix: Remote("payments") returns Prefix+"payments"+Suffix, and Local of that returns "payments". When an explicit Overrides entry matches, the override takes precedence over the prefix/suffix rule.
func (*NamespaceRules) Local ¶
func (r *NamespaceRules) Local(remoteNS string) string
Local returns the local namespace name that corresponds to remoteNS. If an override matches it wins; otherwise the configured Prefix and Suffix are stripped from remoteNS.
func (*NamespaceRules) Remote ¶
func (r *NamespaceRules) Remote(localNS string) string
Remote returns the remote namespace name that corresponds to localNS. If an override matches it wins; otherwise localNS is wrapped with the configured Prefix and Suffix.
func (*NamespaceRules) UnmarshalYAML ¶
func (r *NamespaceRules) UnmarshalYAML(unmarshal func(any) error) error
func (*NamespaceRules) Validate ¶
func (r *NamespaceRules) Validate() error
Validate checks that override entries are complete and that no local or remote name is mapped more than once.
type Routing ¶
type Routing struct {
DefaultUpstream string `yaml:"default"`
SystemUpstream string `yaml:"system"`
Rules []RoutingRule `yaml:"rules"`
}
Routing selects which upstream serves a request. DefaultUpstream is the fallback when no rule matches and SystemUpstream serves system-namespace traffic; both name an upstream and are optional. Rules are evaluated in order against the incoming request.
type RoutingMatch ¶
type RoutingMatch struct {
Namespace string `yaml:"namespace"`
Metadata map[string]string `yaml:"metadata"`
}
RoutingMatch describes the request attributes a rule matches on. A match requires at least one of Namespace or Metadata: an empty match would apply to every request, which is what DefaultUpstream is for.
func (*RoutingMatch) Validate ¶
func (m *RoutingMatch) Validate() error
Validate requires at least one of Namespace or Metadata to be set.
type RoutingRule ¶
type RoutingRule struct {
Upstream string `yaml:"upstream"`
Match RoutingMatch `yaml:"match"`
}
RoutingRule sends every request matched by Match to the named Upstream.
func (*RoutingRule) Validate ¶
func (r *RoutingRule) Validate() error
Validate requires the referenced upstream and checks the match.
type TLSConfig ¶
type TLSConfig struct {
CA string `yaml:"ca"` // PEM-encoded CA certificate (mTLS only)
Cert string `yaml:"cert"` // PEM-encoded server certificate
Key string `yaml:"key"` // PEM-encoded private key
ServerName string `yaml:"serverName"` // Optional SNI override
}
TLSConfig specifies TLS material for an inbound HTTPS listener. When CAFile is non-empty the listener enforces mutual TLS: connecting clients must present a certificate signed by that CA.
NB: Be sure to set ServerName when the host name you dial doesn't match the CN or SAN on the server's certificate.
type Upstream ¶
type Upstream struct {
Name string `yaml:"name"`
Listen ListenConfig `yaml:",inline"`
Namespaces NamespaceConfig `yaml:"namespaces"`
}
Upstream describes a single upstream Temporal cluster the proxy connects workers to along with configuration for that remote cluster. Name identifies the upstream so routing rules can refer to it; it must be unique within the config.
func (*Upstream) IsTemplated ¶
IsTemplated reports whether the upstream's hostPort contains a text/template action and so must be resolved per request.