filter

package
v1.1.49 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: Apache-2.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFilterConfiguration = errors.Newf(1147, "error parsing filter in configuration. Syntax error:%s")
	ErrFilterExpression    = errors.New(1148, "error parsing filter in configuration. Unrecognized expression")
	ErrFilterGeneralParse  = errors.New(1149, "error parsing filter in configuration")
	ErrFilterArgument      = errors.New(1150, "error parsing filter in configuration. Invalid call argument")
	ErrFilterSelectorType  = errors.New(1151, "error parsing filter in configuration. Invalid selector type")
	ErrFilterSelectorExpr  = errors.New(1152, "error parsing filter in configuration. Invalid selector expression")
	ErrFilterOperator      = errors.New(1153, "error parsing filter in configuration. Invalid operator")
	ErrFilterCondition     = errors.New(1154, "error parsing filter in configuration. Unrecognized condition")
)

Errors hit while parsing the APIMANAGER_FILTER

Functions

func SetSupportedCallExprTypes

func SetSupportedCallExprTypes(callTypes []CallType)

SetSupportedCallExprTypes - Overrides the list of supported condition expression

Types

type AgentFilter

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

AgentFilter - Represents the filter

func (*AgentFilter) Evaluate

func (af *AgentFilter) Evaluate(tags interface{}) (result bool)

Evaluate - Performs the evaluation of the filter against the data

type AgentFilterData

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

AgentFilterData - Represents the data for filter evaluation

func (*AgentFilterData) GetKeys

func (ad *AgentFilterData) GetKeys(ftype string) []string

GetKeys - Returns all the map keys based on the filter data type

func (*AgentFilterData) GetValue

func (ad *AgentFilterData) GetValue(ftype, fName string) (val string, ok bool)

GetValue - Returns the value for map entry based on the filter data type

func (*AgentFilterData) GetValues

func (ad *AgentFilterData) GetValues(ftype string) []string

GetValues - Returns all the map values based on the filter data type

type AnyExpr

type AnyExpr struct {
	FilterType string
}

AnyExpr - Any implementation. Returns all filter data values to be checked against

func (*AnyExpr) Execute

func (e *AnyExpr) Execute(data Data) (interface{}, error)

Execute - Returns all filter data values to be checked against

func (*AnyExpr) GetType

func (e *AnyExpr) GetType() CallType

GetType - Returns the CallType

func (*AnyExpr) String

func (e *AnyExpr) String() string

type CallExpr

type CallExpr interface {
	GetType() CallType
	Execute(data Data) (interface{}, error)
	String() string
}

CallExpr - Interface for call expression in filter condition

type CallType

type CallType int

CallType - Call type for filter condition

const (
	GETVALUE CallType = iota
	MATCHREGEX
	CONTAINS
	EXISTS
	ANY
)

Constants for Call type

func GetCallType

func GetCallType(callTypeString string) (callType CallType, err error)

GetCallType - Converts a string to its corresponding call type.

type ComparableValue

type ComparableValue interface {
	String() string
	// contains filtered or unexported methods
}

ComparableValue - Interface for RHS value operand

type CompoundCondition

type CompoundCondition struct {
	RHSCondition Condition
	LHSCondition Condition
	Operator     string
}

CompoundCondition - Represents group of simple conditions

func (*CompoundCondition) Evaluate

func (cf *CompoundCondition) Evaluate(data Data) bool

Evaluate - evaulates the compound condition

func (*CompoundCondition) String

func (cf *CompoundCondition) String() string

String - string representation for compound condition

type Condition

type Condition interface {
	Evaluate(data Data) bool
	String() string
}

Condition - Interface for the filter condition

type ConditionParser

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

ConditionParser - Represents the filter condition parser

func NewConditionParser

func NewConditionParser() *ConditionParser

NewConditionParser - Create a new instance of condition parser

func (*ConditionParser) Parse

func (f *ConditionParser) Parse(filterConfig string) ([]Condition, error)

Parse - parses the AST tree to filter condition

type ContainsExpr

type ContainsExpr struct {
	FilterType string
	Name       string
	Arg        string
}

ContainsExpr - Contains implementation. Check if the argument string is contained in value of specified filter data

func (*ContainsExpr) Execute

func (e *ContainsExpr) Execute(data Data) (interface{}, error)

Execute - Returns true if the argument string is contained in value of specified filter data

func (*ContainsExpr) GetType

func (e *ContainsExpr) GetType() CallType

GetType - Returns the CallType

func (*ContainsExpr) String

func (e *ContainsExpr) String() string

type Data

type Data interface {
	GetValue(filterType string, filterKey string) (string, bool)
	GetKeys(filterType string) []string
	GetValues(filterType string) []string
}

Data - Interface representing the data for filter evaluation

func NewFilterData

func NewFilterData(tags interface{}, attr interface{}) Data

NewFilterData - Transforms the data to flat map which is used for filter evaluation

type ExistsExpr

type ExistsExpr struct {
	FilterType string
	Name       string
}

ExistsExpr - Exists implementation. Checks the existance of the selector as key in filter data

func (*ExistsExpr) Execute

func (e *ExistsExpr) Execute(data Data) (interface{}, error)

Execute - Returns true if the selector key is found in filter data

func (*ExistsExpr) GetType

func (e *ExistsExpr) GetType() CallType

GetType - Returns the CallType

func (*ExistsExpr) String

func (e *ExistsExpr) String() string

type Filter

type Filter interface {
	Evaluate(tags interface{}) bool
}

Filter - Interface for filter

func NewFilter

func NewFilter(filterConfig string) (filter Filter, err error)

NewFilter - Creates a new instance of the filter

type MatchRegExExpr

type MatchRegExExpr struct {
	FilterType string
	Name       string
	Arg        *regexp.Regexp
}

MatchRegExExpr - MatchRegEx implementation. Performs a regular expression match for argument against value of specified filter data

func (*MatchRegExExpr) Execute

func (e *MatchRegExExpr) Execute(data Data) (interface{}, error)

Execute - Returns true if the regular expression in argument matches the value for specified filter data

func (*MatchRegExExpr) GetType

func (e *MatchRegExExpr) GetType() CallType

GetType - Returns the CallType

func (*MatchRegExExpr) String

func (e *MatchRegExExpr) String() string

type SimpleCondition

type SimpleCondition struct {
	LHSExpr  CallExpr
	Value    ComparableValue
	Operator string
}

SimpleCondition - Identifies a simple condition

func (*SimpleCondition) Evaluate

func (sf *SimpleCondition) Evaluate(data Data) (res bool)

Evaluate - evaluates a simple/call expression condition

func (*SimpleCondition) String

func (sf *SimpleCondition) String() string

String - string representation for simple condition

type StringRHSValue

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

StringRHSValue - Represents the RHS value in simple condition

func (*StringRHSValue) String

func (scv *StringRHSValue) String() string

type ValueExpr

type ValueExpr struct {
	FilterType string
	Name       string
}

ValueExpr - Get Value implementation. Evaulates the value from filter data based on selector name

func (*ValueExpr) Execute

func (e *ValueExpr) Execute(data Data) (interface{}, error)

Execute - Returns the value based on the selector name

func (*ValueExpr) GetType

func (e *ValueExpr) GetType() CallType

GetType - Returns the CallType

func (*ValueExpr) String

func (e *ValueExpr) String() string

Jump to

Keyboard shortcuts

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