Documentation
¶
Overview ¶
Package format holds the one description of each input file and checks a file's tree against it.
Index ¶
- Constants
- Variables
- func Check(spec Field, n *tree.Node) []model.Problem
- func CoreKeys(f Field) []string
- func FormRefusedMessage(key, form, target, instead string) string
- func LessStrictHeading(t Target) string
- func LessStrictList(t Target) []byte
- func LessStrictWarning(t Target) string
- func MatrixRows() []string
- func NoGenerator(backend string) string
- func Reference(f Field, path, class string) []byte
- func Refusals(f Field, file, proxyfile *tree.Node, t Target) []model.Problem
- func RefusedMessage(key string, t Target) string
- func Schema(spec Field) ([]byte, error)
- func SupportMatrix(rows []string, targets []Target) []byte
- func WrittenKeys(f Field, root *tree.Node) []string
- type Field
- type Kind
- type LessStrict
- type Level
- type Refusal
- type Support
- type Target
Constants ¶
const ( AgentExpect = "an IPv4 address and a port from 1 to 65535, such as 127.0.0.1:2000" EndpointExpect = "an IP address or a DNS name, and a port, such as 127.0.0.1:4317 or [fd00::40]:4317" )
AgentExpect and EndpointExpect are exported because the reader's message for an agent or an endpoint its pattern admits but ParseAgent or ParseEndpoint refuses must be the check's, and the reader's tooLarge cannot walk the provider's Either to read it from the description.
const ( // HAProxyRewriteRoom is tune.maxrewrite's default, the bytes of each buffer HAProxy keeps for rewrites: a request // head larger than tune.bufsize less these is answered 400 (HAProxy 3.2 and 3.4 configuration manual, tune.bufsize). HAProxyRewriteRoom = 1024 // HAProxySmallestHeaders is the smallest limits.request_headers.size HAProxy writes: HTTP/2 mandates a tune.bufsize // of 16384 or more (the manual, tune.bufsize), of which HAProxyRewriteRoom is kept, 15KiB. HAProxySmallestHeaders = 16384 - HAProxyRewriteRoom // HAProxyMostHeaderFields is the most limits.request_headers.count HAProxy writes: tune.http.maxhdr takes 1 to // 32767 lines and counts the request line among them (the manual, tune.http.maxhdr). HAProxyMostHeaderFields = 32766 // HAProxyLongestTime is the longest time an HAProxy timer holds, in milliseconds: the validator loaded timeout // client 2147483647ms and refused 2147483648ms with "timer overflow ... (maximum value is 2147483647 ms or ~24.8 // days)" on HAProxy 3.2.26 and 3.4.7. HAProxyLongestTime = 2147483647 // HAProxyMostRetries is the most retries HAProxy writes: http-request set-retries takes 0 to 100 (the manual, // http-request set-retries). HAProxyMostRetries = 100 )
HAProxy's bounds on values the format admits, which its declaration refuses past them and its generator refuses too.
Variables ¶
var ( MatchKinds = []string{"prefix", "path", "pattern"} ServicePorts = []Field{withRule(port("http", "The service's HTTP port.", false), "Spoken as HTTP/1.1."), withRule(port("grpc", "The service's gRPC port.", false), "Spoken as HTTP/2 without TLS (h2c).")} )
MatchKinds are the keys of which a route writes exactly one, and ServicePorts the port keys of a service, each named by its protocol. The decoder reads a route's match and a service's ports through these two lists, so a key added to either is read without a second list to keep in step.
var ( CheckRequired = []string{"timeout", "enabled", "when_unavailable"} CheckKeys = slices.Concat(CheckRequired, []string{"only_with_header", "send", "accept", "send_request"}) )
CheckRequired are the keys of auth that ask needs beside it, and CheckKeys every key of auth that sets the check, which a file without ask cannot use. The schema writes the rule from them (authNeeds) and the reader refuses by them (internal/read/decode.go, the decoder's auth method), so the two cannot differ.
var ( NginxRemovedFromClients = []string{"proxy-connection", "x-envoy-auth-failure-mode-allowed", "x-envoy-expected-rq-timeout-ms", "x-envoy-force-trace", "x-envoy-hedge-on-per-try-timeout", "x-envoy-internal", "x-envoy-ip-tags", "x-envoy-max-retries", "x-envoy-original-url", "x-envoy-retriable-header-names", "x-envoy-retriable-status-codes", "x-envoy-retry-grpc-on", "x-envoy-retry-on", "x-envoy-upstream-alt-stat-name", "x-envoy-upstream-rq-per-try-timeout-ms", "x-envoy-upstream-rq-timeout-alt-response", "x-envoy-upstream-rq-timeout-ms", "x-envoy-upstream-stream-duration-ms", "x-forwarded-client-cert", "x-gateway-action", "x-gateway-reports"} NginxRemovedFacingClients = []string{"x-envoy-decorator-operation", "x-envoy-downstream-service-cluster", "x-envoy-downstream-service-node", "x-envoy-original-host", "x-envoy-original-path"} )
NginxRemovedFromClients are the headers the nginx output removes from every client's request itself, sorted: each header the Envoy output removes (generator.RemovedByEnvoy), the unchecked mark and the two question headers; and NginxRemovedFacingClients are those it removes too with client_address connection alone (generator.RemovedByEnvoyFacingClients). The Envoy output removes each before its check's only_with_header condition reads the request, so a client that sends one is never asked about, where nginx's handler reads the client's own copy and asks; with forwarded both pass the second list on and ask by it (measured on Envoy 1.40.2 beside nginx 1.30.6, each name sent with a token the check denies). The format reads header names in lower case only.
var HAProxyFramedBy = []string{"content-length", "transfer-encoding", "host", "te", "connection", "upgrade"}
HAProxyFramedBy are the headers HAProxy frames or routes a request by, so the auth check's answer never sets them on the request it passes on: a check service must never be able to change how HAProxy frames that request. Envoy 1.40.2 set each from the check's answer when auth.accept named it in full or under a prefix (measured), so the declaration refuses a name of them written in full, and HAProxy's script never sets one (internal/haproxy/script.go).
var HAProxyNotRemovable = []string{"content-length", "connection", "upgrade"}
HAProxyNotRemovable are the headers Envoy 1.40.2 removes, in full or under a prefix, in a way HAProxy cannot write: it sent the body chunked once Content-Length was gone, where HAProxy sent content-length: 0 and lost the body, and it left a WebSocket upgrade unanswered once Connection or Upgrade was gone, where HAProxy served it as a plain request (measured on HAProxy 3.2.26 and 3.4.7). The declaration refuses them on remove_from_clients and auth.accept, whose names are removed from clients too, and the HAProxy generator refuses the same forms.
var Health = Field{Name: "health", Doc: "Active checks of each backend: one that fails unhealthy checks in a row leaves the pool until it passes healthy checks in a row.", Kind: Map, Rule: "At least one of `path` and `grpc`.", Fields: []Field{ withRule(Field{Name: "path", Doc: "The path an HTTP GET must answer with a 2xx, on the service's http port.", Kind: Text, Pattern: `^/[^\t\n\f\r ]*$`, Expect: "a path starting with /, with no space"}, "Needs an `http` port."), {Name: "grpc", Doc: "true checks the service's grpc port with the gRPC health protocol, grpc.health.v1.Health/Check.", Kind: True, Rule: "Needs a `grpc` port."}, {Name: "interval", Doc: "How often each backend is checked; 5s when not written.", Kind: Text, Pattern: model.TimePattern, Expect: "a time such as 5s", Rule: "At least `1s`."}, {Name: "timeout", Doc: "How long one check may take; 2s when not written.", Kind: Text, Pattern: model.TimePattern, Expect: "a time such as 2s", Rule: "Shorter than `interval`."}, {Name: "healthy", Doc: "Checks in a row a backend must pass to join the pool; 2 when not written.", Kind: Int, Min: 1, Max: 255}, {Name: "unhealthy", Doc: "Checks in a row a backend must fail to leave the pool; 3 when not written.", Kind: Int, Min: 1, Max: 255, Rule: "With `grpc`, the Envoy generator's check removes a backend that answers it is not serving at once."}, }}
Health is a service's health key. It is exported because the reader quotes its Expect for a time the parser refuses, and cannot walk the services' Dict to reach it.
var Methods = Field{ Doc: "The RPC methods the gateway routes, each with what the check is told about it.", Kind: List, Item: &methodField, Place: "rpc.methods", }
Methods describes the RPC methods file: one entry per method. Which service a method goes to is decided by the rpc entry of the proxyfile, not here.
var NginxNotAccepted = []string{"connection", "content-length", "host", "http2-settings", "origin", "proxy-connection", "te",
"transfer-encoding", "upgrade", "x-envoy-auth-failure-mode-allowed", "x-envoy-decorator-operation",
"x-envoy-downstream-service-cluster", "x-envoy-downstream-service-node", "x-envoy-expected-rq-timeout-ms",
"x-envoy-external-address", "x-envoy-force-trace", "x-envoy-hedge-on-per-try-timeout", "x-envoy-internal",
"x-envoy-ip-tags", "x-envoy-max-retries", "x-envoy-original-host", "x-envoy-original-path", "x-envoy-original-url",
"x-envoy-retriable-header-names", "x-envoy-retriable-status-codes", "x-envoy-retry-grpc-on", "x-envoy-retry-on",
"x-envoy-upstream-alt-stat-name", "x-envoy-upstream-rq-per-try-timeout-ms", "x-envoy-upstream-rq-timeout-alt-response",
"x-envoy-upstream-rq-timeout-ms", "x-envoy-upstream-stream-duration-ms", "x-forwarded-client-cert", "x-forwarded-for",
"x-forwarded-proto", "x-gateway-action", "x-gateway-reports", "x-request-id"}
NginxNotAccepted are the names auth.accept may not name on nginx, sorted: every header the route's location writes itself (writeLocation in internal/nginx: Host, X-Request-Id, X-Forwarded-Proto, Origin, X-Forwarded-For, x-envoy-external-address, Upgrade, Connection, HTTP2-Settings and TE, each header the Envoy output removes, which the location writes empty, X-Forwarded-For, x-envoy-external-address and generator.RemovedByEnvoyFacingClients with client_address connection alone, each refused in both modes so that a list stays valid when the mode changes, and with auth.ask the unchecked mark and the two question headers, which it sets or writes empty), and content-length and transfer-encoding, which nginx writes itself as it frames the body it passes on. The Envoy output sets the mark from a check's 200 that carries it when auth.accept names it, and sends the service neither question header whatever the check answers (measured on Envoy 1.40.2). nginx sets an accepted header with a line of the route's location, beside the location's own line for the same name, and a check service must never change how nginx frames or routes the request it passes on, nor send the service a header the location keeps from it. Envoy 1.40.2 set a framing header from the check's answer when auth.accept named it (measured for HAProxyFramedBy), so the declaration refuses each of these by name. The format reads header names in lower case only, so each is compared as written.
var NginxRemovedTraced = []string{"x-envoy-decorator-operation", "x-envoy-downstream-service-cluster", "x-envoy-downstream-service-node"}
NginxRemovedTraced are the headers the nginx output removes from every client's request with the otel provider, under either client_address, sorted, which the nginx generator reads too: a client's copy would name the span or fill its downstream_cluster, and reach the service. The Envoy output removes them with otel (downstreamHeaders and decoratorHeader in internal/envoy) in the same early header removal as NginxRemovedFromClients (downstreamRemoved in internal/envoy), which Envoy runs before every filter, the check's only_with_header condition among them, so it never asks the check about a client's copy, where nginx's handler reads the client's own copy and asks (asked in proxyfile.js): read from the code, where the other names' removal was measured. With client_address connection they are among NginxRemovedFacingClients already.
var Origins = Field{ Doc: "The origins file: the CORS settings and, for each environment, its hosts and the browser origins it admits.", Kind: Map, Fields: []Field{ corsField, {Name: "environments", Doc: "The environments, each with its hosts and the browser origins it admits.", Kind: List, Required: true, Rule: "At least one environment.", Item: &Field{Doc: "One environment.", Kind: Map, Place: "origins.<environment name>", Fields: slices.Concat([]Field{ {Name: "name", Doc: "The environment's name.", Kind: Text, Required: true, Place: "origins.<environment name>", Rule: "It names the environment's virtual host. Not empty, and not used by another environment."}, }, environmentLists)}}, }, }
The rules for hosts, origins and patterns belong to the origins reader, which names the environment in its messages; this description checks only the keys and the kinds. environments has no Place: it is the proxyfile's origins key, which names this file, so a target that refuses origins refuses the proxyfile before this file is read.
var Proxyfile = Field{ Doc: "A proxyfile: one gateway, the services behind it and the routes to them, from which proxyfile writes the proxy's configuration.", Kind: Map, Moved: map[string]string{"namespace": "envoy.namespace"}, Fields: []Field{ port("listen", "The port of the public listener, on 0.0.0.0.", true), withRule(port("admin", "The port of the admin listener, on 127.0.0.1; no admin listener when not written.", false), "Not the same as `listen`. It answers only `/ready`, `/stats` and `/server_info`."), {Name: "tls", Doc: "The public listener serves HTTPS with this certificate and key; without it, plain HTTP.", Kind: Map, Rule: "The proxy reads the files when it starts.", Fields: []Field{ absolutePath("certificate", "The certificate chain, PEM, a file on the proxy's host.", true), absolutePath("key", "The private key, PEM, a file on the proxy's host.", true), {Name: "clients", Doc: "Require a client certificate on every connection (mutual TLS).", Kind: Map, Fields: []Field{ absolutePath("ca", "The CA bundle, PEM, that a client's certificate must chain to.", true), }}, }}, {Name: "client_address", Doc: "Which address counts as the client's: forwarded, the last address a proxy in front appended to X-Forwarded-For, or connection, the peer of the TCP connection.", Kind: Enum, Values: []string{"forwarded", "connection"}, Rule: "When not written: `connection` in a file that writes `tls`, `forwarded` otherwise. A rate limit by client and `hash.client` read it."}, {Name: "limits", Doc: "Limits on connections and request headers.", Kind: Map, Moved: map[string]string{"heap": "envoy.heap"}, Fields: []Field{ {Name: "connections", Doc: "The most connections at once, from clients and to each service.", Kind: Int, Min: 1, Max: largestUint32}, {Name: "request_headers", Doc: "The largest header block and the most header fields a request may carry.", Kind: Map, Fields: []Field{ {Name: "size", Doc: "The largest header block of a request.", Kind: Text, Required: true, Pattern: model.SizePattern, Expect: "a size such as 96KiB", Rule: "At most `8MiB`."}, {Name: "count", Doc: "The most header fields in a request.", Kind: Int, Required: true, Min: 1, Max: largestUint32}, }}, }}, {Name: "timeouts", Doc: "How long a request, an idle request and an idle connection to a service may last.", Kind: Map, Fields: []Field{ withRule(timeOrNone("request", "The longest a whole request may take."), "Without it, the Envoy configuration keeps Envoy's default of 15 seconds, counted from the end of the request. `none` removes the limit."), timeOrNone("idle", "The longest a request may go without sending or receiving data."), withRule(timeOrNone("upstream_idle", "The longest a connection to a service is kept open with no request on it."), "Without it, the Envoy configuration keeps Envoy's default of 1 hour."), }}, {Name: "services", Doc: "The services behind the gateway, by name.", Kind: Dict, Required: true, Rule: "At least one service.", Key: &Field{Name: "service name", Kind: Text, Pattern: serviceNamePattern, Expect: serviceNameExpect}, Item: &Field{Doc: "One service: a port per protocol, an optional Host header, its backends, how requests are spread over them and how they are checked.", Kind: Map, Rule: "It has at least one port.", Fields: slices.Concat(ServicePorts, []Field{ {Name: "host_header", Doc: "The Host header a request carries when a route sends it to this service.", Kind: Text, Pattern: `^[A-Za-z0-9.:\[\]-]+$`, Expect: "a host, with an optional port", Rule: "Without it a request keeps the client's Host."}, {Name: "address", Doc: "The service's IP address, or a DNS name the proxy looks up again while it runs; 127.0.0.1 when not written.", Kind: Text, Pattern: `^[^\t\n\f\r ]+$`, Expect: "an IP address or a DNS name", Rule: "A name has no port and is looked up every 5 seconds; every address it gives is a backend. Not with `addresses`."}, {Name: "addresses", Doc: "The service's backends, by IP address, each on the service's ports.", Kind: List, Item: &Field{Kind: Text, Pattern: `^[^\t\n\f\r ]+$`, Expect: "an IP address"}, Rule: "Two or more, none written twice. Not with `address`."}, {Name: "balance", Doc: "How requests are spread over the backends; round_robin when not written.", Kind: Enum, Values: []string{"round_robin", "least_requests", "random", "hash"}}, {Name: "hash", Doc: "What balance hash hashes, so that one client or one header value always reaches the same backend.", Kind: Map, OneOf: []string{"header", "client"}, Rule: "Required with `balance: hash`, and refused with any other balance.", Fields: []Field{ {Name: "header", Doc: "The request header whose value is hashed; a request without it goes to a backend chosen at random.", Kind: Text, Pattern: lowerHeaderPattern, Expect: lowerHeaderExpect}, {Name: "client", Doc: "true hashes the client's address, the one client_address names.", Kind: True}, }}, Health, })}}, {Name: "dns", Doc: "The name lookups of every DNS name the gateway reaches: a service's address, the tracing endpoint and the keys URL's host.", Kind: Map, Fields: []Field{ {Name: "resolver", Doc: "The name server the proxy asks; the host's own resolver configuration when not written.", Kind: Text, Pattern: `^[^\t\n\f\r ]+$`, Expect: "an IP address with an optional port, such as 10.0.0.2:53", Rule: "Port 53 when not written. An IPv6 address with a port is written in brackets, such as [fd00::53]:5353; no zone."}, }}, {Name: "auth", Doc: "The checks every request goes through before it reaches a service: a service of yours asked about each request, " + "a signed token the proxy verifies, or both.", Kind: Map, Rule: "At least one of `ask` and `jwt`. Without `auth` there is no check.", AtLeastOneOf: []string{"ask", "jwt"}, Needs: authNeeds, Fields: []Field{ {Name: "ask", Doc: "The service and the path the gateway asks.", Kind: Text, Pattern: `^[a-z][a-z0-9-]* /[^\t\n\f\r ]*$`, Expect: "a service and a path, such as accounts /check", Rule: "The service needs an `http` port."}, {Name: "timeout", Doc: "How long the gateway waits for the answer.", Kind: Text, Pattern: model.TimePattern, Expect: "a time such as 2s", Rule: "Required with `ask`, and refused without it. At most `4294967295s`. `none` is not accepted."}, {Name: "enabled", Doc: "true runs the check on every request it applies to, false on none.", Kind: Bool, Rule: "Required with `ask`, and refused without it. It does not turn `jwt` off."}, {Name: "when_unavailable", Doc: "What happens to a request when the check cannot be asked: allow lets it through, deny refuses it.", Kind: Enum, Values: []string{"allow", "deny"}, Rule: "Required with `ask`, and refused without it."}, {Name: "only_with_header", Doc: "The check runs only on requests that carry this header.", Kind: Text, Pattern: lowerHeaderPattern, Expect: lowerHeaderExpect, Rule: "A request without it, or with it empty, goes through with no check. Needs `ask`."}, withRule(headers("send", "The request headers the check is sent; a name ending in * is a prefix."), "Needs `ask`."), withRule(headers("accept", "The headers of the check's answer that reach the service; a name ending in * is a prefix."), "Needs `ask`."), {Name: "send_request", Doc: "true also tells the check which request it is asked about: its path and query in x-forwarded-uri, " + "its method in x-forwarded-method, its scheme in x-forwarded-proto and its host in x-forwarded-host; false when not written.", Kind: Bool, Rule: "Needs `ask`."}, jwtField, }}, withRule(headers("remove_from_clients", "Headers removed from every client request before routing and before any filter; a name ending in * is a prefix."), "No route, filter or service sees a client's copy. Envoy holds header names in lower case, so a name with a capital would never match."), withRule(corsField, "Not written when `origins` names a file, which holds its own `cors`."), {Name: "origins", Doc: "The browser origins each environment admits, by environment name; or, as in 1.0, the name of an origins file, relative to this file.", Kind: Either, Required: true, Expect: "a mapping of environments by name, or a file name", Rule: "At least one environment.", Choices: []Field{ {Kind: Text, Pattern: `^[^\t\n\f\r ]+$`, Expect: "a file name"}, {Kind: Dict, Key: &Field{Name: "environment name", Kind: Text, Pattern: `[\s\S]`, Expect: "one character or more"}, Item: &Field{Doc: "One environment: its hosts and the browser origins it admits.", Kind: Map, Fields: environmentLists}}, }}, {Name: "routes", Doc: "The routes, tried in the order written; the rpc entry marks where the RPC routes go.", Kind: List, Required: true, Rule: "Not empty. The rpc entry is `- rpc:` in YAML and `{ rpc { ... } }` in HOCON.", Item: &Field{Kind: Either, Expect: "a mapping: a route or an rpc entry", Choices: []Field{ {Doc: "The place in the order where the RPC routes go.", Kind: Map, Select: "rpc", Fields: []Field{ {Name: "rpc", Doc: "The RPC routes: one exact-path route for each RPC method.", Kind: Map, Required: true, Rule: "At most one rpc entry in a file. It needs methods from exactly one of `rpc.methods`, `rpc.proto` and `--rpc-methods`.", Fields: []Field{ retries("How many times an RPC call that never reached its service is tried again."), withRule(RateLimit, "One limit for every RPC route of the entry, in every environment."), {Name: "to", Doc: "The service the RPC methods of each package go to.", Kind: Dict, Required: true, Rule: "Not empty.", Key: &Field{Name: "package pattern", Kind: Text, Doc: "Which services' methods go to the value: * matches every service, a package name ending in .* every service " + "whose full name starts with that package and a dot, and a full service name that service alone.", Pattern: `^(\*|[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*(\.\*)?)$`, Expect: "*, a package name ending in .*, or a full service name"}, Item: &Field{Kind: Either, Expect: "a service name, or a mapping with service and name", Rule: "The service needs a `grpc` port.", Choices: []Field{ serviceName("", "The service the methods go to.", false), {Doc: "The service the methods go to, and the name of their routes.", Kind: Map, Fields: []Field{ serviceName("service", "The service the methods go to.", true), {Name: "name", Doc: "The name of the routes; the service's name followed by -rpc when not written.", Kind: Text, Pattern: routeNamePattern, Expect: routeNameExpect}, }}, }}}, }}, }}, {Doc: "A route: a name, what it matches and the service it goes to.", Kind: Map, OneOf: MatchKinds, Fields: []Field{ {Name: "name", Doc: "The route's name.", Kind: Text, Required: true, Pattern: routeNamePattern, Expect: routeNameExpect, Rule: "It appears in the request log. Not used twice, and not `rpc`."}, path("prefix", "Matches paths that start with this text."), path("path", "Matches this path exactly."), {Name: "pattern", Doc: "Matches paths by this regular expression, in RE2 syntax.", Kind: Text, Pattern: `[\s\S]`, Expect: "a regular expression that is not empty", Rule: "It must compile."}, {Name: "method", Doc: "Matches only requests with this HTTP method.", Kind: Text, Pattern: `^[A-Z]+$`, Expect: "an HTTP method in capitals, such as POST"}, withRule(serviceName("to", "The service the route goes to.", true), "A declared service with an `http` port."), withRule(path("rewrite", "Replaces the matched prefix or path before the request goes to the service."), "Not allowed with `pattern`."), {Name: "auth", Doc: "off sends the route's requests to the service without auth's checks: no service is asked and no token is verified.", Kind: Enum, Values: []string{"off"}, Rule: "Needs an `auth` key."}, retries("How many times a request that never reached the service is tried again."), withRule(RateLimit, "One limit for the route's copy in every environment."), }}, }}}, {Name: "rpc", Doc: "The RPC methods the gateway routes; the routes' rpc entry maps them to services.", Kind: Map, Rule: "Written here or read from `.proto` files, instead of in a methods file. Not given together with `--rpc-methods`.", OneOf: []string{"methods", "proto"}, Fields: []Field{ {Name: "methods", Doc: "One entry for each RPC method the gateway routes, as a build writes them from the gRPC descriptors.", Kind: List, Item: &methodField, Rule: "It may be empty. Which service a method goes to is decided by the rpc entry of `routes`."}, protoField, }}, {Name: "log", Doc: "Which requests the request log writes.", Kind: Map, Rule: "Without `log`, every request is logged.", Fields: []Field{ {Name: "status_from", Doc: "The lowest status that is always logged.", Kind: Int, Required: true, Min: 100, Max: 599}, {Name: "sample", Doc: "The share of the other requests that is logged.", Kind: Text, Required: true, Pattern: model.PercentPattern, Expect: "a whole percentage such as 1%"}, }}, tracingField, envoyField, reserved("nginx", "nginx"), reserved("haproxy", "HAProxy"), }, }
Proxyfile describes the file proxyfile reads: every key, its kind and its rule. The meaning rules that need more than one key, such as a route naming a declared service, belong to the reader.
var RateLimit = Field{Name: "rate_limit", Doc: "How many requests the route admits in a period; a request over the limit is answered 429 and never reaches the service.", Kind: Map, Fields: []Field{ {Name: "requests", Doc: "Requests admitted per period.", Kind: Int, Required: true, Min: 1, Max: largestUint32}, {Name: "per", Doc: "The period.", Kind: Text, Required: true, Pattern: model.TimePattern, Expect: "a time such as 1s or 1m", Rule: "At least `1s`."}, {Name: "burst", Doc: "Extra requests admitted above requests after a quiet spell; 0 when not written.", Kind: Int, Min: 0, Max: largestUint32, Rule: "`requests` and `burst` together at most 4294967295."}, {Name: "by", Doc: "client counts each client address on its own, all every client together; client when not written.", Kind: Enum, Values: []string{"client", "all"}, Rule: "The client's address is the one `client_address` names."}, }}
RateLimit is the rate_limit key of a route and of the rpc entry. It is exported because the reader quotes its Expect for a time the parser refuses, and cannot walk the routes' Either to reach it.
var Targets = []Target{envoyTarget, nginxTarget, haproxyTarget}
Targets are the proxies with a generator, in the order of the support table's columns, each declared in a file of its own. TestTargetDeclarations keeps each target's declarations complete, so a key added to the format cannot go undeclared, and keeps each refused form on a partial key with a test of the value.
var WrittenWithNoKey = []string{"the request's path normalised before a route is picked", "a dot segment with a ; parameter answered 400",
requestLine}
WrittenWithNoKey are the behaviours every configuration holds with no key for them, named in words. The support table lists them after the core keys, so each target declares how it writes them as it declares a key.
Functions ¶
func CoreKeys ¶ added in v2.2.0
CoreKeys returns the path of every key of class core under f, in Reference's order and spelling, so the support each generator declares and the support table name a key as the key reference does.
func FormRefusedMessage ¶ added in v2.2.0
FormRefusedMessage is the problem of a value of key, written in a file rendered for the target named target, that the target refuses in the form form: the key as the support table names it, the form, and what to write instead. A generator that finds such a value only as it writes it names it in the same words.
func LessStrictHeading ¶ added in v2.2.0
LessStrictHeading is the heading of the section of t's page that lists its less strict ways.
func LessStrictList ¶ added in v2.2.0
LessStrictList writes t's less strict ways as the Markdown list its page holds: each name in bold, then what was measured.
func LessStrictWarning ¶ added in v2.2.0
LessStrictWarning is what render prints after it has written t's files: in how many ways the output is less strict than the Envoy output, and where they are listed; "" when there are none.
func MatrixRows ¶ added in v2.2.0
func MatrixRows() []string
MatrixRows are the support table's rows: every core key of the proxyfile, in CoreKeys' order, then WrittenWithNoKey.
func NoGenerator ¶
NoGenerator says why a target is refused: proxyfile has no generator for that proxy yet.
func Reference ¶
Reference writes, as a Markdown table, the key f at path and every key under it, depth first in the description's order, so the documentation lists the keys, kinds and rules the checker reads. With path "", f is the root of a file, which has no row. A row gives the key's path, its Doc, its rule: Required when it is, what the description says the value must be, then the key's own Rule; and its class: the Class it names, else its holder's, and class for f, which is the class of the key that holds f. One description always gives the same bytes.
func Refusals ¶ added in v2.2.0
Refusals returns one problem for each key written in file whose path t declares Refused, at the key, sorted, so a render for t names every key it cannot carry instead of writing a weaker configuration. A Refuses entry of a key's declaration is checked at each key of that path, given the key's value and proxyfile, and names the form it refuses. It follows the description f as Check does, and reads a file Check accepted. f is the proxyfile's description, with file the proxyfile itself, or the origins file's or the methods file's, whose keys are named by the path the proxyfile writes them at (Field.Place); proxyfile is the proxyfile's tree in every case.
func RefusedMessage ¶ added in v2.2.0
RefusedMessage is the problem of key, written in a file rendered for t, which refuses it: the key as the support table names it, and what the proxy offers instead.
func Schema ¶
Schema writes spec as a JSON Schema (draft 2020-12), so an editor checks a file with the keys, kinds and patterns the checker uses. Every schema object is a Go map, which encoding/json writes with its keys sorted, and every list keeps the description's order, so one description always gives the same bytes.
func SupportMatrix ¶ added in v2.2.0
SupportMatrix writes, as a Markdown table, each target's declaration for every row: a column for each target, in the order given, and a line for each row, in the order given. A row in WrittenWithNoKey is written as its words, any other as a key. The rows are told apart by that list, never by a space in the name, because a core key such as services.<service name> holds one.
func WrittenKeys ¶ added in v2.2.0
WrittenKeys returns the path of every key written in root, a tree Check accepted against f, in CoreKeys' spelling, sorted, each once. The conformance battery runs a row on a file only when the file writes the row's keys.
Types ¶
type Field ¶
type Field struct {
Name string // the key; "" for the root, list items and dictionary values
Doc string // one sentence, the schema's description; on a Key, what a key means, which the schema has no place for
// Rule completes the key's row in the documentation's key tables (Reference) with what the other fields cannot
// say, such as a rule the reader checks across keys or a default of Envoy's. It is Markdown, and the schema
// leaves it out.
Rule string
Kind Kind
Required bool
Fields []Field // Map
OneOf []string // Map: exactly one of these keys
Item *Field // List items; Dict values
Key *Field // Dict: the keys the writer chooses (Name says what they are, Pattern and Expect their rule)
// AtLeastOneOf (Map) names keys of which one or more must be written, and Needs (Map) names, by key, the keys that
// must be written beside it. The schema writes them as anyOf and dependentRequired, so an editor refuses what the
// reader refuses. The checker does not read them, because the reader checks the same rules with messages of its
// own: for auth, in internal/read/decode.go (the decoder's auth method).
AtLeastOneOf []string
Needs map[string][]string
// Pattern (Text and Key) runs in two engines: Go's RE2 in the checker, and an editor's ECMAScript engine through
// the JSON Schema, which writes it unchanged. So it keeps to what both read alike. The package fails to load on a
// form Go refuses, such as a lookahead, an atomic group or a possessive repeat. Of the forms Go accepts,
// ECMAScript refuses a flag set for the rest of the pattern, such as (?i), and (?P<name>; it reads \A and \z as
// letters or refuses them; and \s, \S and a . outside brackets match other characters in it: write Go's \S out as
// [^\t\n\f\r ]. [\s\S], every character, is the same in both.
Pattern string
Expect string // Text, Key, Either: completes "must be ..."
Min, Max int64 // Int; Max 0 is no maximum. int64, not int, so a uint32 limit fits on a 32-bit build too
Values []string // Enum
Choices []Field // Either: a Text choice, and Map, Dict or List choices
Select string // a Map choice of an Either: chosen when the node has this key; the Map or Dict choice without Select is the default
// Moved names, by key, the keys of a Map that proxyfile 1.x read here and 2.0 reads at another place, with that place,
// so the check names it instead of calling the key unknown.
Moved map[string]string
// Reserved marks a proxy's own block (Map) that takes no key in this version: it is accepted empty, and every key
// written in it is refused with the check's message for a reserved block.
Reserved bool
// Class is the proxy whose generator alone reads the key and every key under it that names no class of its own:
// envoy, nginx or haproxy. A key that names none, held by none that does, is core: every proxy can carry it
// (docs/portability.md).
Class string
// Place is set in the origins file's and the methods file's descriptions where they write a key of the proxyfile at
// another path: on a key, the path the proxyfile writes that key at, and on a value no key holds, a file's root or
// a list's items, the path of the proxyfile's key whose value it is, which the keys under it continue. Both are
// spelled as CoreKeys spells them. Refusals reads it, so a key a target refuses is refused in whichever file
// writes it.
Place string
}
Field describes one key of a file format. The checker reads it, and `proxyfile schema` prints it as JSON Schema, so the keys an editor offers are the keys the program accepts.
type Kind ¶
type Kind int
Kind is what a key's value must be. Map has the keys its Fields name and Dict the keys its writer chooses; Either is whichever of its Choices fits the value.
type LessStrict ¶ added in v2.2.0
type LessStrict struct {
Row, Name, Measured string
}
LessStrict is a way a target's output is not stricter than the Envoy output: the proxy serves a request the Envoy output refuses or ends, or sends a service what the Envoy output would not. Row is the support table's row it belongs to, which the target declares Partial and whose cell names it after the note; Name is its short name, which that cell and the target's page give; Measured says the request and each proxy's answer, which the page gives after the name. Render counts them after it writes (LessStrictWarning), so a user who did not read the page still learns they exist.
type Refusal ¶ added in v2.2.0
type Refusal struct {
Form string // the refused form, in words that follow the key: "of 1 or more"
Instead string // what to write instead
// Applies says whether the key's value is of the refused form. It reads the other keys the form depends on in
// proxyfile, the proxyfile's tree with its includes merged, also when the key is written in an origins file, a
// methods file or .proto options, because those keys are the proxyfile's.
Applies func(value, proxyfile *tree.Node) bool
}
Refusal is one form of a key that a target refuses, by the key's value or for want of another key.
type Support ¶ added in v2.2.0
Support is a target's declaration for one row of the support table. Note is "" for Supported; for Partial it says the difference in one sentence, and for Refused what the proxy offers instead. The support table and the refusal both quote it. Refuses lists, on a Partial key only, the forms of it the target refuses while it carries the others, each with its Applies.
type Target ¶ added in v2.2.0
type Target struct {
Name, Title string
Keys map[string]Support
LessStrict []LessStrict
}
Target is a proxy with a generator: Name is the --target value, Title the support table's column heading, and Keys its declaration for each row of MatrixRows: a core key by its path as CoreKeys gives it, a behaviour written with no key by its words. LessStrict lists, in the order its page gives them, the ways its output is less strict than the Envoy output, which the Envoy output itself has none of.
func TargetNamed ¶ added in v2.2.0
TargetNamed returns the target whose Name is name. It reads Targets at each call, so a test may declare a target of its own.