condition

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: MIT Imports: 19 Imported by: 8

Documentation

Overview

Package condition contains logical operators that, based on their configuration, return boolean values from messages under certain circumstances.

TODO: V2 Move this package to ./lib

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeAll             = "all"
	TypeAnd             = "and"
	TypeAny             = "any"
	TypeBoundsCheck     = "bounds_check"
	TypeCheckField      = "check_field"
	TypeCount           = "count"
	TypeJMESPath        = "jmespath"
	TypeNot             = "not"
	TypeMetadata        = "metadata"
	TypeOr              = "or"
	TypeProcessorFailed = "processor_failed"
	TypeResource        = "resource"
	TypeStatic          = "static"
	TypeText            = "text"
	TypeXor             = "xor"
)

String constants representing each condition type.

View Source
var Constructors = map[string]TypeSpec{}

Constructors is a map of all condition types with their specs.

View Source
var (
	ErrInvalidMetadataOperator = errors.New("invalid metadata operator type")
)

Errors for the metadata condition.

View Source
var (
	ErrInvalidTextOperator = errors.New("invalid text operator type")
)

Errors for the text condition.

Functions

func Descriptions

func Descriptions() string

Descriptions returns a formatted string of collated descriptions of each type.

func DocumentPlugin added in v0.28.0

func DocumentPlugin(
	typeString, description string,
	configSanitiser PluginConfigSanitiser,
)

DocumentPlugin adds a description and an optional configuration sanitiser function to the definition of a registered plugin. This improves the documentation generated by PluginDescriptions.

func PluginDescriptions added in v0.28.0

func PluginDescriptions() string

PluginDescriptions generates and returns a markdown formatted document listing each registered plugin and an example configuration for it.

func RegisterPlugin added in v0.28.0

func RegisterPlugin(
	typeString string,
	configConstructor PluginConfigConstructor,
	constructor PluginConstructor,
)

RegisterPlugin registers a plugin by a unique name so that it can be constucted similar to regular conditions. A constructor for both the plugin itself as well as its configuration struct must be provided.

WARNING: This API is experimental and could (is likely) to change.

func SanitiseConfig

func SanitiseConfig(conf Config) (interface{}, error)

SanitiseConfig returns a sanitised version of the Config, meaning sections that aren't relevant to behaviour are removed.

Types

type All added in v1.9.0

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

All is a condition that returns the logical or of all children.

func (*All) Check added in v1.9.0

func (c *All) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type AllConfig added in v1.9.0

type AllConfig struct {
	*Config `yaml:",inline" json:",inline"`
}

AllConfig is a configuration struct containing fields for the All condition.

func NewAllConfig added in v1.9.0

func NewAllConfig() AllConfig

NewAllConfig returns a AllConfig with default values.

func (AllConfig) MarshalJSON added in v1.9.0

func (m AllConfig) MarshalJSON() ([]byte, error)

MarshalJSON prints an empty object instead of nil.

func (AllConfig) MarshalYAML added in v1.9.0

func (m AllConfig) MarshalYAML() (interface{}, error)

MarshalYAML prints an empty object instead of nil.

func (*AllConfig) UnmarshalJSON added in v1.9.0

func (m *AllConfig) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ensures that when parsing child config it is initialised.

func (*AllConfig) UnmarshalYAML added in v1.9.0

func (m *AllConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML ensures that when parsing child config it is initialised.

type And added in v0.9.4

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

And is a condition that returns the logical AND of all children.

func (*And) Check added in v0.9.4

func (c *And) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type AndConfig added in v0.9.4

type AndConfig []Config

AndConfig is a configuration struct containing fields for the And condition.

func NewAndConfig added in v0.9.4

func NewAndConfig() AndConfig

NewAndConfig returns a AndConfig with default values.

type Any added in v1.9.0

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

Any is a condition that returns the logical or of all children.

func (*Any) Check added in v1.9.0

func (c *Any) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type AnyConfig added in v1.9.0

type AnyConfig struct {
	*Config `yaml:",inline" json:",inline"`
}

AnyConfig is a configuration struct containing fields for the Any condition.

func NewAnyConfig added in v1.9.0

func NewAnyConfig() AnyConfig

NewAnyConfig returns a AnyConfig with default values.

func (AnyConfig) MarshalJSON added in v1.9.0

func (m AnyConfig) MarshalJSON() ([]byte, error)

MarshalJSON prints an empty object instead of nil.

func (AnyConfig) MarshalYAML added in v1.9.0

func (m AnyConfig) MarshalYAML() (interface{}, error)

MarshalYAML prints an empty object instead of nil.

func (*AnyConfig) UnmarshalJSON added in v1.9.0

func (m *AnyConfig) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ensures that when parsing child config it is initialised.

func (*AnyConfig) UnmarshalYAML added in v1.9.0

func (m *AnyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML ensures that when parsing child config it is initialised.

type BoundsCheck added in v0.31.0

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

BoundsCheck is a condition that checks a message against a set of bounds.

func (*BoundsCheck) Check added in v0.31.0

func (c *BoundsCheck) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition

type BoundsCheckConfig added in v0.31.0

type BoundsCheckConfig struct {
	MaxParts    int `json:"max_parts" yaml:"max_parts"`
	MinParts    int `json:"min_parts" yaml:"min_parts"`
	MaxPartSize int `json:"max_part_size" yaml:"max_part_size"`
	MinPartSize int `json:"min_part_size" yaml:"min_part_size"`
}

BoundsCheckConfig contains configuration fields for the BoundsCheck condition.

func NewBoundsCheckConfig added in v0.31.0

func NewBoundsCheckConfig() BoundsCheckConfig

NewBoundsCheckConfig returns a BoundsCheckConfig with default values.

type CheckField added in v0.31.0

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

CheckField is a condition that extracts a field and checks the contents against a child condition.

func (*CheckField) Check added in v0.31.0

func (c *CheckField) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition

type CheckFieldConfig added in v0.31.0

type CheckFieldConfig struct {
	Parts     []int   `json:"parts" yaml:"parts"`
	Path      string  `json:"path" yaml:"path"`
	Condition *Config `json:"condition" yaml:"condition"`
}

CheckFieldConfig contains configuration fields for the CheckField condition.

func NewCheckFieldConfig added in v0.31.0

func NewCheckFieldConfig() CheckFieldConfig

NewCheckFieldConfig returns a CheckFieldConfig with default values.

func (CheckFieldConfig) MarshalJSON added in v0.31.0

func (c CheckFieldConfig) MarshalJSON() ([]byte, error)

MarshalJSON prints an empty object instead of nil.

func (CheckFieldConfig) MarshalYAML added in v0.31.0

func (c CheckFieldConfig) MarshalYAML() (interface{}, error)

MarshalYAML prints an empty object instead of nil.

type Config

type Config struct {
	Type            string                `json:"type" yaml:"type"`
	All             AllConfig             `json:"all" yaml:"all"`
	And             AndConfig             `json:"and" yaml:"and"`
	Any             AnyConfig             `json:"any" yaml:"any"`
	BoundsCheck     BoundsCheckConfig     `json:"bounds_check" yaml:"bounds_check"`
	CheckField      CheckFieldConfig      `json:"check_field" yaml:"check_field"`
	Count           CountConfig           `json:"count" yaml:"count"`
	JMESPath        JMESPathConfig        `json:"jmespath" yaml:"jmespath"`
	Not             NotConfig             `json:"not" yaml:"not"`
	Metadata        MetadataConfig        `json:"metadata" yaml:"metadata"`
	Or              OrConfig              `json:"or" yaml:"or"`
	Plugin          interface{}           `json:"plugin,omitempty" yaml:"plugin,omitempty"`
	ProcessorFailed ProcessorFailedConfig `json:"processor_failed" yaml:"processor_failed"`
	Resource        string                `json:"resource" yaml:"resource"`
	Static          bool                  `json:"static" yaml:"static"`
	Text            TextConfig            `json:"text" yaml:"text"`
	Xor             XorConfig             `json:"xor" yaml:"xor"`
}

Config is the all encompassing configuration struct for all condition types.

func NewConfig

func NewConfig() Config

NewConfig returns a configuration struct fully populated with default values.

func (*Config) UnmarshalJSON

func (m *Config) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ensures that when parsing configs that are in a slice the default values are still applied.

func (*Config) UnmarshalYAML

func (m *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML ensures that when parsing configs that are in a slice the default values are still applied.

type Count added in v0.11.2

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

Count is a condition that counts each message and returns false once a target count has been reached, at which point it resets the counter and starts again.

func (*Count) Check added in v0.11.2

func (c *Count) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type CountConfig added in v0.11.2

type CountConfig struct {
	Arg int `json:"arg" yaml:"arg"`
}

CountConfig is a configuration struct containing fields for the Count condition.

func NewCountConfig added in v0.11.2

func NewCountConfig() CountConfig

NewCountConfig returns a CountConfig with default values.

type JMESPath added in v0.9.8

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

JMESPath is a condition that checks message against a jmespath query.

func (*JMESPath) Check added in v0.9.8

func (c *JMESPath) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type JMESPathConfig added in v0.9.8

type JMESPathConfig struct {
	Part  int    `json:"part" yaml:"part"`
	Query string `json:"query" yaml:"query"`
}

JMESPathConfig is a configuration struct containing fields for the jmespath condition.

func NewJMESPathConfig added in v0.9.8

func NewJMESPathConfig() JMESPathConfig

NewJMESPathConfig returns a JMESPathConfig with default values.

type Metadata added in v0.23.4

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

Metadata is a condition that checks message text against logical operators.

func (*Metadata) Check added in v0.23.4

func (c *Metadata) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type MetadataConfig added in v0.23.4

type MetadataConfig struct {
	Operator string      `json:"operator" yaml:"operator"`
	Part     int         `json:"part" yaml:"part"`
	Key      string      `json:"key" yaml:"key"`
	Arg      interface{} `json:"arg" yaml:"arg"`
}

MetadataConfig is a configuration struct containing fields for the metadata condition.

func NewMetadataConfig added in v0.23.4

func NewMetadataConfig() MetadataConfig

NewMetadataConfig returns a MetadataConfig with default values.

type Not added in v0.9.4

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

Not is a condition that returns the opposite of a child condition.

func (*Not) Check added in v0.9.4

func (c *Not) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type NotConfig added in v0.9.4

type NotConfig struct {
	*Config `yaml:",inline" json:",inline"`
}

NotConfig is a configuration struct containing fields for the Not condition.

func NewNotConfig added in v0.9.4

func NewNotConfig() NotConfig

NewNotConfig returns a NotConfig with default values.

func (NotConfig) MarshalJSON added in v0.9.4

func (m NotConfig) MarshalJSON() ([]byte, error)

MarshalJSON prints an empty object instead of nil.

func (NotConfig) MarshalYAML added in v0.9.4

func (m NotConfig) MarshalYAML() (interface{}, error)

MarshalYAML prints an empty object instead of nil.

func (*NotConfig) UnmarshalJSON added in v0.9.4

func (m *NotConfig) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ensures that when parsing child config it is initialised.

func (*NotConfig) UnmarshalYAML added in v0.9.4

func (m *NotConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML ensures that when parsing child config it is initialised.

type Or added in v0.9.4

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

Or is a condition that returns the logical or of all children.

func (*Or) Check added in v0.9.4

func (c *Or) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type OrConfig added in v0.9.4

type OrConfig []Config

OrConfig is a configuration struct containing fields for the Or condition.

func NewOrConfig added in v0.9.4

func NewOrConfig() OrConfig

NewOrConfig returns a OrConfig with default values.

type PluginConfigConstructor added in v0.28.0

type PluginConfigConstructor func() interface{}

PluginConfigConstructor is a func that returns a pointer to a new and fully populated configuration struct for a plugin type. It is valid to return a pointer to an empty struct (&struct{}{}) if no configuration fields are needed.

type PluginConfigSanitiser added in v0.28.0

type PluginConfigSanitiser func(conf interface{}) interface{}

PluginConfigSanitiser is a function that takes a configuration object for a plugin and returns a sanitised (minimal) version of it for printing in examples and plugin documentation.

This function is useful for when a plugins configuration struct is very large and complex, but can sometimes be expressed in a more concise way without losing the original intent.

type PluginConstructor added in v0.28.0

type PluginConstructor func(
	config interface{},
	manager types.Manager,
	logger log.Modular,
	metrics metrics.Type,
) (types.Condition, error)

PluginConstructor is a func that constructs a Benthos condition plugin. These are plugins that are specific to certain use cases, experimental, private or otherwise unfit for widespread general use. Any number of plugins can be specified when using Benthos as a framework.

The configuration object will be the result of the PluginConfigConstructor after overlaying the user configuration.

type ProcessorFailed added in v0.38.10

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

ProcessorFailed is a condition that checks whether processing steps have failed for a message.

func (*ProcessorFailed) Check added in v0.38.10

func (p *ProcessorFailed) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type ProcessorFailedConfig added in v0.38.10

type ProcessorFailedConfig struct {
	Part int `json:"part" yaml:"part"`
}

ProcessorFailedConfig is a configuration struct containing fields for the processor_failed condition.

func NewProcessorFailedConfig added in v0.38.10

func NewProcessorFailedConfig() ProcessorFailedConfig

NewProcessorFailedConfig returns a ProcessorFailedConfig with default values.

type Resource added in v0.9.7

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

Resource is a condition that returns the result of a condition resource.

func (*Resource) Check added in v0.9.7

func (c *Resource) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type Static added in v0.11.6

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

Static is a condition that always returns a static boolean value.

func (*Static) Check added in v0.11.6

func (s *Static) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type Text added in v0.17.0

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

Text is a condition that checks message text against logical operators.

func (*Text) Check added in v0.17.0

func (c *Text) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type TextConfig added in v0.17.0

type TextConfig struct {
	Operator string `json:"operator" yaml:"operator"`
	Part     int    `json:"part" yaml:"part"`
	Arg      string `json:"arg" yaml:"arg"`
}

TextConfig is a configuration struct containing fields for the text condition.

func NewTextConfig added in v0.17.0

func NewTextConfig() TextConfig

NewTextConfig returns a TextConfig with default values.

type Type

type Type interface {
	// Check tests a message against a configured condition.
	Check(msg types.Message) bool
}

Type reads a message, calculates a condition and returns a boolean.

func New

func New(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error)

New creates a condition type based on a condition configuration.

func NewAll added in v1.9.0

func NewAll(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewAll returns an All condition.

func NewAnd added in v0.9.4

func NewAnd(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewAnd returns an And condition.

func NewAny added in v1.9.0

func NewAny(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewAny returns an Any condition.

func NewBoundsCheck added in v0.31.0

func NewBoundsCheck(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewBoundsCheck returns a BoundsCheck condition.

func NewCheckField added in v0.31.0

func NewCheckField(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewCheckField returns a CheckField condition.

func NewCount added in v0.11.2

func NewCount(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewCount returns a Count condition.

func NewJMESPath added in v0.9.8

func NewJMESPath(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewJMESPath returns a JMESPath condition.

func NewMetadata added in v0.23.4

func NewMetadata(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewMetadata returns a Metadata condition.

func NewNot added in v0.9.4

func NewNot(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewNot returns a Not condition.

func NewOr added in v0.9.4

func NewOr(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewOr returns an Or condition.

func NewProcessorFailed added in v0.38.10

func NewProcessorFailed(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewProcessorFailed returns a ProcessorFailed condition.

func NewResource added in v0.9.7

func NewResource(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewResource returns a resource condition.

func NewStatic added in v0.11.6

func NewStatic(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewStatic returns a Static condition.

func NewText added in v0.17.0

func NewText(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewText returns a Text condition.

func NewXor added in v0.9.8

func NewXor(
	conf Config, mgr types.Manager, log log.Modular, stats metrics.Type,
) (Type, error)

NewXor returns an Xor condition.

type TypeSpec

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

TypeSpec Constructor and a usage description for each condition type.

type Xor added in v0.9.8

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

Xor is a condition that returns the logical xor of all children.

func (*Xor) Check added in v0.9.8

func (c *Xor) Check(msg types.Message) bool

Check attempts to check a message part against a configured condition.

type XorConfig added in v0.9.8

type XorConfig []Config

XorConfig is a configuration struct containing fields for the Xor condition.

func NewXorConfig added in v0.9.8

func NewXorConfig() XorConfig

NewXorConfig returns a XorConfig with default values.

Jump to

Keyboard shortcuts

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