filter

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 7 Imported by: 2

README

Filter

The filter package is designed to allow you to define filters, primarily by yaml to be able to filter resources. This is used in the nuke package to filter resources based on a set of criteria.

Filter's can be optionally added to a group filters within a group are combined with an AND operation. Filters in different group are combined with an OR operation.

There is also the concept of a global filter that is applied to all resources.

Types

There are multiple filter types that can be used to filter the resources. These types are used to match against the property.

  • empty
  • exact
  • glob
  • regex
  • contains
  • dateOlderThan
  • suffix
  • prefix

Global

You can define a global filter that will be applied to all resources. This is useful for defining a set of filters that should be applied to all resources.

It has a special key called __global__.

This only works when you are defining it as a resource type as part of the Filters map[string][]Filter type.

Documentation

Overview

Package filter provides a way to filter resources based on a set of criteria.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	// Type is the type of filter to apply
	Type Type

	// Property is the name of the property to filter on
	Property string

	// Value is the value to filter on
	Value string

	// Values allows for multiple values to be specified for a filter
	Values []string

	// Invert is a flag to invert the filter
	Invert string
}

Filter is a filter to apply to a resource

func NewExactFilter

func NewExactFilter(value string) Filter

NewExactFilter creates a new filter that matches the exact value

func (*Filter) Match

func (f *Filter) Match(o string) (bool, error)

Match checks if the filter matches the given value

func (*Filter) UnmarshalYAML

func (f *Filter) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Filter) Validate

func (f *Filter) Validate() error

Validate checks if the filter is valid

type Filters

type Filters map[string][]Filter

func (Filters) Append added in v0.10.0

func (f Filters) Append(f2 Filters)

Append appends the filters from f2 to f. This is primarily used to append filters from a preset to a set of filters that were defined on a resource type.

func (Filters) Get added in v0.10.0

func (f Filters) Get(resourceType string) []Filter

Get returns the filters for a specific resource type or the global filters if they exist. If there are no filters it returns nil

func (Filters) Merge

func (f Filters) Merge(f2 Filters)

Merge is an alias of Append for backwards compatibility Deprecated: use Append instead

func (Filters) Validate

func (f Filters) Validate() error

Validate checks if the filters are valid or not and returns an error if they are not

type Type

type Type string
const (
	Empty         Type = ""
	Exact         Type = "exact"
	Glob          Type = "glob"
	Regex         Type = "regex"
	Contains      Type = "contains"
	DateOlderThan Type = "dateOlderThan"
	Suffix        Type = "suffix"
	Prefix        Type = "prefix"
	NotIn         Type = "NotIn"
	In            Type = "In"

	Global = "__global__"
)

Jump to

Keyboard shortcuts

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