config

package
v0.1.0-alpha.20260716 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
var ConfigFileTag = fx.ResultTags(`name:"configFile"`)
View Source
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

func Load(r io.Reader) (*Config, error)

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

func LoadFile(path string) (*Config, error)

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

func (c *Config) Validate() error

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

type ConfigParams struct {
	fx.In
	File string `name:"configFile"`
}

ConfigParams holds the fx-injected dependencies for loading the config file.

type ListenConfig

type ListenConfig struct {
	HostPort string     `yaml:"hostPort"`
	TLS      *TLSConfig `yaml:"tls"`
}

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

type NamespaceMapping struct {
	Local  string `yaml:"local"`
	Remote string `yaml:"remote"`
}

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.

func (*Routing) Validate

func (r *Routing) Validate() error

Validate checks every rule. Per-rule failures are stamped with a "rules[i]" subject. It does not verify that the referenced upstreams exist; that check needs the full set of upstream names and lives in Config.Validate.

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.

func (*TLSConfig) Validate

func (t *TLSConfig) Validate() error

Validate checks the configured certificate material: mutual TLS when a CA is set, otherwise server-only TLS.

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

func (u *Upstream) IsTemplated() bool

IsTemplated reports whether the upstream's hostPort contains a text/template action and so must be resolved per request.

func (*Upstream) Validate

func (u *Upstream) Validate() error

Validate checks the upstream name, dial target, and namespace configuration. A templated hostPort (containing a text/template action) is resolved per-request, so it is not checked as a literal host:port here; a static hostPort still is.

Jump to

Keyboard shortcuts

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