config

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config loads emulator configuration with the precedence flags > env (GCPEMU_*) > gcpemu.yaml > defaults (FR-CORE-010).

Index

Constants

View Source
const (
	IAMOff     = "off"
	IAMAudit   = "audit"
	IAMEnforce = "enforce"
)

IAM enforcement modes (FR-IAM-004).

View Source
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).

View Source
const MinAdminTokenLen = 32

MinAdminTokenLen is the shortest AdminToken accepted.

Variables

View Source
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).

View Source
var DefaultPorts = map[string]int{
	"gateway":  4510,
	"gcs":      4443,
	"pubsub":   8085,
	"ar":       5000,
	"dns":      5353,
	"metadata": 8988,
}

Default service ports (Section 3.2).

View Source
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).

View Source
var RuntimeServices = map[string]bool{"sql": true, "gke": true, "nat": true, "build": true}

RuntimeServices need a container runtime to do anything.

Functions

func IsLoopback

func IsLoopback(bind string) bool

IsLoopback reports whether bind is a loopback address.

func ParseKV

func ParseKV(v string) (map[string]string, error)

ParseKV parses "a=1,b=2".

func ParsePorts

func ParsePorts(v string) (map[string]int, error)

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

func ResolveServices(sel []string) []string

ResolveServices expands the selection with dependencies and returns it in start order. An empty selection means every service.

func SplitList

func SplitList(v string) []string

SplitList splits a comma-separated list, trimming blanks.

func StateHome

func StateHome() string

StateHome returns the base directory for instance data dirs: $XDG_STATE_HOME/gcpemu when set, otherwise %LOCALAPPDATA%\gcpemu on Windows (ADR 0008) and ~/.local/state/gcpemu elsewhere.

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 balancer's forwarding
	// rule listeners also serve, 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"`
	// 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:"-"`
	// 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. CI=true switches on the CI defaults of FR-CI-003.

func (*Config) ApplyFlags

func (c *Config) ApplyFlags(flags *Config, changed map[string]bool)

ApplyFlags overlays the fields of flags whose Go field names are in changed.

func (*Config) ConsoleEnabled added in v0.2.0

func (c *Config) ConsoleEnabled() bool

ConsoleEnabled reports whether the Web console is served: as configured, otherwise on except under CI=true (FR-CI-003).

func (*Config) InstanceDir

func (c *Config) InstanceDir() string

InstanceDir returns the data dir: the explicit one, or one per instance.

func (*Config) LANBinds added in v0.10.0

func (c *Config) LANBinds() []LANBind

LANBinds lists the four --*-bind flags, set or not, in that order.

func (*Config) LRO

func (c *Config) LRO(service string) time.Duration

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) LoadEnv

func (c *Config) LoadEnv(getenv func(string) string) error

LoadEnv overlays GCPEMU_* environment variables onto c.

func (*Config) LoadFile

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

LoadFile overlays a YAML file onto c. A missing file is not an error.

func (*Config) ParsePortRange

func (c *Config) ParsePortRange() (lo, hi int, ok bool, err error)

ParsePortRange parses PortRange ("LO-HI"); ok is false when it is empty.

func (*Config) Port

func (c *Config) Port(name string) int

Port returns the configured port for name (0 means "pick a free port").

func (*Config) PortSet

func (c *Config) PortSet(name string) (int, bool)

PortSet returns the port configured for name, directly or through AllPorts, and whether one is.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration for consistency (NFR-SEC-001).

type LANBind added in v0.10.0

type LANBind struct {
	Flag  string
	Addrs []string
}

LANBind is one of the --lb-bind, --gke-bind, --ar-bind and --gfe-bind flags (Flag, without "--") and its addresses.

Jump to

Keyboard shortcuts

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