filter

package
v0.0.0-...-8b28c38 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StringMapHasKey passes if the map has the provided key
	StringMapHasKey StringMapOperation = "stringmapcontains"

	StringMapStartsWith = "stringmapstartswith"

	// StringMapEquals when the given key and value match
	StringMapEquals = "stringmapequals"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllCut

type AllCut[T any] struct{}

AllCut is a filter that matches nothing. This is useful for applications like authorization, where a user/group/role may be disallowed from viewing data entirely.

func (AllCut[T]) Matches

func (ac AllCut[T]) Matches(T) bool

func (AllCut[T]) String

func (ac AllCut[T]) String() string

type AllPass

type AllPass[T any] struct{}

AllPass is a filter that matches everything and is the same as no filter. It is implemented here as a guard against universal operations occurring in the absence of filters.

func (AllPass[T]) Matches

func (n AllPass[T]) Matches(T) bool

func (AllPass[T]) String

func (n AllPass[T]) String() string

type And

type And[T any] struct {
	Filters []Filter[T]
}

And is a set of filters that should be evaluated as a logical AND.

func (And[T]) Matches

func (a And[T]) Matches(that T) bool

func (And[T]) String

func (a And[T]) String() string

type Filter

type Filter[T any] interface {
	String() string

	// Matches is the canonical in-Go function for determining if T
	// matches a filter.
	Matches(T) bool
}

Filter represents anything that can be used to filter given generic type T.

Implement this interface with caution. While it is generic, it is intended to be introspectable so query handlers can perform various optimizations. These optimizations include: - Routing a query to the most optimal cache - Querying backing data stores efficiently (e.g. translation to SQL)

Custom implementations of this interface outside of this package should not expect to receive these benefits. Passing a custom implementation to a handler may in errors.

type Not

type Not[T any] struct {
	Filter Filter[T]
}

Not negates any filter contained within it

func (Not[T]) Matches

func (n Not[T]) Matches(that T) bool

Matches inverts the result of the child filter

func (Not[T]) String

func (n Not[T]) String() string

type Or

type Or[T any] struct {
	Filters []Filter[T]
}

Or is a set of filters that should be evaluated as a logical OR.

func (Or[T]) Matches

func (o Or[T]) Matches(that T) bool

func (Or[T]) String

func (o Or[T]) String() string

type StringMapOperation

type StringMapOperation string

StringMapOperation is an enum that represents operations that can be performed when filtering (equality, inequality, etc.)

type StringMapPropertied

type StringMapPropertied interface {
	StringMapProperty(string) (map[string]string, error)
}

type StringMapProperty

type StringMapProperty[T StringMapPropertied] struct {
	Field string
	Op    StringMapOperation
	Key   string
	Value string
}

StringMapProperty is the lowest-level type of filter. It represents a filter operation (equality, inequality, etc.) on a property that contains a string map

func (StringMapProperty[T]) Matches

func (smp StringMapProperty[T]) Matches(that T) bool

func (StringMapProperty[T]) String

func (smp StringMapProperty[T]) String() string

type StringOperation

type StringOperation string

StringOperation is an enum that represents operations that can be performed when filtering (equality, inequality, etc.)

const (
	// StringEquals is the equality operator
	// "kube-system" FilterEquals "kube-system" = true
	// "kube-syste" FilterEquals "kube-system" = false
	StringEquals StringOperation = "stringequals"

	// StringStartsWith matches strings with the given prefix.
	// "kube-system" StartsWith "kube" = true
	//
	// When comparing with a field represented by an array/slice, this is like
	// applying FilterContains to every element of the slice.
	StringStartsWith = "stringstartswith"
)

If you add a FilterOp, MAKE SURE TO UPDATE ALL FILTER IMPLEMENTATIONS! Go does not enforce exhaustive pattern matching on "enum" types.

type StringPropertied

type StringPropertied interface {
	// StringProperty acts as a validator and getter for a structs string properties
	StringProperty(string) (string, error)
}

StringPropertied is used to validate the name of a property field and return its value

type StringProperty

type StringProperty[T StringPropertied] struct {
	Field string
	Op    StringOperation

	// Value is for _all_ filters. A filter of 'namespace:"kubecost"' has
	// Value="kubecost"
	Value string
}

StringProperty is the lowest-level type of filter. It represents a filter operation (equality, inequality, etc.) on a field with a string value (namespace, node, pod, etc.).

func (StringProperty[T]) Matches

func (sp StringProperty[T]) Matches(that T) bool

func (StringProperty[T]) String

func (sp StringProperty[T]) String() string

type StringSliceOperation

type StringSliceOperation string

StringSliceOperation is an enum that represents operations that can be performed when filtering (equality, inequality, etc.)

const (
	// StringSliceContains is an array/slice membership operator
	// ["a", "b", "c"] FilterContains "a" = true
	StringSliceContains StringSliceOperation = "stringslicecontains"

	// StringSliceContainsPrefix is like FilterContains, but using StartsWith instead
	// of Equals.
	// ["kube-system", "abc123"] ContainsPrefix ["kube"] = true
	StringSliceContainsPrefix = "stringslicecontainsprefix"
)

type StringSlicePropertied

type StringSlicePropertied interface {
	StringSliceProperty(string) ([]string, error)
}

type StringSliceProperty

type StringSliceProperty[T StringSlicePropertied] struct {
	Field string
	Op    StringSliceOperation

	Value string
}

StringSliceProperty is the lowest-level type of filter. It represents a filter operation (equality, inequality, etc.) on a property that contains a string slice

func (StringSliceProperty[T]) Matches

func (ssp StringSliceProperty[T]) Matches(that T) bool

func (StringSliceProperty[T]) String

func (ssp StringSliceProperty[T]) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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