envrules

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: 4 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 envrules holds the one set of rules for env keys and values. Every writer (API, CLI pre-check, import, templates, clone) calls it so a key is accepted or refused the same way on every surface.

Index

Constants

View Source
const (
	KeyModeStrict = "strict"
	KeyModeLegacy = "legacy"
	ModeRefuse    = "refuse"
	ModeWarn      = "warn"
	ModeOff       = "off"
)

Key policy and refuse-or-warn modes, matching the runtime setting values.

View Source
const PreviousSuffix = "_PREVIOUS"

PreviousSuffix mirrors the secret grace key suffix owned by secret rotation.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code string

Code names why a key or value was flagged. UI and CLI map codes to text.

const (
	CodeEmptyKey      Code = "empty_key"
	CodeEquals        Code = "equals"
	CodeCharset       Code = "charset"
	CodeLength        Code = "length"
	CodeReserved      Code = "reserved"
	CodePrevious      Code = "previous_suffix"
	CodeDangerous     Code = "dangerous"
	CodeDuplicate     Code = "duplicate"
	CodeNUL           Code = "nul"
	CodeValueSize     Code = "value_size"
	CodeCRLF          Code = "crlf"
	CodeMultiline     Code = "multiline"
	CodeWhitespace    Code = "whitespace"
	CodeInterpolation Code = "interpolation"
	CodeEmptyValue    Code = "empty_value"
	CodeLegacyKey     Code = "legacy_key"
	CodeSecretOnly    Code = "secret_only"
)

Codes returned in Issue.Code.

type Existing

type Existing struct {
	Plain map[string]string `json:"plain"`
	Names []string          `json:"names"`
}

Existing is what the app already holds. Plain maps key to current value so an unchanged key is skipped; Names adds keys with no readable value (secrets).

type Issue

type Issue struct {
	Key     string `json:"key"`
	Code    Code   `json:"code"`
	Message string `json:"message"`
}

Issue is one finding for one key. Values never appear in it.

type Options

type Options struct {
	// Secret applies the rules for secret keys (the _PREVIOUS grace suffix is reserved).
	Secret bool `json:"secret"`
	// Multiline marks a path that carries values byte for byte (JSON bodies),
	// so a trailing CR is a real value and not a CRLF line-ending leak.
	Multiline bool `json:"multiline"`
	// ExistingUnknown is set by clients that cannot see the stored keys; the
	// server decides about legacy keys.
	ExistingUnknown bool `json:"existing_unknown"`
}

Options describe one write.

type Policy

type Policy struct {
	KeyMode          string   `json:"key_mode"`
	KeyMaxLen        int      `json:"key_max_len"`
	ValueMaxBytes    int      `json:"value_max_bytes"`
	ReservedPrefixes []string `json:"reserved_prefixes"`
	LoaderMode       string   `json:"loader_mode"`
	PathMode         string   `json:"path_mode"`
}

Policy carries the runtime-setting driven limits.

func DefaultPolicy

func DefaultPolicy() Policy

DefaultPolicy matches the seeded runtime-setting defaults.

type Rejection

type Rejection struct {
	Key    string `json:"key"`
	Code   Code   `json:"code"`
	Reason string `json:"reason"`
}

Rejection is one key the writer refused, with the reason. Values never appear.

type Report

type Report struct {
	Accepted []string    `json:"accepted"`
	Rejected []Rejection `json:"rejected"`
	Warnings []Issue     `json:"warnings"`
}

Report is the per-key outcome of a bulk write such as a dotenv import.

func BuildReport

func BuildReport(set map[string]string, res Result) Report

BuildReport splits the keys of set into accepted and rejected using a Validate result.

type Result

type Result struct {
	Errors   []Issue `json:"errors"`
	Warnings []Issue `json:"warnings"`
}

Result separates refusals from warnings.

func Validate

func Validate(set map[string]string, ex Existing, p Policy, o Options) Result

Validate checks every key and value in set. Keys already stored with the same value are skipped, so an old legacy entry never blocks an unrelated save.

func ValidateKeys

func ValidateKeys(keys []string) Result

ValidateKeys checks keys that carry no value (unset, delete, convert): only the shape rules that make a name unusable, so an old odd key can still be removed.

func (Result) Err

func (r Result) Err() string

Err returns the first refusal as one sentence, or "".

Directories

Path Synopsis
Package contract runs the shared envrules fixture through any writer's validation function, so every writer proves the same accept and reject result.
Package contract runs the shared envrules fixture through any writer's validation function, so every writer proves the same accept and reject result.

Jump to

Keyboard shortcuts

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