config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 11 Imported by: 64

Documentation

Overview

Package config provides types for specifying the expected configuration of a Conduit plugin (connector or processor). It also provides utilities to validate the configuration based on the specifications.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnrecognizedParameter    = errors.New("unrecognized parameter")
	ErrInvalidParameterValue    = errors.New("invalid parameter value")
	ErrInvalidParameterType     = errors.New("invalid parameter type")
	ErrInvalidValidationType    = errors.New("invalid validation type")
	ErrRequiredParameterMissing = errors.New("required parameter is not provided")

	ErrLessThanValidationFail    = errors.New("less-than validation failed")
	ErrGreaterThanValidationFail = errors.New("greater-than validation failed")
	ErrInclusionValidationFail   = errors.New("inclusion validation failed")
	ErrExclusionValidationFail   = errors.New("exclusion validation failed")
	ErrRegexValidationFail       = errors.New("regex validation failed")
)

Functions

This section is empty.

Types

type Config

type Config map[string]string

Config is a map of configuration values. The keys are the configuration parameter names and the values are the configuration parameter values.

func (Config) ApplyDefaults

func (c Config) ApplyDefaults(params Parameters) Config

ApplyDefaults applies the default values defined in the parameter specifications to the configuration. If a parameter is not present in the configuration, the default value is applied.

func (Config) DecodeInto

func (c Config) DecodeInto(target any, hookFunc ...mapstructure.DecodeHookFunc) error

DecodeInto copies configuration values into the target object. Under the hood, this function uses github.com/mitchellh/mapstructure, with the "mapstructure" tag renamed to "json". To rename a key, use the "json" tag. To embed structs, append ",squash" to your tag. For more details and docs, see https://pkg.go.dev/github.com/mitchellh/mapstructure.

func (Config) Sanitize

func (c Config) Sanitize() Config

Sanitize removes leading and trailing spaces from all keys and values in the configuration, and makes sure it's not nil.

func (Config) Validate

func (c Config) Validate(params Parameters) error

Validate is a utility function that applies all the validations defined in the parameter specifications. It checks for unrecognized parameters, type validations, and value validations. It returns all encountered errors.

type Parameter

type Parameter struct {
	// Default is the default value of the parameter, if any.
	Default string `json:"default"`
	// Description holds a description of the field and how to configure it.
	Description string `json:"description"`
	// Type defines the parameter data type.
	Type ParameterType `json:"type"`
	// Validations list of validations to check for the parameter.
	Validations []Validation `json:"validations"`
}

Parameter defines a single configuration parameter.

func (*Parameter) FromProto

func (p *Parameter) FromProto(proto *configv1.Parameter) error

FromProto takes data from the supplied proto object and populates the receiver. If the proto object is nil, the receiver is set to its zero value. If the function returns an error, the receiver could be partially populated.

func (Parameter) ToProto

func (p Parameter) ToProto(proto *configv1.Parameter)

ToProto takes data from the receiver and populates the supplied proto object.

type ParameterType

type ParameterType int
const (
	ParameterTypeString   ParameterType = iota + 1 // string
	ParameterTypeInt                               // int
	ParameterTypeFloat                             // float
	ParameterTypeBool                              // bool
	ParameterTypeFile                              // file
	ParameterTypeDuration                          // duration
)

func (ParameterType) MarshalText

func (pt ParameterType) MarshalText() ([]byte, error)

func (ParameterType) String

func (i ParameterType) String() string

type Parameters

type Parameters map[string]Parameter

Parameters is a map of all configuration parameters.

func (*Parameters) FromProto

func (p *Parameters) FromProto(proto map[string]*configv1.Parameter) error

FromProto takes data from the supplied proto object and populates the receiver. If the proto object is nil, the receiver is set to its zero value. If the function returns an error, the receiver could be partially populated.

func (Parameters) ToProto

func (p Parameters) ToProto(proto map[string]*configv1.Parameter)

ToProto takes data from the receiver and populates the supplied proto object.

type Validation

type Validation interface {
	Type() ValidationType
	Value() string

	Validate(string) error
}

type ValidationExclusion

type ValidationExclusion struct {
	List []string
}

func (ValidationExclusion) MarshalJSON

func (v ValidationExclusion) MarshalJSON() ([]byte, error)

func (ValidationExclusion) Type

func (ValidationExclusion) Validate

func (v ValidationExclusion) Validate(value string) error

func (ValidationExclusion) Value

func (v ValidationExclusion) Value() string

type ValidationGreaterThan

type ValidationGreaterThan struct {
	V float64
}

func (ValidationGreaterThan) MarshalJSON

func (v ValidationGreaterThan) MarshalJSON() ([]byte, error)

func (ValidationGreaterThan) Type

func (ValidationGreaterThan) Validate

func (v ValidationGreaterThan) Validate(value string) error

func (ValidationGreaterThan) Value

func (v ValidationGreaterThan) Value() string

type ValidationInclusion

type ValidationInclusion struct {
	List []string
}

func (ValidationInclusion) MarshalJSON

func (v ValidationInclusion) MarshalJSON() ([]byte, error)

func (ValidationInclusion) Type

func (ValidationInclusion) Validate

func (v ValidationInclusion) Validate(value string) error

func (ValidationInclusion) Value

func (v ValidationInclusion) Value() string

type ValidationLessThan

type ValidationLessThan struct {
	V float64
}

func (ValidationLessThan) MarshalJSON

func (v ValidationLessThan) MarshalJSON() ([]byte, error)

func (ValidationLessThan) Type

func (ValidationLessThan) Validate

func (v ValidationLessThan) Validate(value string) error

func (ValidationLessThan) Value

func (v ValidationLessThan) Value() string

type ValidationRegex

type ValidationRegex struct {
	Regex *regexp.Regexp
}

func (ValidationRegex) MarshalJSON

func (v ValidationRegex) MarshalJSON() ([]byte, error)

func (ValidationRegex) Type

func (ValidationRegex) Validate

func (v ValidationRegex) Validate(value string) error

func (ValidationRegex) Value

func (v ValidationRegex) Value() string

type ValidationRequired

type ValidationRequired struct{}

func (ValidationRequired) MarshalJSON

func (v ValidationRequired) MarshalJSON() ([]byte, error)

func (ValidationRequired) Type

func (ValidationRequired) Validate

func (v ValidationRequired) Validate(value string) error

func (ValidationRequired) Value

func (v ValidationRequired) Value() string

type ValidationType

type ValidationType int64
const (
	ValidationTypeRequired    ValidationType = iota + 1 // required
	ValidationTypeGreaterThan                           // greater-than
	ValidationTypeLessThan                              // less-than
	ValidationTypeInclusion                             // inclusion
	ValidationTypeExclusion                             // exclusion
	ValidationTypeRegex                                 // regex
)

func (ValidationType) MarshalText

func (vt ValidationType) MarshalText() ([]byte, error)

func (ValidationType) String

func (i ValidationType) String() string

Jump to

Keyboard shortcuts

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