filters

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const RFC7230_3_2_6Token = "^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$"

RFC7230_3_2_6Token is the regular expression defining the RFC 7230 production for "tokens", which is used to check valid HTTP methods.

Variables

View Source
var EmptyRegexp = regexp.MustCompile(``)

EmptyRegexp is the compiled regexp for the empty string.

View Source
var NewEmptyRegexpMatcher = func() RegexpMatcher {
	return &regexpMatcher{EmptyRegexp}
}

NewEmptyRegexpMatcher provides a default all-accepting matcher.

Functions

This section is empty.

Types

type ConnectionErrorFilter

type ConnectionErrorFilter struct{}

ConnectionErrorFilter matches if any non-nil error is present.

func (*ConnectionErrorFilter) MatchesCall

func (f *ConnectionErrorFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*ConnectionErrorFilter) SetMatcher

func (*ConnectionErrorFilter) SetMatcher(matcher Matcher) error

SetMatcher is part of the Filter interface. In ConnectionErrorFilter, is only accepts a nil matcher, as no underlying matcher is actually used.

func (*ConnectionErrorFilter) Type

Type is part of the Filter interface.

type DomainFilter

type DomainFilter struct {
	RegexpMatcher
}

DomainFilter provides a filter for the host name in API requests.

func (*DomainFilter) MatchesCall

func (f *DomainFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*DomainFilter) SetMatcher

func (f *DomainFilter) SetMatcher(matcher Matcher) error

SetMatcher sets the filter RegexpMatcher.

If the returned error is not nil, the filter Matcher cannot be used.

If the returned error is not nil, the filter Regex will accept any value.

To apply a case-insensitive match, prepend (?i) to the regex, as in: (?i)\.bearer\.sh$ DomainFilter should always use a case-insensitive match.

func (*DomainFilter) Type

func (*DomainFilter) Type() FilterType

Type is part of the Filter interface.

type Filter

type Filter interface {
	Type() FilterType
	// MatchesCall checks whether the filter, with its configuration, matches the
	// events.Event passed to it, if any: some filters may not need a
	// request nor a response, in which case nil is a valid value to pass them.
	MatchesCall(event events.Event) bool
	// SetMatcher assigns a specific Matcher instance to the filter.
	// Passing a nil matcher will assign a filter-specific default Matcher.
	SetMatcher(Matcher) error
}

Filter defines the behaviour common to all filters

func NewFilterFromDescription

func NewFilterFromDescription(filterMap FilterMap, fd *FilterDescription) Filter

NewFilterFromDescription creates a Filter instance from a FilterDescription.

type FilterDescription

type FilterDescription struct {
	// ChildHash is set on filters.NotFilter
	ChildHash string

	// Value is set on filters using filters.StringMatcher, like filters.HTTPMethodFilter.
	Value string

	// Pattern is set on filters using filters.RegexpMatcher, like filters.DomainFilter.
	// XXX Its fields are not portable across regexp implementations.
	Pattern *RegexpMatcherDescription

	// FilterSetDescription carries the fields set on filters.FilterSet filters.
	FilterSetDescription

	// KeyValueDescription carries the fields set on filters using filters.KeyValueMatcher.
	// XXX Its fields are not portable across regexp implementations.
	KeyValueDescription

	// Range is set on filters using filters.RangeMatcher like filters.StatusCodeFilter.
	Range RangeMatcherDescription

	// StageType is one of the 4 API call stages.
	StageType string

	// TypeName is the name of the filter type, used to select which fields
	// from the config to parse.
	TypeName string
}

FilterDescription is a kind of "union type" describing all possible fields returned by the config server, with TypeName acting as the discriminator.

func (FilterDescription) KeyPatternRegexp

func (d FilterDescription) KeyPatternRegexp() *regexp.Regexp

KeyPatternRegexp returns the KeyPattern as a Regexp

func (FilterDescription) PatternRegexp

func (d FilterDescription) PatternRegexp() *regexp.Regexp

PatternRegexp returns the Pattern as a Regexp

func (FilterDescription) String

func (d FilterDescription) String() string

func (FilterDescription) ValuePatternRegexp

func (d FilterDescription) ValuePatternRegexp() *regexp.Regexp

ValuePatternRegexp returns the ValuePattern as a Regexp

type FilterMap

type FilterMap map[string]Filter

FilterMap binds Filter hashes in a config.Description to the actual Filter instances.

type FilterSet

type FilterSet interface {
	Filter
	// AddChildren adds any number of children filters. Nil filters are stripped
	// from the list.
	AddChildren(...Filter) FilterSet

	// Children returns the list of children.
	Children() []Filter
}

FilterSet is the type of compound Filters made of other Filters, which can themselves be FilterSet values.

func NewFilterSet

func NewFilterSet(operator FilterSetOperator, children ...Filter) FilterSet

NewFilterSet builds a FilterSet from an operator and children Filter instances.

type FilterSetDescription

type FilterSetDescription struct {
	// ChildHashes is set on filters.FilterSet filters
	ChildHashes []string

	// Operator is set on filters.FilterSet filters. It may only be `ANY` or `ALL`.
	Operator string
}

FilterSetDescription provides a serialization-friendly description of a FilterSet.

func (FilterSetDescription) String

func (d FilterSetDescription) String() string

String implements fmt.Stringer.

type FilterSetOperator

type FilterSetOperator byte

FilterSetOperator represents the operators available in Filter sets.

const (
	// Any matches if any of the child Filters matches.
	Any FilterSetOperator = iota

	// All matches if all of the child Filters match.
	All

	// NotFirst is special: it only matches if the first child does not match,
	// ignoring any other children.
	NotFirst
)

func (FilterSetOperator) String

func (i FilterSetOperator) String() string

type FilterType

type FilterType interface {
	// Create creates an instance of the described type. The actual type of the
	// description depends on the FilterType and will be asserted.
	Create(fm FilterMap, description *FilterDescription) Filter
	Name() string
	WantsRequest() bool
	WantsResponse() bool
	fmt.Stringer
}

FilterType allows Filter types to have "static" properties.

var (
	// NotFilterType describes NotFilter.
	NotFilterType FilterType = filterType{"NotFilter", notFilterFromDescription, true, true}
	// FilterSetFilterType describes the FilterSet.
	FilterSetFilterType FilterType = filterType{"FilterSet", setFilterFromDescription, true, true}

	// DomainFilterType describes DomainFilter.
	DomainFilterType FilterType = filterType{"DomainFilter", domainFilterFromDescription, true, false}

	// HTTPMethodFilterType describes HTTPMethodFilter.
	HTTPMethodFilterType FilterType = filterType{"HttpMethodFilter", methodFilterFromDescription, true, false}
	// ParamFilterType describes ParamFilter.
	ParamFilterType FilterType = filterType{"ParamFilter", paramFilterFromDescription, true, false}
	// PathFilterType describes PathFilter.
	PathFilterType FilterType = filterType{"PathFilter", pathFilterFromDescription, true, false}
	// RequestHeadersFilterType describes RequestHeadersFilter.
	RequestHeadersFilterType FilterType = filterType{"RequestHeadersFilter", requestFilterHeadersFromDescription, true, false}
	// ResponseHeadersFilterType describes ResponseHeadersFilter.
	ResponseHeadersFilterType FilterType = filterType{"ResponseHeadersFilter", responseHeadersFilterFromDescription, false, true}
	// StatusCodeFilterType describes StatusCodeFilter.
	StatusCodeFilterType FilterType = filterType{"StatusCodeFilter", statusCodeFilterFromDescription, false, true}

	// ConnectionErrorFilterType describes ConnectionErrorFilter.
	ConnectionErrorFilterType FilterType = filterType{"ConnectionErrorFilter", connectionErrorFilterFromDescription, false, false}
	// YesInternalFilter described YesFilter, an internal use filter.
	YesInternalFilter FilterType = filterType{"YesFilter", yesFilterFromDescription, false, false}
)

func FilterTypeByName

func FilterTypeByName(name string) FilterType

FilterTypeByName returns a FilterType instance for the passed name, or nil if the name does not match an existing FilterType.

type HTTPMethodFilter

type HTTPMethodFilter struct {
	StringMatcher
}

HTTPMethodFilter provides a filter for the HTTP method in API calls.

func (*HTTPMethodFilter) MatchesCall

func (f *HTTPMethodFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*HTTPMethodFilter) SetMatcher

func (f *HTTPMethodFilter) SetMatcher(matcher Matcher) error

SetMatcher sets the filter StringMatcher.

To ensure compliance with RFC 7230 §3.2.6, the matcher string must match RFC7230_3_2_6Token.

If the returned error is not nil, the filter will only accept GET, applying Go HTTP conventions where an empty method means GET, ignoring case.

Note that in most cases, the CONNECT method will not behave like any other. See http.Transport for details.

func (*HTTPMethodFilter) Type

func (*HTTPMethodFilter) Type() FilterType

Type is part of the Filter interface.

type KeyValueDescription

type KeyValueDescription struct {
	ValuePattern *RegexpMatcherDescription
	KeyPattern   *RegexpMatcherDescription
}

KeyValueDescription is a serialization-friendly representation of a KeyValueMatcher.

func (KeyValueDescription) String

func (d KeyValueDescription) String() string

type KeyValueMatcher

type KeyValueMatcher interface {
	Matcher
	KeyRegexp() *regexp.Regexp
	ValueRegexp() *regexp.Regexp
}

KeyValueMatcher is a matcher combining key and value matching for nested data types.

Because it is reflection-based and can crawl complex structures, it may be very CPU-expensive.

func NewKeyValueMatcher

func NewKeyValueMatcher(keyRegexp, valueRegexp *regexp.Regexp) KeyValueMatcher

NewKeyValueMatcher creates a KeyValueMatcher accepting values matching the regular expressions built from the passed strings. Passing an empty string for either expression builds a nil regex accepting anything. Passing an invalid regex string will return a unusable nil matcher.

type Matcher

type Matcher interface {
	Matches(x interface{}) bool
}

Matcher is the interface shared by all matchers.

type NotFilter

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

NotFilter provides a filter inverting the underlying filter.

func (*NotFilter) AddChildren

func (f *NotFilter) AddChildren(filters ...Filter) FilterSet

AddChildren overrides the embedded filterSet method to have one child at most.

func (NotFilter) Children

func (f NotFilter) Children() []Filter

func (*NotFilter) MatchesCall

func (f *NotFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*NotFilter) SetFilter

func (f *NotFilter) SetFilter(filter Filter) error

SetFilter sets the filter to invert.

Passing a nil filter treats it as a Yes filter, returning a No filter.

func (*NotFilter) SetMatcher

func (f *NotFilter) SetMatcher(matcher Matcher) error

SetMatcher only accepts a nil Matcher, because it applies the matcher found in its underlying Filter.

func (*NotFilter) Type

func (*NotFilter) Type() FilterType

Type is part of the Filter interface.

type ParamFilter

type ParamFilter struct {
	KeyValueMatcher
}

ParamFilter provides a key-value filter for API request parameters.

func (*ParamFilter) MatchesCall

func (f *ParamFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*ParamFilter) SetMatcher

func (f *ParamFilter) SetMatcher(matcher Matcher) error

SetMatcher sets the filter KeyValueMatcher.

If the returned error is not nil, the filter Regex will accept any value.

To apply a case-insensitive match, prepend (?i) to the matcher regexps, as in: (?i)\.bearer\.sh$

func (*ParamFilter) Type

func (*ParamFilter) Type() FilterType

Type is part of the Filter interface.

type PathFilter

type PathFilter struct {
	RegexpMatcher
}

PathFilter provides a filter for the path in API requests.

func (*PathFilter) MatchesCall

func (f *PathFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*PathFilter) SetMatcher

func (f *PathFilter) SetMatcher(matcher Matcher) error

SetMatcher sets the filter RegexpMatcher.

If the returned error is not nil, the filter Matcher cannot be used.

As per the Go runtime client, the setter accepts relative paths, which are likely not to be what you expect in API calls, so be sure to include leading slashes in most - if not all - cases.

If the returned error is not nil, the filter Regex will accept any value.

To apply a case-insensitive match, prepend (?i) to the regex, as in: (?i)\.bearer\.sh$

func (*PathFilter) Type

func (*PathFilter) Type() FilterType

Type is part of the Filter interface.

type RangeMatcher

type RangeMatcher interface {
	Matcher
	fmt.Stringer
	Contains(int) bool
	From(int) RangeMatcher
	To(int) RangeMatcher
	ExcludeFrom() RangeMatcher
	ExcludeTo() RangeMatcher
}

RangeMatcher provides the ability to check whether an int value is within an integer range.

By default, its lo and hi limits are the maximum representable values, and they are included in comparisons.

The interface allows a fluent initialization, like: NewRangeMatcher().hi(200).ExcludeTo(), which will define the semi-open interval [minInt, 200[.

func NewHTTPStatusMatcher

func NewHTTPStatusMatcher() RangeMatcher

NewHTTPStatusMatcher returns a range matcher for the valid HTTP status code range.

func NewRangeMatcher

func NewRangeMatcher() RangeMatcher

NewRangeMatcher creates a valid default RangeMatcher covering all int values.

type RangeMatcherDescription

type RangeMatcherDescription struct {
	From        interface{} // FIXME Config server returns inconsistent types.
	To          interface{} // FIXME Config server returns inconsistent types.
	ExcludeFrom bool
	ExcludeTo   bool
}

RangeMatcherDescription is a serialization-friendly description of a RangeMatcher.

func (RangeMatcherDescription) String

func (d RangeMatcherDescription) String() string

String() implements fmt.Stringer.

func (RangeMatcherDescription) ToInt

func (RangeMatcherDescription) ToInt(mixed interface{}) int

ToInt converts any value to an int. Strings not describing integer numbers, and all types except int convert to 0.

type RegexpMatcher

type RegexpMatcher interface {
	Matcher
	Regexp() *regexp.Regexp
}

RegexpMatcher provides the ability to match agains a Go regular expression.

By default, it matches anything.

func NewRegexpMatcher

func NewRegexpMatcher(re *regexp.Regexp) RegexpMatcher

NewRegexpMatcher creates a RangeMatcher.

type RegexpMatcherDescription

type RegexpMatcherDescription struct {
	// Flags is a string of the regexp flags
	Flags string
	// Value is the string form of the regexp.
	Value string
}

RegexpMatcherDescription is a serialization-friendly description of a RegexpMatcher.

func (RegexpMatcherDescription) String

func (d RegexpMatcherDescription) String() string

String implements fmt.Stringer.

type RequestHeadersFilter

type RequestHeadersFilter struct {
	KeyValueMatcher
}

RequestHeadersFilter provides a filter for API Request headers.

func (*RequestHeadersFilter) MatchesCall

func (f *RequestHeadersFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*RequestHeadersFilter) SetMatcher

func (f *RequestHeadersFilter) SetMatcher(matcher Matcher) error

SetMatcher sets the filter KeyValueMatcher.

If the returned error is not nil, the filter will accept any value except nil.

To apply a case-insensitive match, prepend (?i) to the matcher regexps, as in: (?i)\.bearer\.sh$

func (*RequestHeadersFilter) Type

func (f *RequestHeadersFilter) Type() FilterType

Type is part of the Filter interface.

type ResponseHeadersFilter

type ResponseHeadersFilter struct {
	KeyValueMatcher
}

ResponseHeadersFilter provides a filter for API Response headers.

func (*ResponseHeadersFilter) MatchesCall

func (f *ResponseHeadersFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*ResponseHeadersFilter) SetMatcher

func (f *ResponseHeadersFilter) SetMatcher(matcher Matcher) error

SetMatcher sets the filter KeyValueMatcher.

If the returned error is not nil, the filter will accept any value except nil.

To apply a case-insensitive match, prepend (?i) to the matcher regexps, as in: (?i)\.bearer\.sh$

func (*ResponseHeadersFilter) Type

Type is part of the Filter interface.

type StatusCodeFilter

type StatusCodeFilter struct {
	RangeMatcher
}

StatusCodeFilter provides a filter for the response status code in API requests.

func (*StatusCodeFilter) MatchesCall

func (f *StatusCodeFilter) MatchesCall(e events.Event) bool

MatchesCall is part of the Filter interface.

func (*StatusCodeFilter) SetMatcher

func (f *StatusCodeFilter) SetMatcher(matcher Matcher) error

SetMatcher sets the filter RangeMatcher. A nil RangeMatcher mean any valid StatusCode.

If the returned error is not nil, the RangeMatcher is rejected.

func (*StatusCodeFilter) Type

func (*StatusCodeFilter) Type() FilterType

Type is part of the Filter interface.

type StringMatcher

type StringMatcher interface {
	Matches(x interface{}) bool
	fmt.Stringer
	IgnoresCase() bool
}

StringMatcher provides the ability to match against a string, possibly ignoring case.

By default, it matches the empty string.

func NewStringMatcher

func NewStringMatcher(s string, ignoreCase bool) StringMatcher

NewStringMatcher creates a StringMatcher.

It will never be invalid, its default value will match the empty string.

type YesFilter

type YesFilter struct{}

YesFilter provides a filter accepting any input, even nil.

func (*YesFilter) AddChildren

func (f *YesFilter) AddChildren(...Filter) FilterSet

AddChildren is part of the FilterSet interface.

func (*YesFilter) Children

func (*YesFilter) Children() []Filter

Children is part of the FilterSet interface.

func (*YesFilter) MatchesCall

func (*YesFilter) MatchesCall(events.Event) bool

MatchesCall is part of the Filter interface.

func (*YesFilter) SetMatcher

func (*YesFilter) SetMatcher(matcher Matcher) error

SetMatcher is part of the Filter interface. In YesFilter, is only accepts a nil matcher, as no underlying matcher is actually used.

func (*YesFilter) Type

func (*YesFilter) Type() FilterType

Type is part of the Filter interface.

Jump to

Keyboard shortcuts

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