Documentation
¶
Overview ¶
Package eval evaluates a parsed Puppet manifest (ast.Program) into a catalog.Catalog. It implements Puppet scoping, expression semantics, conditionals, iteration, class/defined-type instantiation, resource declaration and relationship chaining, and a built-in function set. The type system is delegated to github.com/go-pcore/pcore, data binding to github.com/go-hiera/hiera, and facts to an injectable provider (backed by github.com/go-facter/facter by default).
A function/type registry seam (Evaluator.RegisterFunction) lets a host — notably go-ruby-puppet — contribute Ruby-defined custom functions.
Index ¶
- func EvalPlanString(src, plan string, params map[string]any, opts ...Option) (Value, []LogEntry, error)
- type Block
- type Context
- type ERBRenderer
- type Error
- type Evaluator
- type ExportedStore
- type FactsProvider
- type Function
- type LogEntry
- type MapFacts
- type MemoryExportedStore
- type Option
- func WithERBRenderer(r ERBRenderer) Option
- func WithExportedStore(store ExportedStore) Option
- func WithFacts(f FactsProvider) Option
- func WithHiera(h *hiera.Hiera) Option
- func WithNodeName(name string) Option
- func WithPlanExecutor(x PlanExecutor) Option
- func WithTemplateLoader(l TemplateLoader) Option
- type PlanExecutor
- type ResourceRef
- type Scope
- type Sensitive
- type TemplateLoader
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block is a Puppet lambda captured with its defining scope, invocable by a Function during iteration.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is handed to every Function. It exposes the evaluator services a function needs without widening the public surface.
type ERBRenderer ¶
ERBRenderer renders an ERB template (the legacy Ruby-based template format used by template()/inline_template()). ERB templates may contain arbitrary Ruby, which a pure-Go evaluator cannot execute; a host that embeds a Ruby runtime (e.g. go-ruby-puppet/rbgo, which can reuse github.com/go-ruby-erb to compile the template to Ruby and then run it) wires an implementation via WithERBRenderer.
src is the raw template text. vars is the set of top-scope variables and facts the template may reference (as @instance variables / scope lookups in Ruby ERB). The result is the rendered string.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator holds the state of one compilation.
func (*Evaluator) EvalPlan ¶
EvalPlan runs a previously-parsed `plan` by name with the given parameters and returns its result value. Definitions must have been registered first (via EvalProgram or by parsing a program that contains the plan). It is the entry point a Bolt host uses to run a `.pp` plan.
func (*Evaluator) EvalProgram ¶
EvalProgram evaluates a whole program: definitions are registered first (hoisted) so forward references resolve, then top-level statements run in order.
func (*Evaluator) RegisterFunction ¶
RegisterFunction adds or replaces a named function. This is the seam a host (e.g. go-ruby-puppet) uses to contribute custom functions.
type ExportedStore ¶
type ExportedStore interface {
StoreExported(node string, r *catalog.Resource) error
CollectExported(capType, excludeNode string) ([]*catalog.Resource, error)
}
ExportedStore is the storeback seam for exported resources (`@@`). A host wires a real backend (e.g. PuppetDB via github.com/go-puppetdb/puppetdb) so that resources exported by one node's compilation can be collected by another node with `Type <<| query |>>`.
StoreExported is called for every `@@` resource declared during compilation. CollectExported returns the exported resources of the given capitalized type (e.g. "Sshkey"), excluding those exported by excludeNode (a node never collects its own exports). Query filtering is applied by the evaluator, so an implementation may return a superset.
type FactsProvider ¶
FactsProvider supplies top-scope facts. A bare fact name ("os") or a dotted path ("os.family") resolves through Fact; Facts returns the whole tree for `$facts`.
func FacterFacts ¶
func FacterFacts() FactsProvider
FacterFacts returns a FactsProvider backed by go-facter's live host inventory. Pass it via WithFacts.
type Function ¶
Function is a callable contributed to the evaluator. args are the already evaluated positional arguments; block is the optional trailing lambda (nil when absent).
type MapFacts ¶
MapFacts is a deterministic FactsProvider backed by a nested map. A dotted fact name digs through nested map[string]any / []any values, so {"os": {"family": "Debian"}} resolves "os.family".
type MemoryExportedStore ¶
type MemoryExportedStore struct {
// contains filtered or unexported fields
}
MemoryExportedStore is an in-memory ExportedStore. It is safe for concurrent use and is the default backend used in tests and single-process runs.
func NewMemoryExportedStore ¶
func NewMemoryExportedStore() *MemoryExportedStore
NewMemoryExportedStore returns an empty in-memory exported-resource store.
func (*MemoryExportedStore) CollectExported ¶
func (m *MemoryExportedStore) CollectExported(capType, excludeNode string) ([]*catalog.Resource, error)
CollectExported returns the exported resources of capType not exported by excludeNode.
func (*MemoryExportedStore) StoreExported ¶
func (m *MemoryExportedStore) StoreExported(node string, r *catalog.Resource) error
StoreExported records r as exported by node.
type Option ¶
type Option func(*Evaluator)
Option configures a new Evaluator.
func WithERBRenderer ¶
func WithERBRenderer(r ERBRenderer) Option
WithERBRenderer wires an ERB renderer for template()/inline_template().
func WithExportedStore ¶
func WithExportedStore(store ExportedStore) Option
WithExportedStore wires a backing store for exported resources (`@@`), so they can be collected on other nodes with `<<| |>>`. Without one, exported resources are only collectable within the same compilation.
func WithFacts ¶
func WithFacts(f FactsProvider) Option
WithFacts sets the facts provider (default: none — `$facts` is undef).
func WithNodeName ¶
WithNodeName sets the compiling node's name (default "default").
func WithPlanExecutor ¶
func WithPlanExecutor(x PlanExecutor) Option
WithPlanExecutor wires a PlanExecutor for the plan functions.
func WithTemplateLoader ¶
func WithTemplateLoader(l TemplateLoader) Option
WithTemplateLoader wires a template loader for epp()/template().
type PlanExecutor ¶
type PlanExecutor interface {
RunTask(task string, targets []string, params map[string]any) (Value, error)
RunCommand(command string, targets []string) (Value, error)
RunScript(script string, targets []string, args []any) (Value, error)
GetTargets(spec Value) (Value, error)
ApplyCatalog(targets []string, cat *catalog.Catalog) (Value, error)
}
PlanExecutor is the orchestration seam a Bolt-like host (notably github.com/go-puppet-bolt/bolt) wires so that a `plan` written in the Puppet language can run tasks/commands/scripts and apply catalogs against targets.
Values use the evaluator's generic model (strings, []any, map[string]any) so the interface has no dependency on a specific transport package. Targets are passed as their string specs; an executor resolves them through its own inventory. The returned Value becomes the plan function's result (typically a ResultSet rendered as an Array of per-target result Hashes).
type ResourceRef ¶
ResourceRef is a Puppet resource reference value, e.g. `File['/tmp/x']`.
func (*ResourceRef) String ¶
func (r *ResourceRef) String() string
String renders the canonical `Type[Title]` form.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope is a Puppet variable scope: a set of `$name => value` bindings with a lexical parent chain up to the top scope. Puppet variables are immutable once set within a scope.
type Sensitive ¶
type Sensitive struct {
// contains filtered or unexported fields
}
Sensitive is the value-model wrapper for Puppet's Sensitive data type. It carries an arbitrary value while redacting it in every rendered form (to_s, inspect, interpolation) so secrets do not leak into logs or catalogs. The wrapped value is retrievable only through Sensitive.Unwrap (or the `unwrap` function). It is used by resource-api sensitive-parameter handling and by stdlib::rewrap_sensitive_data.
func NewSensitive ¶
NewSensitive wraps v as a Sensitive value. Wrapping mirrors Puppet's Sensitive.new: any value (including an already-Sensitive one) may be wrapped.
type TemplateLoader ¶
TemplateLoader resolves an EPP/ERB template reference (e.g. "apache/vhost.epp") to its raw source text. Wire one via WithTemplateLoader so epp()/template() can load files. Without a loader, only the inline_* forms work.
type Value ¶
type Value = any
Value is a Puppet value. It uses the same representation as github.com/go-pcore/pcore: bool, int64, float64 and string for scalars, []any for arrays, map[string]any for hashes, pcore.Undef for undef, the pcore wrapper types for the rich values, and pcore.Type for data types.
Source Files
¶
- builtins.go
- call.go
- decl.go
- epp.go
- eval.go
- exported.go
- expr.go
- facts.go
- iterate.go
- plan.go
- resources.go
- scope.go
- sensitive.go
- stdlib.go
- stdlib_array.go
- stdlib_augeas.go
- stdlib_catalog.go
- stdlib_crypt.go
- stdlib_data.go
- stdlib_digest.go
- stdlib_encode.go
- stdlib_extra.go
- stdlib_hash.go
- stdlib_hocon.go
- stdlib_number.go
- stdlib_password.go
- stdlib_path.go
- stdlib_pson.go
- stdlib_random.go
- stdlib_resources.go
- stdlib_scanf.go
- stdlib_serialize.go
- stdlib_shellwords.go
- stdlib_string.go
- stdlib_time.go
- stdlib_toml.go
- stdlib_type.go
- stdlib_validate2.go
- template.go
- value.go