Documentation
¶
Overview ¶
Package cuetry parses, validates, and resolves CUE remote recipes for honey.
Index ¶
- Constants
- func EffectiveEnv(step RecipeStep, defaults *RecipeDefaults) (map[string]string, error)
- func EffectiveEnvForRun(step RecipeStep, defaults *RecipeDefaults, cliEnv map[string]string, ...) (map[string]string, error)
- func EffectiveRunAs(step RecipeStep, defaults *RecipeDefaults) string
- func ExpandStepHosts(host string, records []hosts.Record) ([]hosts.Record, error)
- func ParseEnvKeyValuePairs(pairs []string) (map[string]string, error)
- func ResolveHostFromRecords(host string, records []hosts.Record) (hosts.Record, error)
- func ResolveLocalAgainstRecipe(recipeDir, local string) (string, error)
- func ScriptRunAfterUpload(remotePath, runAs string, env map[string]string) (string, error)
- func ShellExportPrefixForRemote(env map[string]string, inner string) (string, error)
- func ValidateHostField(host string) error
- func ValidateRecipeEnvMap(m map[string]string) error
- func ValidateRemoteRecipe(cueBytes []byte) error
- func ValidateRunAsUser(user string) error
- func ValidateStepRunAsForKind(kind StepKind, step RecipeStep) error
- func WrapRemoteShell(runAs, innerCommand string) (string, error)
- type Recipe
- type RecipeDefaults
- type RecipeFileTransfer
- type RecipeStep
- type StepKind
Constants ¶
const MatchAllSearchHosts = "*"
MatchAllSearchHosts is a recipe step host value meaning: run this step on every host in the current search result set that has a PrimaryIP (same filter as parallel SSH in the UI).
const MatchHostRegexPrefix = "re:"
MatchHostRegexPrefix starts a host value interpreted as a Go regexp (RE2) matched against each search row's Name. Example: re:^prod-kafka-.+$ Use (?i) inside the pattern for case-insensitive matching.
Variables ¶
This section is empty.
Functions ¶
func EffectiveEnv ¶
func EffectiveEnv(step RecipeStep, defaults *RecipeDefaults) (map[string]string, error)
EffectiveEnv merges recipe.defaults.env with step.env (step wins on duplicate keys).
func EffectiveEnvForRun ¶
func EffectiveEnvForRun(step RecipeStep, defaults *RecipeDefaults, cliEnv map[string]string, r *hosts.Record) (map[string]string, error)
EffectiveEnvForRun merges recipe env (defaults then step) with cliEnv and adds host variables; cliEnv wins on duplicate keys.
func EffectiveRunAs ¶
func EffectiveRunAs(step RecipeStep, defaults *RecipeDefaults) string
EffectiveRunAs returns step-level run_as, else recipe defaults.run_as, else "".
func ExpandStepHosts ¶
ExpandStepHosts returns the host records one step should run against. If host is MatchAllSearchHosts, returns all records with a non-empty PrimaryIP (preserving search order). If host starts with MatchHostRegexPrefix, returns every record with PrimaryIP whose Name matches the regexp. Otherwise returns a single-element slice from ResolveHostFromRecords (literal IP or exact name match).
func ParseEnvKeyValuePairs ¶
ParseEnvKeyValuePairs parses repeated "KEY=value" strings (first '=' separates key from value). Empty entries are skipped. Later duplicates overwrite earlier ones.
func ResolveHostFromRecords ¶
ResolveHostFromRecords maps recipe "host" to a record with PrimaryIP. If host looks like an IP address, it returns a synthetic record (Name=host). Otherwise it matches Record.Name with case-insensitive equality; multiple matches are an error.
func ResolveLocalAgainstRecipe ¶
ResolveLocalAgainstRecipe returns an absolute local path: absolute paths are unchanged; relative paths are joined to recipeDir.
func ScriptRunAfterUpload ¶
ScriptRunAfterUpload builds the remote shell command to execute an uploaded file with POSIX sh (after SFTP). Optional run_as wraps the run like command steps. Optional env is applied as export assignments before `sh remotePath` (same as command steps). Scripts should be compatible with `sh` (or rely on a shebang if the kernel honors it when executed as argument to sh — use POSIX sh syntax for portability).
func ShellExportPrefixForRemote ¶
ShellExportPrefixForRemote prepends stable `export KEY='value'; ` assignments before inner (remote shell).
func ValidateHostField ¶
ValidateHostField checks host syntax (empty, regex compile). Call from ParseRemoteRecipe; ExpandStepHosts enforces match counts at runtime.
func ValidateRecipeEnvMap ¶
ValidateRecipeEnvMap checks every key/value pair for safe use in POSIX export assignments.
func ValidateRemoteRecipe ¶
ValidateRemoteRecipe checks that cueBytes is valid CUE and conforms to #Recipe.
func ValidateRunAsUser ¶
ValidateRunAsUser restricts remote account names to a safe POSIX-like subset to avoid shell metacharacters in sudo -u.
func ValidateStepRunAsForKind ¶
func ValidateStepRunAsForKind(kind StepKind, step RecipeStep) error
ValidateStepRunAsForKind rejects per-step run_as on put/get (SFTP only). Script steps allow run_as for the execute phase; defaults.run_as applies there too.
func WrapRemoteShell ¶
WrapRemoteShell runs the inner command as SSH login user; if runAs is set, wraps with: sudo -n -u '<runAs>' -- sh -lc '<inner>' (non-interactive sudo).
Types ¶
type Recipe ¶
type Recipe struct {
Name string `json:"name"`
Defaults *RecipeDefaults `json:"defaults,omitempty"`
Steps []RecipeStep `json:"steps"`
}
Recipe is the decoded "recipe" block from a CUE document.
type RecipeDefaults ¶
type RecipeDefaults struct {
RunAs string `json:"run_as,omitempty"`
Env map[string]string `json:"env,omitempty"`
K8sDebugImage string `json:"k8s_debug_image,omitempty"`
}
RecipeDefaults holds recipe-level defaults (optional fields).
type RecipeFileTransfer ¶
RecipeFileTransfer is a local ↔ remote path pair for SFTP put/get steps.
type RecipeStep ¶
type RecipeStep struct {
Host string `json:"host"`
Command string `json:"command,omitempty"`
Put *RecipeFileTransfer `json:"put,omitempty"`
Get *RecipeFileTransfer `json:"get,omitempty"`
Script *RecipeFileTransfer `json:"script,omitempty"`
RunAs string `json:"run_as,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
RecipeStep is one remote action: exactly one of Command, Put, Get, or Script. Host selects targets: literal IP, exact name, "*", or "re:…" (see resolve.go).
type StepKind ¶
type StepKind int
StepKind describes which action a recipe step performs.
StepKind values correspond to exactly one populated field on RecipeStep.
func ClassifyStep ¶
func ClassifyStep(s RecipeStep) (StepKind, error)
ClassifyStep returns the step kind after validating exactly one of command / put / get / script.