databind

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDiscovery

func NewDiscovery(variables data.Map, metricAnnotations data.InterfaceMap, entityRewrites []data.EntityRewrite) discovery.Discovery

NewDiscovery returns an instance of discovery.Discovery aimed to be used for testing as prod should come from unmarshalling.

func Replace

func Replace(vals *Values, template interface{}, options ...ReplaceOption) (transformedData []data.Transformed, err error)

Replace receives one template, which may be a map or a struct whose string fields may contain ${variable} placeholders, and returns an array of items of the same type of the template, but replacing the variable placeholders from the respective Values. The Values of type "variable" are the same for all the returned values. The returned array contains one instance per each "discovered" data value.

func ReplaceBytes added in v0.1.0

func ReplaceBytes(vals *Values, template []byte, options ...ReplaceOption) ([][]byte, error)

ReplaceBytes receives a byte array that may contain ${variable} placeholders, and returns an array of byte arrays replacing the variable placeholders from the respective Values.

Types

type Binder

type Binder interface {

	// Fetch queries the Sources for discovery data and user-defined variables, and returns the
	// acquired Values.
	Fetch(ctx *Sources) (Values, error)

	// Replace receives one template, which may be a map or a struct whose string fields may
	// contain ${variable} placeholders, and returns an array of items of the same type of the
	// template, but replacing the variable placeholders from the respective Values.
	// The Values of type "variable" are the same for all the returned values. The returned
	// array contains one instance per each "discovered" data value.
	Replace(vals *Values, template interface{}, options ...ReplaceOption) (transformedData []data.Transformed, err error)
}

Binder wraps the functions provided by this package

func New

func New() Binder

New returns an instance of Binder

type DiscovererInfo

type DiscovererInfo struct {
	Type     DiscovererType
	Name     string
	Matchers map[string]string
}

DiscovererInfo keeps util info about the discoverer.

type DiscovererType

type DiscovererType string

type OnDemand

type OnDemand func(key string) (value []byte, found bool)

OnDemand can be used during Replace and ReplaceBytes to dynamically get variable values given a variable name (key).

type ReplaceOption

type ReplaceOption func(rc *replaceConfig)

Option provide extra behaviour configuration to the replacement process.

func Provided

func Provided(od OnDemand) ReplaceOption

Provided configures the Replace and ReplaceBytes functions to get variables from the OnDemand function. If a given variable is not found on the variables/discovery replacement, the variable name is first looked up in the OnDemand provider before being replaced or discarded as not found.

type Sources

type Sources struct {
	Info DiscovererInfo
	// contains filtered or unexported fields
}

Sources holds the configuration of all the discovery and variable sources. It is built from the LoadYAML function

func LoadYAML

func LoadYAML(bytes []byte) (*Sources, error)

LoadYaml builds a set of data binding Sources from a YAML file

type Test

type Test struct {
	Value interface{} `yaml:"value,omitempty" json:"value,omitempty"`
}

Test for testing purposes until providers get decoupled.

func (*Test) Validate

func (t *Test) Validate() error

type Values

type Values struct {
	// contains filtered or unexported fields
}

The outcome of a sources Fetch process. It keeps both variables (secrets) and discovered matches

func Fetch

func Fetch(ctx *Sources) (Values, error)

Fetch queries the Sources for discovery data and user-defined variables, and returns the acquired Values.

func NewValues

func NewValues(vars data.Map, discoveries ...discovery.Discovery) Values

NewValues returns an instance of value

func (*Values) VarsLen

func (v *Values) VarsLen() int

VarsLen amount of variables to be replaced.

type YAMLAgentConfig

type YAMLAgentConfig struct {
	Variables map[string]varEntry `yaml:"variables,omitempty" json:"variables,omitempty"` // key: variable name
}

func (*YAMLAgentConfig) DataSources

func (dc *YAMLAgentConfig) DataSources() (*Sources, error)

type YAMLConfig

type YAMLConfig struct {
	YAMLAgentConfig `yaml:",inline"`
	Discovery       struct {
		TTL     string               `yaml:"ttl,omitempty"`
		Docker  *discovery.Container `yaml:"docker,omitempty"`
		Fargate *discovery.Container `yaml:"fargate,omitempty"`
		Command *discovery.Command   `yaml:"command,omitempty"`
	} `yaml:"discovery"`
}

func (*YAMLConfig) DataSources

func (dc *YAMLConfig) DataSources() (*Sources, error)

DataSources builds a set of data binding sources for the YAMLConfig instance.

func (*YAMLConfig) Enabled

func (y *YAMLConfig) Enabled() bool

Jump to

Keyboard shortcuts

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