Documentation
¶
Overview ¶
Package augeas is a pure-Go (no cgo, stdlib-only) implementation of the core of Augeas, the configuration-editing library from the Puppet ecosystem.
Augeas models configuration files as an ordered tree and exposes an XPath-like path language to read and edit that tree; lenses translate the tree back and forth to the concrete file syntax. This package provides:
- a tree model (Node) of ordered, labelled nodes with optional values (siblings that share a label are addressed with 1-based positional indices, exactly like Augeas);
- an Augeas-subset path evaluator (see Augeas.Match) backing the whole read/write API;
- the core editing API on Augeas: Get, Exists, Set, SetMultiple, Insert, Remove, Move, Match, Label, DefineVariable, DefineNode and an Error surface, plus a minimal Span;
- a Lens framework (Parse/Build round-tripping text and tree) with the in-memory Augeas.TextStore and Augeas.TextRetrieve helpers;
- a starter set of built-in lenses (Hosts, Fstab, Shellvars/Simplevars and Ini/Keyvalue), registered by name;
- file Augeas.Load and Augeas.Save through a lens over an injectable FileSystem seam (the default seam is the real OS).
Supported path constructs, the shipped lenses and the explicit list of what is deferred are documented in the README. This package has no cgo and no third-party dependencies.
Index ¶
- Variables
- func LensNames() []string
- func Register(name string, lens Lens)
- type Augeas
- func (a *Augeas) DefineNode(name, expr, value string) (string, bool)
- func (a *Augeas) DefineVariable(name, expr string) (int, error)
- func (a *Augeas) Error() error
- func (a *Augeas) Exists(path string) bool
- func (a *Augeas) Get(path string) (string, bool)
- func (a *Augeas) Insert(path, label string, before bool) error
- func (a *Augeas) Label(path string) (string, bool)
- func (a *Augeas) Load(lens Lens, pattern, mount string) error
- func (a *Augeas) LoadFile(path string) error
- func (a *Augeas) Match(path string) []string
- func (a *Augeas) Move(src, dst string) error
- func (a *Augeas) Remove(path string) int
- func (a *Augeas) Root() *Node
- func (a *Augeas) Save(lens Lens, mount, filename string) error
- func (a *Augeas) Set(path, value string) error
- func (a *Augeas) SetFileSystem(fs FileSystem)
- func (a *Augeas) SetMultiple(base, sub, value string) (int, error)
- func (a *Augeas) Span(path string) (Span, error)
- func (a *Augeas) TextRetrieve(lens Lens, path string, node *Node) (string, error)
- func (a *Augeas) TextStore(lens Lens, path, text string) error
- type Engine
- type FileSystem
- type Lens
- type Node
- type Span
Constants ¶
This section is empty.
Variables ¶
var ErrSpanUnsupported = errors.New("augeas: span information is not tracked")
ErrSpanUnsupported is returned by Augeas.Span; span tracking is a documented deferred feature.
Functions ¶
Types ¶
type Augeas ¶
type Augeas struct {
// contains filtered or unexported fields
}
Augeas holds a configuration tree and the editing state (variables, the filesystem seam and the last error). Create one with New.
func (*Augeas) DefineNode ¶
DefineNode binds name to the nodes matching expr. When expr matches nothing, a single node is created at expr with the given value. It returns the path of the (first) bound node and whether a node was created.
func (*Augeas) DefineVariable ¶
DefineVariable binds name to the node-set produced by expr; the variable can then be used as "$name" at the head of a path. It returns the number of nodes bound.
func (*Augeas) Exists ¶
Exists reports whether at least one node matches path. A malformed path sets the last error and yields false.
func (*Augeas) Get ¶
Get returns the value of the single node matching path. The boolean reports whether exactly one node matched; a valueless node yields ("", true). If the path is malformed or matches more than one node the last error is set.
func (*Augeas) Insert ¶
Insert inserts a new, valueless sibling labelled label next to the single node matching path, before it when before is true, otherwise after it.
func (*Augeas) Load ¶
Load reads every file matching the glob pattern, parses it with lens and stores the resulting tree under mount+"/"+basename. A read or parse failure for one file is recorded under /augeas/files/<basename>/error and the remaining files are still processed; only a failing glob is returned as an error.
func (*Augeas) LoadFile ¶
LoadFile reads path through the filesystem seam, selects the matching lens from the corpus autoload filters, and stores the parsed tree under /files/<path>. It is the interpreted-corpus analogue of Augeas' aug_load.
func (*Augeas) Match ¶
Match returns the absolute paths of all nodes matching path, in document order. A malformed path sets the last error and yields nil.
func (*Augeas) Move ¶
Move moves the single node matching src (with its subtree) onto dst. dst may match one existing node (overwritten) or none (created). dst must not be a descendant of src.
func (*Augeas) Remove ¶
Remove deletes every node matching path together with its subtree, and returns the number of nodes removed. The root is never removed.
func (*Augeas) Save ¶
Save serialises the single subtree at mount with lens and writes it to filename through the filesystem seam.
func (*Augeas) Set ¶
Set sets the value of the node matching path. The path must match exactly one node; if it matches none, the node (and any missing ancestors) is created.
func (*Augeas) SetFileSystem ¶
func (a *Augeas) SetFileSystem(fs FileSystem)
SetFileSystem replaces the filesystem seam used by Load and Save. Passing nil is a no-op so callers cannot accidentally disable I/O.
func (*Augeas) SetMultiple ¶
SetMultiple sets value on every node matching the sub path relative to each node matching base, creating the sub node where absent. It returns the number of nodes set.
func (*Augeas) TextRetrieve ¶
TextRetrieve serialises a subtree back to text with lens. When node is non-nil it is serialised directly; otherwise the single subtree at path is used. It mirrors the C aug_text_retrieve signature, in which the caller may supply either an explicit node or a tree path.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine interprets the embedded lens corpus. Create one with NewEngine.
type FileSystem ¶
type FileSystem interface {
ReadFile(name string) ([]byte, error)
WriteFile(name string, data []byte, perm fs.FileMode) error
Glob(pattern string) ([]string, error)
}
FileSystem is the seam through which Load and Save reach files. The default implementation (New installs it) is the real OS; tests inject an in-memory implementation so the engine can be exercised without touching disk.
type Lens ¶
Lens converts between the concrete text of a configuration file and a subtree in the Augeas tree. Parse turns text into a synthetic parent node whose children are the parsed entries; Build performs the reverse. A well-behaved lens round-trips: Build(Parse(text)) reproduces canonical text, and Parse(Build(node)) reproduces the tree.
func LensByName ¶
LensByName returns the lens registered under name.
type Node ¶
Node is a single entry in the configuration tree. A node has a label, an optional value and an ordered list of children. Siblings may share a label; such siblings are distinguished by their 1-based position, matching Augeas' label[n] addressing.
func (*Node) ClearValue ¶
func (n *Node) ClearValue()
ClearValue removes the node's value, leaving it valueless.