substitution

package
v1.1.6-testAutoZone Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingCIDR is returned when the CIDR is missing
	ErrMissingCIDR = errors.New("missing CIDR")
)

Functions

func RegisterSubstitution

func RegisterSubstitution(sub Handler)

RegisterSubstitution registers a new substitution

func ReplaceByState

func ReplaceByState(identifier Identifier, globalState *GlobalState, target string) (string, error)

ReplaceByState replaces the placeholders in the target string with the values from the state

Types

type GlobalState

type GlobalState map[Identifier][]State

GlobalState defines the global state of the substitutions it's a map of index to a list of substitutions

func NewGlobalState

func NewGlobalState() *GlobalState

NewGlobalState returns a new global state

func (GlobalState) Each

func (gs GlobalState) Each(f func(Identifier, []State))

Each iterates over the global state and calls the provided function

func (GlobalState) Exists

func (gs GlobalState) Exists(identifier Identifier, key string) bool

Exists checks if a key exists in the global state

func (GlobalState) GetByIdentifier

func (gs GlobalState) GetByIdentifier(identifier Identifier) []State

GetByIdentifier returns the state by the provided identifier

func (GlobalState) Len

func (gs GlobalState) Len() int

Len returns the length of the global state

func (GlobalState) Set

func (gs GlobalState) Set(identifier Identifier, key string, value string)

Set adds a new state to the global state

type Handler

type Handler interface {
	Type() string
	WriteGlobalState(identifier Identifier, state *GlobalState, sub Substitution) error
}

Handler defines the interface for a substitution handler

func GetSubstitution

func GetSubstitution(subType string) Handler

GetSubstitution returns a substitution by its type

type Identifier

type Identifier string

Identifier is used to identify the state of the current replica

type State

type State struct {
	Key   string
	Value string
}

State keeps track of "Key" to generated "Value".

type Substitution

type Substitution struct {
	Type                 string            `json:"type" yaml:"type"` // Type of the substitution, ipv4Address, ipv6Address, etc
	Key                  string            `json:"key" yaml:"key"`   // Name of the substitution to be replaced $ipv4Address for example
	Unique               bool              `json:"unique" yaml:"unique"`
	AdditionalProperties map[string]string `json:"additionalProperties" yaml:"additionalProperties"`
}

Substitution defines a substitution that can be used to replace placeholders in the cloud-init configuration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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