Documentation
¶
Overview ¶
Package config loads emulator configuration with the precedence flags > env (GCPEMU_*) > gcpemu.yaml > defaults (FR-CORE-010).
Index ¶
- Constants
- Variables
- 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 Config
- func (c *Config) ApplyFlags(flags *Config, changed map[string]bool)
- func (c *Config) ConsoleEnabled() bool
- func (c *Config) InstanceDir() string
- 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
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).
Variables ¶
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).
var DefaultPorts = map[string]int{
"gateway": 4510,
"gcs": 4443,
"pubsub": 8085,
"ar": 5000,
"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"},
"gcs": {"iam"},
"ar": {"iam"},
"pubsub": {"iam"},
"secrets": {"iam"},
"dns": {"iam"},
"compute": {"iam"},
}
Dependencies of each service (FR-CORE-003).
RuntimeServices need a container runtime to do anything.
Functions ¶
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 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 ¶
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 except under CI=true (FR-CI-003).
func (*Config) InstanceDir ¶
InstanceDir returns the data dir: the explicit one, or one per instance.
func (*Config) ParsePortRange ¶
ParsePortRange parses PortRange ("LO-HI"); ok is false when it is empty.