infrastructure

package
v2.44.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package infrastructure reads the infrastructure contract that the platform mounts into a service: the infrastructure config file and the directories its secrets are mounted at.

DefaultConfig reads the contract once per process from DefaultPaths and returns the cached result on every later call, including a failed read.

Load reads the contract on every call from the given Paths. Use it when the process must observe a contract change without a restart, for example a database registered after startup:

cfg, err := infrastructure.Load(ctx, infrastructure.DefaultPaths())
if err != nil {
	return err
}
db, err := postgres.New(ctx, postgres.WithInfraConfig(cfg))

or when the contract is kept elsewhere, as tools and tests do:

cfg, err := infrastructure.Load(ctx, infrastructure.Paths{
	ConfigPath:    filepath.Join(dir, "infrastructure.yaml"),
	SecretsDir:    filepath.Join(dir, "secrets"),
	TLSSecretsDir: filepath.Join(dir, "tls"),
})

WithStrictMode rejects fields the schema does not define, for tools and CI that validate a hand-written contract:

cfg, err := infrastructure.Load(ctx, paths, infrastructure.WithStrictMode())

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConfigured = errors.New("not configured")

ErrNotConfigured is returned by concrete infrastructure dependencies (e.g. the postgres package) when no configuration exists for them in the infrastructure config. This can happen when the infrastructure dependency is explicitly marked as optional in the Fairway manifest.

Functions

This section is empty.

Types

type Config

type Config struct {
	*infrapb.Config

	// Secrets resolves credentials by "<kind>/<key>" keys, for example
	// "postgresql/password".
	Secrets secret.Provider

	// TLSSecrets resolves TLS material by "<kind>/<file>" keys, for example
	// "redis/ca.crt".
	TLSSecrets secret.Provider
}

Config holds the infrastructure config and its secret providers. A nil provider is absent; a nil *secret.FileProvider stored in a field is a provider that reports every key as not found.

func DefaultConfig

func DefaultConfig() (*Config, error)

DefaultConfig returns the infrastructure config read from DefaultPaths. The config is read on the first call; subsequent calls return the cached result, including a failed read. Use Load to read the contract again.

func Load added in v2.43.0

func Load(ctx context.Context, paths Paths, opts ...Option) (*Config, error)

Load reads the infrastructure config and secrets from paths. The config is not cached: every call reads the file again, so a caller observes changes made after the process started. The returned Config owns no resources and needs no shutdown; its secret providers read a file on each Get.

type Option added in v2.43.0

type Option func(*loadOptions)

Option configures Load.

func WithStrictMode added in v2.43.0

func WithStrictMode() Option

WithStrictMode rejects a config file with fields the schema does not define, for tools and CI that validate a hand-written contract. A service must not use it: a contract written for a newer schema would fail to load.

type Paths added in v2.43.0

type Paths struct {
	ConfigPath string

	SecretsDir string

	TLSSecretsDir string
}

Paths locates the infrastructure contract on the filesystem. Every field is required; DefaultPaths returns the paths the platform mounts the contract at.

func DefaultPaths added in v2.43.0

func DefaultPaths() Paths

DefaultPaths returns the paths the platform mounts the contract at.

Jump to

Keyboard shortcuts

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