configs

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEntries = errors.New("no entries in selection")

ErrNoEntries is returned when a Selection has no entries.

View Source
var ErrSkip = errors.New("skipping operation for this entry")

ErrSkip is a special sentinel error that signals that the given entry should be skipped during batch processing. When a caller's function returns ErrSkip, the error is not returned back to the caller.

Functions

This section is empty.

Types

type Configuration

type Configuration interface {
	Name() string
}

Configuration describes any type that can be named (such as a package configuration struct, where the package has name (e.g. "busybox") that's a meaningful key for indexing the configuration itself.)

type Entry

type Entry[T Configuration] interface {

	// Update applies the given entryUpdater to the entry.
	Update(ctx context.Context, updater EntryUpdater[T]) error

	// Configuration returns the entry as a decoded configuration.
	Configuration() *T
	// contains filtered or unexported methods
}

Entry represents an individual item in the Index.

type EntryUpdater

type EntryUpdater[T Configuration] func(*Index[T], Entry[T]) error

An EntryUpdater is a function that takes a configuration Entry and modifies a specific section of the configuration (type T) data. It's meant to be passed into NewTargetedYAMLASTMutater as an argument to update the YAML data that underlies the configuration data.

The EntryUpdater ultimately needs to be passed to an Index to do the actual update operation.

func NewYAMLUpdateFunc

func NewYAMLUpdateFunc[T Configuration](yamlASTMutater YAMLASTMutater[T]) EntryUpdater[T]

NewYAMLUpdateFunc returns a EntryUpdater function that will use the YAMLASTMutater provided to operate on a given Entry.

type Index

type Index[T Configuration] struct {
	// contains filtered or unexported fields
}

An Index is a queryable store of configurations, where each configuration has already been decoded both into the configuration Go type (T) and into a YAML AST.

func NewIndex

func NewIndex[T Configuration](ctx context.Context, fsys rwfs.FS, cfgDecodeFunc func(context.Context, string) (*T, error)) (*Index[T], error)

NewIndex returns a new Index of all configurations found within the given filesystem. The provided cfgDecodeFunc should take a path to a YAML file in a fs.FS, decode the file to type T, and return a reference the "type T" data, or an error if there was a problem.

func NewIndexFromPaths

func NewIndexFromPaths[T Configuration](ctx context.Context, fsys rwfs.FS, cfgDecodeFunc func(context.Context, string) (*T, error), paths ...string) (*Index[T], error)

NewIndexFromPaths returns a new Index of configurations for each of the given paths. The provided cfgDecodeFunc should take a path to a YAML file in a fs.FS, decode the file to type T, and return a reference the "type T" data, or an error if there was a problem.

func (*Index[T]) Create

func (i *Index[T]) Create(ctx context.Context, filepath string, cfg T) error

Create creates a new configuration file at the given path, with the given cfg. The new configuration is automatically added to the Index.

func (*Index[T]) Path

func (i *Index[T]) Path(name string) string

Path returns the path to the configuration file for the given name.

func (*Index[T]) Select

func (i *Index[T]) Select() Selection[T]

Select returns a Selection for the Index, which allows the caller to begin chaining selection clauses.

type SectionUpdater

type SectionUpdater[K any, T Configuration] func(configuration T) (K, error)

A SectionUpdater is a function that takes a Configuration (type T) and returns an updated version of a section (type K) of that Configuration.

type Selection

type Selection[T Configuration] struct {
	// contains filtered or unexported fields
}

A Selection is a view into an Index's configuration (type T) entries. The selection can expose anywhere from zero entries up to all the index's entries. A selection allows the caller to chain methods to further constrain the selection and to perform operations on each item in the selection.

func (Selection[T]) Configurations

func (s Selection[T]) Configurations() []T

Configurations returns the Configuration items included in the current Selection.

func (Selection[T]) Each

func (s Selection[T]) Each(iterator func(Entry[T]))

Each calls the given iterator function for each Entry in the Selection.

func (Selection[T]) Entries

func (s Selection[T]) Entries() []Entry[T]

Entries returns the Entry items included in the current Selection.

func (Selection[T]) First

func (s Selection[T]) First() (Entry[T], error)

First returns the first Entry in the Selection.

func (Selection[T]) Len

func (s Selection[T]) Len() int

Len returns the count of configurations in the Selection.

func (Selection[T]) Update

func (s Selection[T]) Update(ctx context.Context, entryUpdater EntryUpdater[T]) error

Update applies the given entryUpdater to all entries currently in the Selection.

func (Selection[T]) Where

func (s Selection[T]) Where(condition func(Entry[T]) bool) Selection[T]

Where filters the selection down to entries for which the given condition is true.

func (Selection[T]) WhereFilePath

func (s Selection[T]) WhereFilePath(p string) Selection[T]

WhereFilePath filters the selection down to entries whose configuration file path match the given parameter.

func (Selection[T]) WhereName

func (s Selection[T]) WhereName(name string) Selection[T]

WhereName filters the selection down to entries whose name match the given parameter.

type YAMLASTMutater

type YAMLASTMutater[T any] func(T, *yaml.Node) error

A YAMLASTMutater is a function that mutates a YAML AST. The function is also given a configuration struct (type T) in case implementations require it for context.

func NewTargetedYAMLASTMutater

func NewTargetedYAMLASTMutater[K any, T Configuration](
	sectionName string,
	updater SectionUpdater[K, T],
	cfgSectionDataAssigner func(configuration T, sectionData K) T,
) YAMLASTMutater[T]

NewTargetedYAMLASTMutater returns a YAMLASTMutater designed to update a single "section" of the YAML AST. The section is root-level mapping key, the data of which is described by type K.

Directories

Path Synopsis
advisory
v1
v2
os

Jump to

Keyboard shortcuts

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