Documentation ¶
Overview ¶
Package selectors provides utilities for selecting entities based on profiles using CEL
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrResultUnknown is returned when the result of a selector expression is unknown // this tells the caller to try again with more information ErrResultUnknown = errors.New("result is unknown") // ErrUnsupported is returned when the entity type is not supported ErrUnsupported = errors.New("unsupported entity type") // ErrSelectorCheck is returned if the selector fails to be checked for syntax errors ErrSelectorCheck = errors.New("failed to check selector") )
Functions ¶
This section is empty.
Types ¶
type CheckError ¶
type CheckError struct { ErrDetails // contains filtered or unexported fields }
CheckError is an error type for type checking errors in CEL expressions, e.g. mismatched types
func (*CheckError) Error ¶
func (ce *CheckError) Error() string
Error implements the error interface for CheckError
func (*CheckError) Is ¶
func (_ *CheckError) Is(target error) bool
Is checks if the target error is a CheckError
func (*CheckError) Unwrap ¶
func (ce *CheckError) Unwrap() error
type EntitySelection ¶
type EntitySelection struct {
// contains filtered or unexported fields
}
EntitySelection is a struct that holds the compiled CEL expressions for a given entity type
func (*EntitySelection) Select ¶
func (s *EntitySelection) Select(se *internalpb.SelectorEntity, userOpts ...SelectOption) (bool, string, error)
Select return true if the entity matches all the compiled expressions and false otherwise
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is a struct that holds the CEL environments for each entity type and the factories for creating
func NewEnv ¶
func NewEnv() *Env
NewEnv creates a new Env struct with the default factories for each entity type. The factories are used on first access to create the CEL environments for each entity type.
func (*Env) CheckSelector ¶
func (e *Env) CheckSelector(sel *minderv1.Profile_Selector) error
CheckSelector checks if a selector expression compiles and is valid for a given entity
func (*Env) NewSelectionFromProfile ¶
func (e *Env) NewSelectionFromProfile( entityType minderv1.Entity, profileSelection []models.ProfileSelector, ) (Selection, error)
NewSelectionFromProfile creates a new Selection (compiled CEL programs for that entity type) from a profile
type ErrDetails ¶
type ErrDetails struct { Errors []ErrInstance `json:"errors,omitempty"` Source string `json:"source,omitempty"` }
ErrDetails is a struct that holds the details of an error in a CEL expression
func (*ErrDetails) AsJSON ¶
func (ed *ErrDetails) AsJSON() string
AsJSON returns the ErrDetails as a JSON string
type ErrInstance ¶
type ErrInstance struct { Line int `json:"line,omitempty"` Col int `json:"col,omitempty"` Msg string `json:"msg,omitempty"` }
ErrInstance is one occurrence of an error in a CEL expression
type ErrStructure ¶
type ErrStructure struct { Err ErrKind `json:"err"` Details ErrDetails `json:"details"` }
ErrStructure is a struct that callers can use to deserialize the JSON error
type ParseError ¶
type ParseError struct { ErrDetails // contains filtered or unexported fields }
ParseError is an error type for syntax errors in CEL expressions
func (*ParseError) Error ¶
func (pe *ParseError) Error() string
Error implements the error interface for ParseError
func (*ParseError) Is ¶
func (_ *ParseError) Is(target error) bool
Is checks if the target error is a ParseError
func (*ParseError) Unwrap ¶
func (pe *ParseError) Unwrap() error
type SelectOption ¶
type SelectOption func(*selectionOptions)
SelectOption is a functional option for the Select method
func WithUnknownPaths ¶
func WithUnknownPaths(paths ...string) SelectOption
WithUnknownPaths sets the explicit unknown paths for the selection
type Selection ¶
type Selection interface {
Select(*internalpb.SelectorEntity, ...SelectOption) (bool, string, error)
}
Selection is an interface for selecting entities based on a profile
type SelectionBuilder ¶
type SelectionBuilder interface {
NewSelectionFromProfile(minderv1.Entity, []models.ProfileSelector) (Selection, error)
}
SelectionBuilder is an interface for creating Selections (a collection of compiled CEL expressions) for an entity type. This is what the user of this module uses. The interface makes it easier to pass mocks by the user of this module.
type SelectionChecker ¶
type SelectionChecker interface {
CheckSelector(*minderv1.Profile_Selector) error
}
SelectionChecker is an interface for checking if a selector expression is valid for a given entity type