Documentation
¶
Overview ¶
Package hiera is a pure-Go (no cgo) adapter that presents the Ruby Hiera API surface over the hierarchical data-lookup engine github.com/go-hiera/hiera.
The go-hiera engine already implements everything that is Hiera semantics: parsing hiera.yaml, walking the configured hierarchy, the four merge behaviours (first / unique / hash / deep), per-key lookup_options, dotted-key digging into structured data and the full %{...} interpolation grammar. This package does not reimplement any of that; it wraps the engine and adds the thin, Ruby-facing conveniences the engine deliberately omits so that a consumer such as go-embedded-ruby (rbgo) can expose a Ruby "Hiera" class:
- a ResolutionType enum mirroring Ruby's resolution_type / Puppet's lookup merge behaviours (:priority, :array, :hash, :deep), mapped onto the engine's MergeStrategy;
- a Hiera value that binds one engine to one scope, constructed either from a hiera.yaml on disk (New) or from inline configuration bytes (NewFromConfig);
- a LookupOptions struct carrying the Ruby lookup() knobs (merge override, default value, per-key default hash);
- NewFactScope, which builds a Scope from Puppet-style fact namespaces, placing facts both at top level (legacy %{osfamily}) and under a "facts" key (%{facts.os.family}), plus trusted data under "trusted".
The package has no dependency on any Ruby runtime: the surface is Go-typed, and a Ruby binding layer marshals Ruby values onto these Go types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hiera ¶
type Hiera struct {
// contains filtered or unexported fields
}
Hiera is the Ruby Hiera class surface: one configured go-hiera engine bound to one scope.
func New ¶
New loads the hiera.yaml at configPath and returns a Hiera resolving interpolation against scope. The configuration's directory is the base for relative datadirs. It returns an error if the file cannot be read or parsed.
func NewFromConfig ¶
NewFromConfig builds a Hiera from inline hiera.yaml bytes, using baseDir as the base directory for relative datadirs, resolving interpolation against scope. It returns an error if the bytes cannot be parsed.
func (*Hiera) Lookup ¶
Lookup resolves key and returns its value, whether it was found, and any error. key may be dotted (e.g. "profile.ntp.servers.0") to dig into structured data after the root key is looked up and merged.
func (*Hiera) RegisterDataHash ¶
func (h *Hiera) RegisterDataHash(name string, fn func(data []byte, path string) (map[string]any, error))
RegisterDataHash registers (or replaces) a custom data_hash backend under name, which a hierarchy level selects via "data_hash: name". This is the seam for eyaml/hocon and other Ruby Hiera backends.
type LookupOptions ¶
type LookupOptions struct {
// Merge, when non-nil, overrides the merge behaviour for this call.
Merge *ResolutionType
// Default supplies the value returned when the key is not found.
Default Value
// HasDefault enables Default (so a nil default is distinguishable).
HasDefault bool
// DefaultValuesHash supplies per-key defaults consulted, by looked-up root
// key, when the key is not found and HasDefault is false.
DefaultValuesHash map[string]any
}
LookupOptions carries the knobs of a single Ruby-style lookup() call. A nil Merge means "let the configuration and per-key lookup_options decide"; a non-nil Merge overrides the merge behaviour for this call only.
type MapScope ¶
MapScope is a Scope backed by a nested map of variables, re-exported from the engine so callers depend on a single import.
type ResolutionType ¶
type ResolutionType int
ResolutionType mirrors Ruby Hiera's resolution_type and Puppet's lookup merge behaviour, selecting how values found at several hierarchy levels combine.
const ( // Priority (:priority) returns the highest-priority value found. Priority ResolutionType = iota // Unique (:array) flattens every found array/scalar into one deduplicated // array. Unique // Hash (:hash) shallow-merges every found hash, higher priority winning. Hash // Deep (:deep) recursively merges every found hash, higher priority winning. Deep )
type Scope ¶
Scope is the pluggable variable provider interpolation resolves against. It is re-exported so callers depend on a single import.
func NewFactScope ¶
NewFactScope builds a Scope from Puppet-style fact namespaces. Each fact is placed both at top level (so legacy references such as %{osfamily} resolve) and under a "facts" key (so structured references such as %{facts.os.family} resolve); trusted data is placed under "trusted". facts or trusted may be nil.