envcontract

package
v1.5.16 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 6 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 envcontract checks an app's effective env against its declared contract. It reports key names, kinds and reasons only: no value is ever returned, logged or placed in an error.

Index

Constants

View Source
const (
	FormatNonEmpty = "nonempty"
	FormatURL      = "url"
	FormatPort     = "port"
	FormatInt      = "int"
	FormatBool     = "bool"
	FormatEnum     = "enum"
)

Shapes a rule's Format may name. enum takes a list: "enum:a,b,c".

View Source
const (
	ModeOff   = "off"
	ModeWarn  = "warn"
	ModeBlock = "block"
)

Gate modes, the values of the env.contract.mode setting.

View Source
const BlockedPrefix = "env contract not met, deploy stopped before any container changed: "

BlockedPrefix starts the message of a blocked deploy. The failure classifier keys on the matching phrase, so change both together.

Variables

This section is empty.

Functions

func Describe

func Describe(v []Violation) string

Describe is the one line shown for violations in a warn event.

func Summary

func Summary(v []Violation) string

Summary renders violations as one line of key names and reasons.

func ValidFormat

func ValidFormat(f string) error

ValidFormat reports whether f is a format Evaluate understands.

Types

type BlockedError

type BlockedError struct{ Violations []Violation }

BlockedError stops a deploy. It carries key names and reasons, never values.

func (*BlockedError) Error

func (e *BlockedError) Error() string

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

Entry is one effective env key as the oracle sees it. The value stays private so a caller of Evaluate cannot get it back out.

func OpaqueEntry

func OpaqueEntry(secret bool) Entry

OpaqueEntry describes a key whose value is resolved later (secret store, reference, vault): it counts as present and well formed.

func PlainEntry

func PlainEntry(value string) Entry

PlainEntry describes a literal value.

type Env

type Env map[string]Entry

Env maps each effective env key to its entry.

func FromParts

func FromParts(plain map[string]string, secretNames, otherOpaque []string) Env

FromParts builds an Env from plain values and names whose value is resolved elsewhere.

type Gate

type Gate struct {
	Rules  func(ctx context.Context, app string) ([]Rule, error)
	Base   func(ctx context.Context, app string) (Env, error)
	Mode   func(ctx context.Context) string
	Record func(ctx context.Context, app, attemptID string, v []Violation)
}

Gate runs the contract check for a deploy. Every dependency is a func so the gate stays free of the store and the settings service.

func (Gate) Check

func (g Gate) Check(ctx context.Context, app, attemptID string, overlay Env) error

Check merges overlay over the app's stored env and evaluates the contract. Only the block mode returns an error. A lookup failure fails closed in block mode and never blocks in warn mode.

type Kind

type Kind string

Kind names why a key violates the contract.

const (
	KindMissing               Kind = "missing"
	KindEmpty                 Kind = "empty"
	KindMalformed             Kind = "malformed"
	KindNotSecretButSensitive Kind = "not_secret_but_sensitive"
)

Violation kinds.

type LookupError

type LookupError struct{}

LookupError stops a block-mode deploy when the contract could not be read. It carries no cause text so a store error never reaches a deploy message.

func (*LookupError) Error

func (*LookupError) Error() string

type Rule

type Rule struct {
	Key      string `json:"key"`
	Required bool   `json:"required"`
	Format   string `json:"format"`
	Secret   bool   `json:"secret"`
}

Rule is one declared key.

type Violation

type Violation struct {
	Key    string `json:"key"`
	Kind   Kind   `json:"kind"`
	Reason string `json:"reason"`
}

Violation is one broken rule. Reason never contains a value.

func Evaluate

func Evaluate(rules []Rule, env Env) []Violation

Evaluate returns the violations of rules against env, sorted by key.

func PresenceOnly

func PresenceOnly(v []Violation) []Violation

PresenceOnly keeps the violations that say whether a key is set, dropping the ones that depend on what a value looks like.

Jump to

Keyboard shortcuts

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