Documentation
¶
Overview ¶
Package config loads emulator configuration with the precedence flags > env (GCPEMU_*) > gcpemu.yaml > defaults (FR-CORE-010).
Index ¶
- Constants
- Variables
- func IsAPIName(s string) bool
- func IsLoopback(bind string) bool
- func ParseKV(v string) (map[string]string, error)
- func ParsePorts(v string) (map[string]int, error)
- func ResolveServices(sel []string) []string
- func SplitList(v string) []string
- func StateHome() string
- type BuildConfig
- type Config
- func (c *Config) ApplyFlags(flags *Config, changed map[string]bool)
- func (c *Config) ConsoleEnabled() bool
- func (c *Config) InstanceDir() string
- func (c *Config) LANBinds() []LANBind
- func (c *Config) LRO(service string) time.Duration
- func (c *Config) LoadEnv(getenv func(string) string) error
- func (c *Config) LoadFile(path string) error
- func (c *Config) ParsePortRange() (lo, hi int, ok bool, err error)
- func (c *Config) Port(name string) int
- func (c *Config) PortSet(name string) (int, bool)
- func (c *Config) Validate() error
- type LANBind
Constants ¶
const ( IAMOff = "off" IAMAudit = "audit" IAMEnforce = "enforce" )
IAM enforcement modes (FR-IAM-004).
const AllPorts = "*"
AllPorts is the Ports key that applies to every listener without its own entry: `--port 0` makes them all pick free ports (FR-CORE-042).
const Managed = "managed"
Managed is the --external value that has the Instance run the External emulator itself, as a Managed emulator (ADR 0029).
const MinAdminTokenLen = 32
MinAdminTokenLen is the shortest AdminToken accepted.
Variables ¶
var AllServices = []string{"iam", "compute", "dns", "certs", "ar", "pubsub", "secrets", "gcs", "sql", "gke", "lb", "cdn", "nat", "build"}
AllServices lists every service name in start order (also the seed order: a peer a service depends on at seed time must come first).
var DefaultPorts = map[string]int{
"gateway": 4562,
"gcs": 4443,
"pubsub": 8085,
"ar": 4561,
"dns": 5353,
"metadata": 8988,
}
Default service ports (Section 3.2).
var Dependencies = map[string][]string{
"gke": {"iam", "compute", "ar", "dns"},
"sql": {"iam", "compute"},
"lb": {"iam", "compute", "certs", "dns", "gcs"},
"certs": {"iam", "dns"},
"cdn": {"lb", "compute"},
"nat": {"compute"},
"build": {"iam", "gcs", "ar", "pubsub", "secrets"},
"gcs": {"iam"},
"ar": {"iam"},
"pubsub": {"iam"},
"secrets": {"iam"},
"dns": {"iam"},
"compute": {"iam"},
}
Dependencies of each service (FR-CORE-003).
var ManagedAPIs = []string{"bigtable", "datastore", "firestore", "spanner"}
ManagedAPIs are the APIs whose External emulator can be Managed: those Google ships an emulator for, less Pub/Sub, which has its own Service.
var RuntimeServices = map[string]bool{"sql": true, "gke": true, "nat": true, "build": true}
RuntimeServices need a container runtime to do anything.
Functions ¶
func IsAPIName ¶ added in v0.12.0
IsAPIName reports whether s has the form of a GCP API name, the first label of its API.googleapis.com host (firestore, bigtableadmin).
func IsLoopback ¶
IsLoopback reports whether bind is a loopback address.
func ParsePorts ¶
ParsePorts parses port settings: comma-separated name=port pairs, and a bare port (only 0 is valid) that applies to every listener (AllPorts).
func ResolveServices ¶
ResolveServices expands the selection with dependencies and returns it in start order. An empty selection means every service.
Types ¶
type BuildConfig ¶ added in v0.9.0
type BuildConfig struct {
// Concurrency caps how many Builds are WORKING at once; further
// Builds wait QUEUED (build.concurrency, default 4).
Concurrency int `yaml:"concurrency" env:"CONCURRENCY"`
}
BuildConfig configures Cloud Build.
type Config ¶
type Config struct {
Instance string `yaml:"instance" env:"INSTANCE"`
DataDir string `yaml:"dataDir" env:"DATA_DIR"`
Ephemeral bool `yaml:"ephemeral" env:"EPHEMERAL"`
Services []string `yaml:"services" env:"SERVICES"`
Bind string `yaml:"bind" env:"BIND"`
Insecure bool `yaml:"iUnderstandThisIsInsecure" env:"I_UNDERSTAND_THIS_IS_INSECURE"`
Ports map[string]int `yaml:"ports" env:"PORTS"`
PortRange string `yaml:"portRange" env:"PORT_RANGE"`
IAMMode string `yaml:"iamMode" env:"IAM_MODE"`
DefaultPrincipal string `yaml:"defaultPrincipal" env:"DEFAULT_PRINCIPAL"`
LogFormat string `yaml:"logFormat" env:"LOG_FORMAT"`
LogLevel string `yaml:"logLevel" env:"LOG_LEVEL"`
LROLatency map[string]string `yaml:"lroLatency" env:"LRO_LATENCY"`
Deterministic bool `yaml:"deterministic" env:"DETERMINISTIC"`
StrictProjects bool `yaml:"strictProjects" env:"STRICT_PROJECTS"`
Projects []string `yaml:"projects" env:"PROJECTS"`
Seed string `yaml:"seed" env:"SEED"`
WaitTimeout time.Duration `yaml:"waitTimeout" env:"WAIT_TIMEOUT"`
DNSNoForward bool `yaml:"dnsNoForward" env:"DNS_NO_FORWARD"`
Offline bool `yaml:"offline" env:"OFFLINE"`
// NATReject makes Cloud NAT egress enforcement reject disallowed
// connections immediately (TCP reset / ICMP unreachable) instead of
// silently dropping them like GCP (FR-NAT-002), for fast tests.
NATReject bool `yaml:"natReject" env:"NAT_REJECT"`
// NATSinkResponse is the response the --offline NAT sink returns to
// HTTP requests (FR-NAT-005): "STATUS" or "STATUS:BODY"; default
// "503:gcpemu offline: egress blocked".
NATSinkResponse string `yaml:"natSinkResponse" env:"NAT_SINK_RESPONSE"`
// DefaultProject is the project ID the metadata server reports
// (FR-IAM-008); empty means "gcpemu-project".
DefaultProject string `yaml:"defaultProject" env:"DEFAULT_PROJECT"`
// MetadataServiceAccount is the metadata server's default service
// account email; empty means the project's default compute SA.
MetadataServiceAccount string `yaml:"metadataServiceAccount" env:"METADATA_SERVICE_ACCOUNT"`
// HostMode serves real Google hostnames to host processes through a
// frontend container and its DNS (FR-CORE-043, internal/hostmode).
HostMode bool `yaml:"hostMode" env:"HOST_MODE"`
// CDNCacheSize is the Cloud CDN cache size limit (FR-CDN-008), e.g.
// "1GiB", "512MiB" or a byte count; empty means 1 GiB.
CDNCacheSize string `yaml:"cdnCacheSize" env:"CDN_CACHE_SIZE"`
// Console serves the Web console under /console on the gateway
// (FR-UI-002); nil means the default of ConsoleEnabled.
Console *bool `yaml:"console" env:"CONSOLE"`
// LBBind lists extra addresses on which the load balancing Data plane,
// forwarding rules and GKE LoadBalancer Services, also serves, on
// their real ports, alongside loopback. Nothing else is exposed there,
// so it needs no Insecure.
LBBind []string `yaml:"lbBind" env:"LB_BIND"`
// GKEBind lists extra addresses on which every GKE cluster's
// Kubernetes API is also served, and which its serving certificate
// covers. The API server then accepts only real credentials.
GKEBind []string `yaml:"gkeBind" env:"GKE_BIND"`
// ARBind lists extra addresses on which the Artifact Registry registry
// is also served, over TLS from the instance CA and only to
// authenticated callers, whatever the IAM enforcement level.
ARBind []string `yaml:"arBind" env:"AR_BIND"`
// GFEBind lists extra addresses on which the Google front end also
// serves real Google hostnames, on port 443 over TLS from the instance
// CA and only to authenticated callers, whatever the IAM enforcement
// level (ADR 0021).
GFEBind []string `yaml:"gfeBind" env:"GFE_BIND"`
// SQLBind lists extra addresses on which every Cloud SQL instance with
// a public IP is also served: Postgres on a port of its own, and the
// connectors' port 3307, routed by TLS server name. Callers arriving
// through the LAN are told the address (ADR 0011, ADR 0027).
SQLBind []string `yaml:"sqlBind" env:"SQL_BIND"`
// LinkBind lists addresses on which the Instance serves the link
// protocol to Linked Instances, over mutual TLS and only to Instances
// it paired with, except for Pairing requests (ADR 0027).
LinkBind []string `yaml:"linkBind" env:"LINK_BIND"`
// LinkDiscover lists link addresses (host, or host:port) that `gcpemu
// link discover` asks besides browsing mDNS, for container networks and
// CI, where multicast usually doesn't cross bridges (ADR 0027).
LinkDiscover []string `yaml:"linkDiscover" env:"LINK_DISCOVER"`
// LinkMDNSPort is the port Instances advertise and browse on over mDNS;
// zero means 5353. Instances on another port find only each other, as
// tests' do. There is no flag.
LinkMDNSPort int `yaml:"linkMdnsPort" env:"LINK_MDNS_PORT"`
// External maps the API name of each Delegated API, one no Service
// serves (e.g. "firestore"), to the host:port of the External emulator
// the API gateway forwards it to (ADR 0027), or to Managed, for an API
// in ManagedAPIs, to have the Instance run it (ADR 0029).
External map[string]string `yaml:"external" env:"EXTERNAL"`
// AdminToken is the Admin token used when the API gateway is bound
// beyond loopback (FR-UI-009); empty means a random one per start.
// There is no flag, so that it never shows in a process listing.
AdminToken string `yaml:"adminToken" env:"ADMIN_TOKEN"`
// VMRuntime says whether a Containerized Instance runs on a VM runtime,
// whose host reaches LoadBalancer Services only through the Instance's
// published ports (ADR 0012): "auto" guesses from the runtime's info,
// "true" and "false" override the guess.
VMRuntime string `yaml:"vmRuntime" env:"VM_RUNTIME"`
// LoopbackAliases says whether a Containerized Instance on a VM runtime
// publishes Cloud SQL instances on 127.0.0.2-127.0.0.254, which it
// can't see on the host (ADR 0012): "auto" says yes on Docker Desktop
// only, "true" and "false" override it.
LoopbackAliases string `yaml:"loopbackAliases" env:"LOOPBACK_ALIASES"`
// Containerized says whether the Instance is a Containerized Instance
// when the container runtime can't tell (#502): "auto" goes by the
// container marker files, "true" and "false" override them. The
// runtime's answer, when there is one, wins.
Containerized string `yaml:"containerized" env:"CONTAINERIZED"`
// NoSQLHostClients stops Cloud SQL serving host clients on a loopback
// address on a VM runtime (ADR 0005), so that tests which never dial
// an instance's reported address don't contend for 127.0.0.1 (#316).
// Only emutest sets it: it has no flag, env var or config key.
NoSQLHostClients bool `yaml:"-" env:"-"`
// NoRegistryRelay stops an Instance on a VM runtime starting the
// Registry relay (ADR 0043) and, with it, connecting to the runtime
// as it starts, so that tests which push from the host start no
// containers. Only emutest sets it: it has no flag, env var or config
// key.
NoRegistryRelay bool `yaml:"-" env:"-"`
// Build configures Cloud Build: the build: section of gcpemu.yaml and
// the GCPEMU_BUILD_* variables.
Build BuildConfig `yaml:"build" env:"BUILD"`
}
Config is the full emulator configuration. Field `env` tags name the GCPEMU_* variable; `yaml` tags name the gcpemu.yaml key.
func Defaults ¶
func Defaults() Config
Defaults returns the default configuration. It never reads the environment: the CI defaults of FR-CI-003 are the CLI's (ADR 0039).
func (*Config) ApplyFlags ¶
ApplyFlags overlays the fields of flags whose Go field names are in changed.
func (*Config) ConsoleEnabled ¶ added in v0.2.0
ConsoleEnabled reports whether the Web console is served: as configured, otherwise on. The CLI turns it off under CI=true (FR-CI-003, ADR 0039).
func (*Config) InstanceDir ¶
InstanceDir returns the data dir: the explicit one, or one per instance.
func (*Config) LANBinds ¶ added in v0.10.0
LANBinds lists the six --*-bind flags, set or not, in that order.
func (*Config) LRO ¶
LRO returns the configured LRO latency for the Service ID service (FR-CORE-023): its own key, else its API name alias, else "*".
func (*Config) LoadFile ¶
LoadFile overlays the keys a YAML file names onto c, zero values included, so "ephemeral: false" beats a default of true. A missing file is not an error.
func (*Config) ParsePortRange ¶
ParsePortRange parses PortRange ("LO-HI"); ok is false when it is empty.