render

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidParameters = errors.New("invalid parameters")

ErrInvalidParameters is the sentinel returned by Validate.

View Source
var NameRe = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,38}[a-z0-9]$`)

NameRe is the DNS-label constraint for template ids and instance slugs.

Functions

func ApplyDefaults

func ApplyDefaults(m Meta, params map[string]any) map[string]any

ApplyDefaults returns a copy of params with any omitted parameter filled from its ParamDef.Default. Caller-supplied values always win. Parameters without a default are left absent (Validate enforces required ones).

func NormalizeParams

func NormalizeParams(m *Meta) error

NormalizeParams normalizes each parameter's Type (blank → "string") and returns an error for an unknown type (allowed: string|int|bool|select).

func RenderBody

func RenderBody(body string, params map[string]any) (string, error)

RenderBody substitutes params into an already-separated template body using text/template (with missingkey=error) and returns the final YAML. Callers that hold the full source (meta + body) split it with ParseMeta first; a store.Template keeps Meta and Body apart and renders the body directly.

func ValidName

func ValidName(s string) bool

ValidName reports whether s is a valid template id / name.

func Validate

func Validate(m Meta, params map[string]any, secrets map[string]string) error

Validate checks that params and secrets satisfy the template's contract:

  • All Required parameters are present.
  • No params outside the declared parameter set.
  • All PerInstance secrets are present.
  • No secrets outside PerInstance (PerHostReferenced are not in this map).

Returns a single error listing every problem found.

func ValidateAllowMissingSecrets

func ValidateAllowMissingSecrets(m Meta, params map[string]any, secrets map[string]string) error

ValidateAllowMissingSecrets is Validate without the "every PerInstance secret must be present" rule. It still rejects unknown secrets and enforces required parameters. The secret-rotation path uses this to re-apply a stored spec that legitimately lacks a PerInstance secret (one never set, or added to the template after deploy) without forcing the operator to re-supply it.

func ValidateIngress

func ValidateIngress(ing *Ingress) error

ValidateIngress checks an ingress declaration: container non-empty and port in 1..65535. nil is valid (no ingress).

Types

type Display

type Display struct {
	Name        string `yaml:"name,omitempty" json:"name,omitempty"`
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
	Category    string `yaml:"category,omitempty" json:"category,omitempty"`
	Icon        string `yaml:"icon,omitempty" json:"icon,omitempty"`
}

Display holds human-readable presentation metadata for a template.

type Ingress

type Ingress struct {
	Container string `yaml:"container" json:"container"`
	Port      int    `yaml:"port" json:"port"`
}

Ingress declares which container+port in the rendered pod serves HTTP, so the ingress layer can route a domain to it. Absent on non-web templates.

type Meta

type Meta struct {
	ID         string     `yaml:"id" json:"id"`
	Display    Display    `yaml:"display,omitempty" json:"display,omitempty"`
	Parameters []ParamDef `yaml:"parameters" json:"parameters,omitempty"`
	Secrets    Secrets    `yaml:"secrets" json:"secrets,omitempty"`
	Volumes    []Volume   `yaml:"volumes" json:"volumes,omitempty"`
	Ingress    *Ingress   `yaml:"ingress" json:"ingress,omitempty"`
}

Meta describes a template's parameter and secret contract. It is parsed from the leading "# template-meta:" comment block.

func ParseMeta

func ParseMeta(src string) (Meta, string, error)

ParseMeta extracts the template-meta block from the head of the file and returns the rest of the file as the renderable body.

The block must look like:

# template-meta:
#   id: postgres
#   parameters: ...

The parser stops at the first non-comment line. The body is everything from that point onward (with a leading "---" preserved if present).

type ParamDef

type ParamDef struct {
	Name        string   `yaml:"name" json:"name"`
	Type        string   `yaml:"type" json:"type"`
	Required    bool     `yaml:"required,omitempty" json:"required,omitempty"`
	Label       string   `yaml:"label,omitempty" json:"label,omitempty"`
	Description string   `yaml:"description,omitempty" json:"description,omitempty"`
	Default     any      `yaml:"default,omitempty" json:"default,omitempty"`
	Placeholder string   `yaml:"placeholder,omitempty" json:"placeholder,omitempty"`
	Options     []string `yaml:"options,omitempty" json:"options,omitempty"`
	Secret      bool     `yaml:"secret,omitempty" json:"secret,omitempty"`
}

ParamDef describes a single template parameter, its type, and constraints.

type Secrets

type Secrets struct {
	PerInstance       []string `yaml:"per_instance" json:"per_instance,omitempty"`
	PerHostReferenced []string `yaml:"per_host_referenced" json:"per_host_referenced,omitempty"`
}

type Volume

type Volume struct {
	Name   string `yaml:"name" json:"name"`
	Backup string `yaml:"backup,omitempty" json:"backup,omitempty"`
}

Jump to

Keyboard shortcuts

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