Documentation
¶
Overview ¶
Package format holds the one description of each input file and checks a file's tree against it.
Index ¶
Constants ¶
const AgentExpect = "an IPv4 address and a port from 1 to 65535, such as 127.0.0.1:2000"
AgentExpect is exported because the reader's message for an agent its pattern admits but ParseAgent refuses must be the check's, and the reader's tooLarge cannot walk the provider's Either to read it from the description.
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 Methods = Field{ Doc: "The RPC methods the gateway routes, each with what the check is told about it.", Kind: List, Item: &methodField, }
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 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, Fields: slices.Concat([]Field{ {Name: "name", Doc: "The environment's name.", Kind: Text, Required: true, 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.
var Proxyfile = Field{ Doc: "A proxyfile: one gateway, the services behind it and the routes to them, from which proxyfile writes an Envoy configuration.", Kind: Map, Moved: map[string]string{"namespace": "envoy.namespace", "tracing": "envoy.tracing"}, 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: "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 a route has 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."), "Envoy's default is 1 hour."), }}, {Name: "services", Doc: "The services behind the gateway, on the same host, 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 and an optional address.", 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; 127.0.0.1 when not written.", Kind: Text, Pattern: `^[^\t\n\f\r ]+$`, Expect: "an IP address", Rule: "Not a name: Envoy looks up no name for a static cluster."}, })}}, {Name: "auth", Doc: "The external check every request goes through before it reaches a service.", Kind: Map, Rule: "Without `auth` there is no check.", Fields: []Field{ {Name: "ask", Doc: "The service and the path the gateway asks.", Kind: Text, Required: true, 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, Required: true, Pattern: model.TimePattern, Expect: "a time such as 2s", Rule: "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, Required: true}, {Name: "when_unavailable", Doc: "What happens to a request when the check cannot be asked: allow lets it through, deny refuses it.", Kind: Enum, Required: true, Values: []string{"allow", "deny"}}, {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."}, headers("send", "The request headers the check is sent; a name ending in * is a prefix."), headers("accept", "The headers of the check's answer that reach the service; a name ending in * is a prefix."), }}, 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."), {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 the check.", Kind: Enum, Values: []string{"off"}, Rule: "Needs an `auth` key."}, retries("How many times a request that never reached the service is tried again."), }}, }}}, {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%"}, }}, 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.
Functions ¶
func NoGenerator ¶
NoGenerator says why a target and a key of its block are 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 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.
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)
// 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 or Dict 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 the block of a proxy proxyfile has no generator for yet (Map): it is accepted empty, and every key
// written in it is refused with NoGenerator.
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
}
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.