cfgfile

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cfgfile implements managed config files (plan §7.4): a SELECTIVE, single-pass renderer that fills ONLY Mooring's own `{{hm.<key>}}` delimiter and copies everything else — the app's `${…}`, `$VAR`, Go `{{ }}`, and even `{{hmFoo}}` (no dot) — byte-identical. It is a byte scanner, NOT a template engine (no conditionals/loops/functions/shell). Output is emitted, never re-scanned, so a resolved secret containing `{{hm.X}}` can't trigger a second pass. Every `{{hm.X}}` resolves only via the file's explicit bindings allowlist and fails closed (never empty string) on anything unknown.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownBinding means a well-formed {{hm.X}} had no binding (fail-closed).
	ErrUnknownBinding = errors.New("cfgfile: unknown binding")
	// ErrBadValue means a resolved value contained NUL or CR/LF.
	ErrBadValue = errors.New("cfgfile: resolved value contains NUL or newline")
)

Functions

func LiteralSecretLint

func LiteralSecretLint(body []byte) (string, bool)

LiteralSecretLint detects credential-shaped LITERALS in a config-file body that has NO secret: binding (plan §7.4): such material should be a {{hm.secret:KEY}} binding, not pasted in clear (which would also be written world-ish and stored unencrypted). Returns a reason + true on a hit.

func ParseSource

func ParseSource(source string) (kind, arg string, err error)

ParseSource splits a binding source into its kind and argument, validating the argument grammar per kind. It does NOT resolve anything.

func Render

func Render(template []byte, resolve Resolver) (out []byte, secretBearing bool, err error)

Render performs the selective substitution. It returns the rendered bytes and whether any secret-bearing binding was used. Any unknown binding, resolve error, or unsafe resolved value is a hard error (fail-closed).

func SecretBearing

func SecretBearing(bindings []Binding) bool

SecretBearing reports whether any binding draws from a secret source (so the rendered file must be stored encrypted and written 0600).

func ValidKey

func ValidKey(key string) bool

ValidKey reports whether key is a valid {{hm.<key>}} binding name.

func ValidateBindings

func ValidateBindings(bindings []Binding) error

ValidateBindings checks the binding set: valid keys, no duplicates, parseable sources. Returns the first violation.

Types

type Binding

type Binding struct {
	Key    string // the {{hm.<Key>}} placeholder name
	Source string // env:NAME | secret:NAME | cert:<binding>.<crt|key|ca> | app:<field>
}

Binding maps a template key ({{hm.<Key>}}) to a typed source (plan §7.4).

type Resolver

type Resolver func(key string) (value string, secret bool, err error)

Resolver returns a binding's value and whether it is secret-bearing.

Jump to

Keyboard shortcuts

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