Documentation
¶
Index ¶
- Constants
- func FormatSeconds(millis int64) string
- func IsDNSName(text string) bool
- func ParseAgent(text string) (address string, port int64, ok bool)
- func ParseEndpoint(text string) (host string, port int64, dns bool, ok bool)
- func ParseKeysURL(text string) (host string, port int64, dns bool, ok bool)
- func ParsePercent(text string) (percent int, ok bool)
- func ParseResolver(text string) (address string, port int64, ok bool)
- func ParseSize(text string) (bytes int64, ok bool)
- func ParseTime(text string) (millis int64, ok bool)
- func Reason(err error) string
- func SortProblems(ps []Problem)
- type Auth
- type Claim
- type ClientAddress
- type Count
- type Envoy
- type Gateway
- type Hash
- type Header
- type Health
- type JWT
- type Limits
- type Log
- type MatchKind
- type OTel
- type Port
- type Pos
- type Problem
- type Problems
- type Protocol
- type RPC
- type RPCTarget
- type RateLimit
- type RequestHeaders
- type Resolver
- type Route
- type Sample
- type SampleRule
- type Service
- type ServicePort
- type Size
- type TLS
- type Tag
- type Text
- type Time
- type Timeouts
- type Tracing
- type XRay
Constants ¶
const ( SizePattern = `^[1-9][0-9]*(KiB|MiB|GiB)$` TimePattern = `^` + timeFragment + `$` TimeOrNonePattern = `^(none|` + timeFragment + `)$` PercentPattern = `^(100|[1-9]?[0-9])%$` AgentPattern = `^[0-9]{1,3}(\.[0-9]{1,3}){3}:[1-9][0-9]{0,4}$` )
ParseSize, ParseTime, ParsePercent and ParseAgent compile SizePattern, TimeOrNonePattern, PercentPattern and AgentPattern, the same text the schema's "pattern" carries, so the schema and the parser accept the same forms. They differ in three places. No parser compiles TimePattern, and ParseTime accepts "none", so a field whose schema uses TimePattern relies on the schema check alone to refuse "none". A value can match its pattern yet overflow an int64, which only the parser refuses. And an agent can match its pattern, which takes digits and dots, and still hold an octet above 255, an octet with a leading zero or a port above 65535, which only ParseAgent refuses. The two time patterns share timeFragment so their digits and units cannot drift apart.
Variables ¶
This section is empty.
Functions ¶
func FormatSeconds ¶
FormatSeconds writes a duration the way Envoy reads it: the ProtoJSON form of google.protobuf.Duration, which accepts any number of fractional digits down to nanoseconds, so trailing zeros are dropped. Integer arithmetic keeps the text exact, because a float64 cannot hold every int64 millisecond count. Go's / and % truncate toward zero, so for a negative count both parts carry the sign; it is written once in front and the parts are made positive. The parts are negated rather than millis itself, because -math.MinInt64 does not fit in an int64.
func IsDNSName ¶ added in v2.1.0
IsDNSName says whether text is an RFC 1123 host name, without a trailing dot and at most 253 characters. A name whose last label is all digits is refused, because RFC 1123 section 2.1 says a host name never has the dotted decimal form: a mistyped IPv4 address such as 10.0.0.256 is then neither an address nor a name, and is refused instead of being looked up.
func ParseAgent ¶
ParseAgent returns the IPv4 address and the UDP port of an agent written as address:port. The pattern refuses a port of 0 or one with a leading zero, which netip.ParseAddrPort would take; netip refuses what the pattern cannot, an octet above 255 or with a leading zero and a port above 65535.
func ParseEndpoint ¶ added in v2.1.0
ParseEndpoint returns the host and the port of an endpoint written as host:port, where the host is an IP address or a DNS name; dns is true for a name, which the proxy looks up while it runs. An IPv6 address takes brackets, as netip.ParseAddrPort reads it, and host holds it without them. The port is always written, from 1 to 65535: no collector listens on port 0. A zone is refused, as ParseResolver refuses one.
func ParseKeysURL ¶ added in v2.1.0
ParseKeysURL returns the host and the port of an auth.jwt.keys URL: https, with no user part, and a host that is an IP address or a DNS name; dns is true for a name, which the proxy looks up while it runs. An IPv6 address takes brackets, which net/url requires, and host holds it without them. The port is 443 when not written, and otherwise from 1 to 65535. A zone is refused, as ParseResolver refuses one.
func ParsePercent ¶
func ParseResolver ¶ added in v2.1.0
ParseResolver returns the IP address and the port of a name server written as an address with an optional port, 53 when not written. An IPv6 address with a port takes brackets, as netip.ParseAddrPort reads it. Port 0 is refused: no name server answers there. A zone (fe80::1%eth0) is refused: Envoy 1.40.2 aborts on one in a resolver's address when it loads the file (measured).
func ParseSize ¶
ParseSize returns the size in bytes. It refuses a size whose byte count does not fit in an int64 instead of letting it wrap to a wrong or negative limit.
func ParseTime ¶
ParseTime returns the time in milliseconds. "none" is 0: the caller decides what "none" means for the field it fills.
func Reason ¶
Reason is why a file or directory cannot be read, as a problem words it. The message it goes in names the path already, so the path an os error holds is left out rather than written twice.
func SortProblems ¶
func SortProblems(ps []Problem)
SortProblems orders problems by file, line, column, key path and message. The message is the last key so that two problems at the same position still come out in the same order on every run. A YAML problem has no key path, so YAML problems keep the order they had before the key path existed.
Types ¶
type Auth ¶
type Auth struct {
Service Text // the service of `ask`, at the position of `ask`
Path string
Timeout Time
Enabled bool
Allow bool // when_unavailable: allow
OnlyWithHeader string
Send, Accept []Header
SendRequest bool // send_request: true, which tells the check the request's path, method, scheme and host
}
type Claim ¶ added in v2.1.0
type Claim struct {
Header, Name string
}
Claim is one entry of auth.jwt.claims: the token's claim Name, copied into the request header Header.
type ClientAddress ¶ added in v2.1.0
type ClientAddress string
ClientAddress says which address counts as the client's.
const ( // ClientForwarded is the last address a proxy in front appended to X-Forwarded-For. ClientForwarded ClientAddress = "forwarded" // ClientConnection is the peer of the TCP connection. ClientConnection ClientAddress = "connection" )
type Envoy ¶
type Envoy struct {
Namespace string // "proxyfile" when not written
Heap *Size // nil when not written
ConnectBridge bool // true when not written
}
Envoy is the envoy block: what only the Envoy generator reads.
type Gateway ¶
type Gateway struct {
Listen Port
Admin *Port
TLS *TLS // nil when not written: the public listener serves plain HTTP
ClientAddress ClientAddress // when not written, ClientConnection with TLS and ClientForwarded without
Limits Limits
Timeouts Timeouts
Services []Service // written order
ServicesPos Pos // the `services` key
Resolver *Resolver // nil when not written
Auth *Auth // the check, auth.ask; nil when ask is not written
JWT *JWT // auth.jwt; nil when not written
RemoveFromClients []Header
Origins Text // the origins file as written, absolute or relative to the proxyfile's directory; "" when the proxyfile writes the origins
Routes []Route // written order
RoutesPos Pos // the `routes` key
Log *Log
Tracing *Tracing // nil when neither tracing nor envoy.tracing is written
Envoy Envoy
}
Gateway is one proxyfile after reading: every default filled in and every rule checked. Each value a rule or a later stage may name in a problem keeps the position it was written at; a default that was not written has no position, and nothing refuses a default.
type Hash ¶ added in v2.1.0
Hash is what balance hash hashes: exactly one of Header and Client is set.
type Header ¶
type Header struct {
Name string // without the trailing * of a prefix
Prefix bool // written with a trailing *
Pos Pos
}
func (Header) Covers ¶ added in v2.1.0
Covers reports whether the entry h names every header other names: an exact entry covers the one name equal to it, and a prefix entry every name and prefix that starts with it. The early header removal adds no header an entry before it covers, and the reader refuses a claims header an entry of send or accept covers.
type Health ¶ added in v2.1.0
type Health struct {
Path, GRPC *Text
Interval, Timeout Time
Healthy, Unhealthy int64
Pos Pos // the health key
}
Health is the service's active checks. Path and GRPC are nil when not written; GRPC keeps the true for its position, as Route.AuthOff keeps off. Interval, Timeout, Healthy and Unhealthy are 5s, 2s, 2 and 3, without a position, when not written.
type JWT ¶ added in v2.1.0
type JWT struct {
Issuer string
Audiences []string // nil for any, which accepts every audience
// File or URL is set: the keys, as a JSON Web Key Set, in a file on the proxy's host or at an https URL.
File, URL string
// Host, Port and DNS describe the URL's host, "" and 0 with a file: an IP address (an IPv6 one without brackets) or a
// DNS name, which the proxy looks up while it runs; Port is 443 when the URL writes none.
Host string
Port int64
DNS bool
CA string // the CA bundle the URL's certificate must chain to: /etc/ssl/certs/ca-certificates.crt when not written, "" with a file
Header string // the header that carries the token; authorization when not written
Optional bool // a request with no token goes through unverified
Claims []Claim // written order
}
JWT is auth.jwt: the proxy verifies a signed token on each request itself.
type Limits ¶
type Limits struct {
Connections *Count
RequestHeaders *RequestHeaders
}
type OTel ¶ added in v2.1.0
type OTel struct {
Host string // the collector's IP address, an IPv6 one without brackets, or its DNS name
Port int64
DNS bool // Host is a DNS name, which the proxy looks up while it runs
Service string // the service.name the spans carry
RatePercent int // 5 when sample.rate is not written
}
OTel is tracing.provider.otel: an OpenTelemetry span for each sampled request, sent as OTLP over gRPC to a collector.
type Pos ¶
type Pos struct {
File string
Line, Column int
Path string // the key path, where the syntax gives no line: services.api.http, routes[1].to
}
Pos is where a problem was found. Line and Column count from 1, so 0 is free to mean "not known". Path places a value whose syntax gives it no line, which is every value of a HOCON file: the HOCON library keeps no position for a value, only for a syntax error.
type Problem ¶
func CannotRead ¶
CannotRead is the problem of a file that cannot be read. Every reader of every form reports it with this one text, so a missing file reads the same whichever reader met it.
func FileProblem ¶
FileProblem is a problem with the file as a whole, which names no line. It returns a list because every caller returns it alone, as all the problems of its stage.
type Problems ¶
type Problems struct {
// contains filtered or unexported fields
}
Problems collects the problems of one stage. A stage goes on after a problem, so one run names every problem of it.
type RateLimit ¶ added in v2.1.0
RateLimit is a token bucket: it holds at most Requests + Burst tokens and refills at Requests tokens per Per, and each request takes one. Burst is 0 and ByClient true when not written; ByClient gives each client address a bucket of its own, and false counts every client together.
type RequestHeaders ¶
type Route ¶
type Route struct {
Pos Pos
RPC *RPC // the `- rpc:` entry; the other fields are empty then
Name Text
Match MatchKind
Value Text // the prefix, path or pattern
Method string
To Text
Rewrite *Text
AuthOff *Text // the `auth: off` value, kept for its position
Retries int64
RateLimit *RateLimit // nil when not written: the route is never limited
}
Route is one entry of `routes`: the `- rpc:` entry when RPC is set, else a plain route.
type Sample ¶
type Sample struct {
Default SampleRule
Rules []SampleRule // written order
}
Sample is what the sampling manifest holds. The default rule matches every request, so its Host, Method and Path are empty.
type SampleRule ¶
type Service ¶
type Service struct {
Name string
Pos Pos // the service's name
// Addresses are the backends: address, or 127.0.0.1 when neither address nor addresses is written, as one item,
// or each of addresses in written order.
Addresses []Text
DNS bool // Addresses holds one DNS name, which the proxy looks up while it runs
Balance Text // "round_robin", without a position, when not written
Hash *Hash
Health *Health // nil when not written: every backend stays in the pool
HostHeader string
Ports []ServicePort // written order
}
type ServicePort ¶
type TLS ¶ added in v2.1.0
type TLS struct {
Certificate, Key string
ClientsCA string // "" without tls.clients: no client certificate is asked for
}
TLS is the public listener's certificate and key, and the CA a client's certificate must chain to when tls.clients is written. Each is an absolute path to a PEM file on the proxy's host.
type Tag ¶
type Tag struct {
Name, Env, Header string
Default string // "" when not written; the check refuses an empty one
}
Tag is one custom tag: exactly one of Env and Header is set.
type Tracing ¶
type Tracing struct {
// XRay and OTel are the provider written: exactly one is set, and envoy.tracing takes XRay alone.
XRay *XRay
OTel *OTel
Tags []Tag // written order
PathInURL bool
}
Tracing is the tracing key, or envoy.tracing, its old place, which holds the same keys: a trace span for each sampled request.
type XRay ¶
type XRay struct {
Address string // the agent's IPv4 address; 127.0.0.1 when not written
Port int64 // the agent's UDP port; 2000 when not written
Segment string
Sample *Sample // nil when not written: no manifest, and Envoy's own rule applies
}
XRay is tracing.provider.xray: an X-Ray segment for each sampled request, sent to an agent over UDP.