config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 9 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).

Variables

View Source
var AllServices = []string{"iam", "compute", "dns", "certs", "ar", "pubsub", "secrets", "gcs", "sql", "gke", "lb", "cdn", "nat"}

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"},
	"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}

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.

Types

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"`
}

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

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

LRO returns the configured LRO latency for service (FR-CORE-023).

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

Jump to

Keyboard shortcuts

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