Skip to content

Latest commit

 

History

History
902 lines (646 loc) · 26.1 KB

File metadata and controls

902 lines (646 loc) · 26.1 KB

Greenbone Logo

filter

import "github.com/greenbone/opensight-golang-libraries/pkg/query/filter"

Index

Variables

var ErrInvalidAggregateMetric = fmt.Errorf("not a valid AggregateMetric, try [%s]", strings.Join(_AggregateMetricNames, ", "))

var ErrInvalidCompareOperator = fmt.Errorf("not a valid CompareOperator, try [%s]", strings.Join(_CompareOperatorNames, ", "))

var ErrInvalidControlType = fmt.Errorf("not a valid ControlType, try [%s]", strings.Join(_ControlTypeNames, ", "))

var ErrInvalidLogicOperator = fmt.Errorf("not a valid LogicOperator, try [%s]", strings.Join(_LogicOperatorNames, ", "))

func AggregateMetricNames

func AggregateMetricNames() []string

AggregateMetricNames returns a list of possible string values of AggregateMetric.

func CompareOperatorNames

func CompareOperatorNames() []string

CompareOperatorNames returns a list of possible string values of CompareOperator.

func ControlTypeNames

func ControlTypeNames() []string

ControlTypeNames returns a list of possible string values of ControlType.

func LogicOperatorNames

func LogicOperatorNames() []string

LogicOperatorNames returns a list of possible string values of LogicOperator.

func NewInvalidFilterFieldError

func NewInvalidFilterFieldError(format string, value ...any) error

func ValidateFilter

func ValidateFilter(request *Request, requestOptions []RequestOption) error

ValidateFilter validates the filter in the request

type AggregateMetric

AggregateMetric ENUM(

sum
min
max
avg

valueCount

)

type AggregateMetric string

const (
    // AggregateMetricSum is a AggregateMetric of type sum.
    AggregateMetricSum AggregateMetric = "sum"
    // AggregateMetricMin is a AggregateMetric of type min.
    AggregateMetricMin AggregateMetric = "min"
    // AggregateMetricMax is a AggregateMetric of type max.
    AggregateMetricMax AggregateMetric = "max"
    // AggregateMetricAvg is a AggregateMetric of type avg.
    AggregateMetricAvg AggregateMetric = "avg"
    // AggregateMetricValueCount is a AggregateMetric of type valueCount.
    AggregateMetricValueCount AggregateMetric = "valueCount"
)

func ParseAggregateMetric

func ParseAggregateMetric(name string) (AggregateMetric, error)

ParseAggregateMetric attempts to convert a string to a AggregateMetric.

func (*AggregateMetric) AppendText

func (x *AggregateMetric) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (AggregateMetric) Cmp

func (x AggregateMetric) Cmp(other AggregateMetric) int

func (AggregateMetric) IsValid

func (x AggregateMetric) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (AggregateMetric) MarshalText

func (x AggregateMetric) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*AggregateMetric) Scan

func (x *AggregateMetric) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (AggregateMetric) String

func (x AggregateMetric) String() string

String implements the Stringer interface.

func (*AggregateMetric) UnmarshalText

func (x *AggregateMetric) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (AggregateMetric) Value

func (x AggregateMetric) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type CompareOperator

CompareOperator ENUM(

beginsWith
doesNotBeginWith

contains
doesNotContain

textContains

isNumberEqualTo
isNumberNotEqualTo

isEqualTo
isNotEqualTo

isIpEqualTo
isIpNotEqualTo

isStringEqualTo
isStringNotEqualTo
isStringCaseInsensitiveEqualTo

isGreaterThan
isGreaterThanOrEqualTo

isLessThan
isLessThanOrEqualTo

beforeDate
afterDate
betweenDates

exists

isEqualToRating
isNotEqualToRating

isLessThanRating
isLessThanOrEqualToRating

isGreaterThanRating
isGreaterThanOrEqualToRating

)

type CompareOperator string

const (
    // CompareOperatorBeginsWith is a CompareOperator of type beginsWith.
    CompareOperatorBeginsWith CompareOperator = "beginsWith"
    // CompareOperatorDoesNotBeginWith is a CompareOperator of type doesNotBeginWith.
    CompareOperatorDoesNotBeginWith CompareOperator = "doesNotBeginWith"
    // CompareOperatorContains is a CompareOperator of type contains.
    CompareOperatorContains CompareOperator = "contains"
    // CompareOperatorDoesNotContain is a CompareOperator of type doesNotContain.
    CompareOperatorDoesNotContain CompareOperator = "doesNotContain"
    // CompareOperatorTextContains is a CompareOperator of type textContains.
    CompareOperatorTextContains CompareOperator = "textContains"
    // CompareOperatorIsNumberEqualTo is a CompareOperator of type isNumberEqualTo.
    CompareOperatorIsNumberEqualTo CompareOperator = "isNumberEqualTo"
    // CompareOperatorIsNumberNotEqualTo is a CompareOperator of type isNumberNotEqualTo.
    CompareOperatorIsNumberNotEqualTo CompareOperator = "isNumberNotEqualTo"
    // CompareOperatorIsEqualTo is a CompareOperator of type isEqualTo.
    CompareOperatorIsEqualTo CompareOperator = "isEqualTo"
    // CompareOperatorIsNotEqualTo is a CompareOperator of type isNotEqualTo.
    CompareOperatorIsNotEqualTo CompareOperator = "isNotEqualTo"
    // CompareOperatorIsIpEqualTo is a CompareOperator of type isIpEqualTo.
    CompareOperatorIsIpEqualTo CompareOperator = "isIpEqualTo"
    // CompareOperatorIsIpNotEqualTo is a CompareOperator of type isIpNotEqualTo.
    CompareOperatorIsIpNotEqualTo CompareOperator = "isIpNotEqualTo"
    // CompareOperatorIsStringEqualTo is a CompareOperator of type isStringEqualTo.
    CompareOperatorIsStringEqualTo CompareOperator = "isStringEqualTo"
    // CompareOperatorIsStringNotEqualTo is a CompareOperator of type isStringNotEqualTo.
    CompareOperatorIsStringNotEqualTo CompareOperator = "isStringNotEqualTo"
    // CompareOperatorIsStringCaseInsensitiveEqualTo is a CompareOperator of type isStringCaseInsensitiveEqualTo.
    CompareOperatorIsStringCaseInsensitiveEqualTo CompareOperator = "isStringCaseInsensitiveEqualTo"
    // CompareOperatorIsGreaterThan is a CompareOperator of type isGreaterThan.
    CompareOperatorIsGreaterThan CompareOperator = "isGreaterThan"
    // CompareOperatorIsGreaterThanOrEqualTo is a CompareOperator of type isGreaterThanOrEqualTo.
    CompareOperatorIsGreaterThanOrEqualTo CompareOperator = "isGreaterThanOrEqualTo"
    // CompareOperatorIsLessThan is a CompareOperator of type isLessThan.
    CompareOperatorIsLessThan CompareOperator = "isLessThan"
    // CompareOperatorIsLessThanOrEqualTo is a CompareOperator of type isLessThanOrEqualTo.
    CompareOperatorIsLessThanOrEqualTo CompareOperator = "isLessThanOrEqualTo"
    // CompareOperatorBeforeDate is a CompareOperator of type beforeDate.
    CompareOperatorBeforeDate CompareOperator = "beforeDate"
    // CompareOperatorAfterDate is a CompareOperator of type afterDate.
    CompareOperatorAfterDate CompareOperator = "afterDate"
    // CompareOperatorBetweenDates is a CompareOperator of type betweenDates.
    CompareOperatorBetweenDates CompareOperator = "betweenDates"
    // CompareOperatorExists is a CompareOperator of type exists.
    CompareOperatorExists CompareOperator = "exists"
    // CompareOperatorIsEqualToRating is a CompareOperator of type isEqualToRating.
    CompareOperatorIsEqualToRating CompareOperator = "isEqualToRating"
    // CompareOperatorIsNotEqualToRating is a CompareOperator of type isNotEqualToRating.
    CompareOperatorIsNotEqualToRating CompareOperator = "isNotEqualToRating"
    // CompareOperatorIsLessThanRating is a CompareOperator of type isLessThanRating.
    CompareOperatorIsLessThanRating CompareOperator = "isLessThanRating"
    // CompareOperatorIsLessThanOrEqualToRating is a CompareOperator of type isLessThanOrEqualToRating.
    CompareOperatorIsLessThanOrEqualToRating CompareOperator = "isLessThanOrEqualToRating"
    // CompareOperatorIsGreaterThanRating is a CompareOperator of type isGreaterThanRating.
    CompareOperatorIsGreaterThanRating CompareOperator = "isGreaterThanRating"
    // CompareOperatorIsGreaterThanOrEqualToRating is a CompareOperator of type isGreaterThanOrEqualToRating.
    CompareOperatorIsGreaterThanOrEqualToRating CompareOperator = "isGreaterThanOrEqualToRating"
)

func ParseCompareOperator

func ParseCompareOperator(name string) (CompareOperator, error)

ParseCompareOperator attempts to convert a string to a CompareOperator.

func (*CompareOperator) AppendText

func (x *CompareOperator) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (CompareOperator) Cmp

func (x CompareOperator) Cmp(other CompareOperator) int

func (CompareOperator) IsValid

func (x CompareOperator) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (CompareOperator) MarshalText

func (x CompareOperator) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*CompareOperator) Scan

func (x *CompareOperator) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (CompareOperator) String

func (x CompareOperator) String() string

String implements the Stringer interface.

func (*CompareOperator) UnmarshalText

func (x *CompareOperator) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (CompareOperator) Value

func (x CompareOperator) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type ControlType

ControlType ENUM(

bool
enum
float
integer
string
dateTime
uuid
autocomplete

)

type ControlType string

const (
    // ControlTypeBool is a ControlType of type bool.
    ControlTypeBool ControlType = "bool"
    // ControlTypeEnum is a ControlType of type enum.
    ControlTypeEnum ControlType = "enum"
    // ControlTypeFloat is a ControlType of type float.
    ControlTypeFloat ControlType = "float"
    // ControlTypeInteger is a ControlType of type integer.
    ControlTypeInteger ControlType = "integer"
    // ControlTypeString is a ControlType of type string.
    ControlTypeString ControlType = "string"
    // ControlTypeDateTime is a ControlType of type dateTime.
    ControlTypeDateTime ControlType = "dateTime"
    // ControlTypeUuid is a ControlType of type uuid.
    ControlTypeUuid ControlType = "uuid"
    // ControlTypeAutocomplete is a ControlType of type autocomplete.
    ControlTypeAutocomplete ControlType = "autocomplete"
)

func ParseControlType

func ParseControlType(name string) (ControlType, error)

ParseControlType attempts to convert a string to a ControlType.

func (*ControlType) AppendText

func (x *ControlType) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (ControlType) Cmp

func (x ControlType) Cmp(other ControlType) int

func (ControlType) IsValid

func (x ControlType) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (ControlType) MarshalText

func (x ControlType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*ControlType) Scan

func (x *ControlType) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (ControlType) String

func (x ControlType) String() string

String implements the Stringer interface.

func (*ControlType) UnmarshalText

func (x *ControlType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (ControlType) Value

func (x ControlType) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type InvalidFilterFieldError

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

func (*InvalidFilterFieldError) Error

func (i *InvalidFilterFieldError) Error() string

type LogicOperator

LogicOperator ENUM(

and
or

)

type LogicOperator string

const (
    // LogicOperatorAnd is a LogicOperator of type and.
    LogicOperatorAnd LogicOperator = "and"
    // LogicOperatorOr is a LogicOperator of type or.
    LogicOperatorOr LogicOperator = "or"
)

func ParseLogicOperator

func ParseLogicOperator(name string) (LogicOperator, error)

ParseLogicOperator attempts to convert a string to a LogicOperator.

func (*LogicOperator) AppendText

func (x *LogicOperator) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (LogicOperator) Cmp

func (x LogicOperator) Cmp(other LogicOperator) int

func (LogicOperator) IsValid

func (x LogicOperator) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (LogicOperator) MarshalText

func (x LogicOperator) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*LogicOperator) Scan

func (x *LogicOperator) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (LogicOperator) String

func (x LogicOperator) String() string

String implements the Stringer interface.

func (*LogicOperator) UnmarshalText

func (x *LogicOperator) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (LogicOperator) Value

func (x LogicOperator) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type ReadableValue

ReadableValue is a generic type that represents a human-readable value with a corresponding backend value. It has two fields: `Label` (the human-readable form of the value) and `Value` (the value for the backend).

type ReadableValue[T any] struct {
    // Label is the human-readable form of the value
    Label string `json:"label"`
    // Value is the value for the backend
    Value T   `json:"value"`
}

func NewReadableValue

func NewReadableValue[T any](label string, value T) ReadableValue[T]

NewReadableValue is a constructor faction that helps with auto detection of value type while creating ReadableValue.

func SortedReadableValues

func SortedReadableValues[T any](values ...ReadableValue[T]) []ReadableValue[T]

SortedReadableValues creates a sorted slice of ReadableValues.

func (ReadableValue[T]) Cmp

func (x ReadableValue[T]) Cmp(other ReadableValue[T]) int

Cmp allows comparing two ReadableValues. It first compares values (if they are comparable in any way) and then it compares labels.

type Request

Request is a struct representing a filter request. Operator is the logic operator used for the request. Fields is a slice of RequestField, representing the fields to be used for the filtering.

type Request struct {
    Operator LogicOperator  `json:"operator" binding:"required"`
    Fields   []RequestField `json:"fields" binding:"dive"`
}

type RequestField

RequestField represents a field in a request Field Name: The name of the field Field Keys: Sequence of keys of a nested key structure - only used for fields with a nested structure. Example: Tag -> Name: ABC (which would be represented as []string{"Tag", "Name: ABC"} ) Field Operator: The comparison operator for the field Field Value: The value of the field, which can be a list of values or a single value

type RequestField struct {
    Name     string          `json:"name" binding:"required"`
    Keys     []string        `json:"keys,omitempty"`
    Operator CompareOperator `json:"operator" binding:"required"`
    // Value can be a list of values or a value
    Value any `json:"value" binding:"required"`
}

type RequestOption

RequestOption configures a field for validation

Name: The name of the option Control: The type of control for the option Operators: The list of comparison operators for the option Values: The possible values for the option MultiSelect: Indicates whether the option supports multiple selections

type RequestOption struct {
    Name        ReadableValue[string]
    Control     RequestOptionType
    Operators   []ReadableValue[CompareOperator]
    Values      []string
    MultiSelect bool
}

type RequestOptionType

RequestOptionType configures the type of control for a field in a request option.

type RequestOptionType struct {
    Type ControlType `json:"type" enums:"string,float,integer,enum,bool"`
}

type UuidValidationError

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

func NewUuidValidationError

func NewUuidValidationError(format string, value ...any) *UuidValidationError

func (*UuidValidationError) Error

func (v *UuidValidationError) Error() string

type ValidationError

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

func NewValidationError

func NewValidationError(format string, value ...any) *ValidationError

func (*ValidationError) Error

func (v *ValidationError) Error() string

Generated by gomarkdoc

License

Copyright (C) 2022-2023 [Greenbone AG][Greenbone AG]

Licensed under the GNU General Public License v3.0 or later.