Documentation
¶
Overview ¶
Package history contains logic for tracking evaluation history
Index ¶
- Constants
- Variables
- type AlertFilter
- type Direction
- type EntityNameFilter
- type EntityTypeFilter
- type EvaluationHistoryService
- type Filter
- type FilterOpt
- func WithAlert(alert string) FilterOpt
- func WithEntityName(entityName string) FilterOpt
- func WithEntityType(entityType string) FilterOpt
- func WithFrom(from time.Time) FilterOpt
- func WithProfileName(profileName string) FilterOpt
- func WithProjectID(projectID uuid.UUID) FilterOpt
- func WithProjectIDStr(projectID string) FilterOpt
- func WithRemediation(remediation string) FilterOpt
- func WithStatus(status string) FilterOpt
- func WithTo(to time.Time) FilterOpt
- type ListEvaluationCursor
- type ListEvaluationFilter
- type ListEvaluationHistoryResult
- type ProfileNameFilter
- type ProjectFilter
- type RemediationFilter
- type StatusFilter
- type TimeRangeFilter
Constants ¶
const ( // Next represents the next page. Next = Direction("next") // Prev represents the prev page. Prev = Direction("prev") )
Variables ¶
var ( // ErrMalformedCursor represents errors in the cursor payload. ErrMalformedCursor = errors.New("malformed cursor") // ErrInvalidProjectID is returned when project id is missing // or malformed form the filter. ErrInvalidProjectID = errors.New("invalid project id") // ErrInvalidTimeRange is returned the time range from-to is // either missing one end or from is greater than to. ErrInvalidTimeRange = errors.New("invalid time range") // ErrInclusionExclusion is returned when both inclusion and // exclusion filters are specified on the same field. ErrInclusionExclusion = errors.New("inclusion and exclusion filter specified") // ErrInvalidIdentifier is returned when an identifier // (e.g. entity name) is empty or malformed. ErrInvalidIdentifier = errors.New("invalid identifier") )
var ( // DefaultCursor is a cursor starting from the beginning of // the data set. DefaultCursor = ListEvaluationCursor{ Time: time.UnixMicro(999999999999999999).UTC(), Direction: Next, } )
Functions ¶
This section is empty.
Types ¶
type AlertFilter ¶ added in v0.0.55
type AlertFilter interface {
// AddAlert adds an alert setting for inclusion/exclusion in
// the filter.
AddAlert(string) error
// IncludedAlerts returns the list of included alert settings.
IncludedAlerts() []string
// IncludedAlerts returns the list of excluded alert settings.
ExcludedAlerts() []string
}
AlertFilter interface should be implemented by types implementing a filter on alert settings.
type Direction ¶ added in v0.0.55
type Direction string
Direction enumerates the direction of the Cursor.
type EntityNameFilter ¶ added in v0.0.55
type EntityNameFilter interface {
// AddEntityName adds an entity name for inclusion/exclution
// in the filter.
AddEntityName(string) error
// IncludedEntityNames returns the list of included entity
// names.
IncludedEntityNames() []string
// ExcludedEntityNames returns the list of excluded entity
// names.
ExcludedEntityNames() []string
}
EntityNameFilter interface should be implemented by types implementing a filter on entity names.
type EntityTypeFilter ¶ added in v0.0.55
type EntityTypeFilter interface {
// AddEntityType adds an entity type for inclusion/exclusion
// in the filter.
AddEntityType(string) error
// IncludedEntityTypes returns the list of included entity
// types.
IncludedEntityTypes() []string
// ExcludedEntityTypes returns the list of excluded entity
// types.
ExcludedEntityTypes() []string
}
EntityTypeFilter interface should be implemented by types implementing a filter on entity types.
type EvaluationHistoryService ¶
type EvaluationHistoryService interface {
// StoreEvaluationStatus stores the result of this evaluation in the history table.
// Returns the UUID of the evaluation status, and the UUID of the rule-entity
StoreEvaluationStatus(
ctx context.Context,
qtx db.Querier,
ruleID uuid.UUID,
profileID uuid.UUID,
entityType db.Entities,
entityID uuid.UUID,
evalError error,
marshaledCheckpoint []byte,
) (uuid.UUID, error)
// ListEvaluationHistory returns a list of evaluations stored
// in the history table.
ListEvaluationHistory(
ctx context.Context,
qtx db.Querier,
cursor *ListEvaluationCursor,
size uint32,
filter ListEvaluationFilter,
) (*ListEvaluationHistoryResult, error)
}
EvaluationHistoryService contains methods to add/query data in the history table.
func NewEvaluationHistoryService ¶
func NewEvaluationHistoryService() EvaluationHistoryService
NewEvaluationHistoryService creates a new instance of EvaluationHistoryService
type Filter ¶ added in v0.0.55
type Filter interface{}
Filter is an empty interface to be implemented by structs representing filters. Its main purpose is to allow a generic definition of options functions.
type FilterOpt ¶ added in v0.0.55
FilterOpt is the option type used to configure filters.
func WithAlert ¶ added in v0.0.55
WithAlert adds an alert string to the filter. The alert is added for inclusion unless it starts with a `!` characters, in which case it is added for exclusion.
func WithEntityName ¶ added in v0.0.55
WithEntityName adds an entity name string to the filter. The entity name is added for inclusion unless it starts with a `!` characters, in which case it is added for exclusion.
func WithEntityType ¶ added in v0.0.55
WithEntityType adds an entity type string to the filter. The entity type is added for inclusion unless it starts with a `!` characters, in which case it is added for exclusion.
func WithProfileName ¶ added in v0.0.55
WithProfileName adds an profile name string to the filter. The profile name is added for inclusion unless it starts with a `!` characters, in which case it is added for exclusion.
func WithProjectID ¶ added in v0.0.55
WithProjectID adds a project id (uuid) to the filter. Whether a null uuid is valid or not is determined on a per-endpoint basis.
func WithProjectIDStr ¶ added in v0.0.55
WithProjectIDStr adds a project id (string) to the filter. Whether a null uuid is valid or not is determined on a per-endpoint basis.
func WithRemediation ¶ added in v0.0.55
WithRemediation adds a remediation string to the filter. The remediation is added for inclusion unless it starts with a `!` characters, in which case it is added for exclusion.
func WithStatus ¶ added in v0.0.55
WithStatus adds a status string to the filter. The status is added for inclusion unless it starts with a `!` characters, in which case it is added for exclusion.
type ListEvaluationCursor ¶ added in v0.0.55
ListEvaluationCursor is a struct representing a cursor in the dataset of historical evaluations.
func ParseListEvaluationCursor ¶ added in v0.0.55
func ParseListEvaluationCursor(payload string) (*ListEvaluationCursor, error)
ParseListEvaluationCursor interprets an opaque payload and returns a ListEvaluationCursor. The opaque paylaod is expected to be of one of the following forms
`"+1257894000000000"` meaning the next page of data starting from the given timestamp excluded
`"-1257894000000000"` meaning the previous page of data starting from the given timestamp excluded
`"1257894000000000"` meaning the next page of data (default) starting from the given timestamp excluded
type ListEvaluationFilter ¶ added in v0.0.55
type ListEvaluationFilter interface {
ProjectFilter
EntityTypeFilter
EntityNameFilter
ProfileNameFilter
StatusFilter
RemediationFilter
AlertFilter
TimeRangeFilter
}
ListEvaluationFilter is a filter to be used when listing historical evaluations.
func NewListEvaluationFilter ¶ added in v0.0.55
func NewListEvaluationFilter(opts ...FilterOpt) (ListEvaluationFilter, error)
NewListEvaluationFilter is a constructor routine for ListEvaluationFilter objects.
It accepts a list of ListEvaluationFilterOpt options and performs validation on them, allowing only logically sound filters.
type ListEvaluationHistoryResult ¶ added in v0.0.55
type ListEvaluationHistoryResult struct {
// Data is an ordered collection of evaluation events.
Data []db.ListEvaluationHistoryRow
// Next is an object usable as cursor to fetch the next
// page. The page is absent if Next is nil.
Next []byte
// Prev is an object usable as cursor to fetch the previous
// page. The page is absent if Prev is nil.
Prev []byte
}
ListEvaluationHistoryResult is the return value of ListEvaluationHistory function.
type ProfileNameFilter ¶ added in v0.0.55
type ProfileNameFilter interface {
// AddProfileName adds a profile name for inclusion/exclusion
// in the filter.
AddProfileName(string) error
// IncludedProfileNames returns the list of included profile
// names.
IncludedProfileNames() []string
// ExcludedProfileNames returns the list of excluded profile
// names.
ExcludedProfileNames() []string
}
ProfileNameFilter interface should be implemented by types implementing a filter on profile names.
type ProjectFilter ¶ added in v0.0.55
type ProjectFilter interface {
// AddProjectID adds a project id for inclusion in the filter.
AddProjectID(uuid.UUID) error
// GetProjectID returns the included project id.
GetProjectID() uuid.UUID
}
ProjectFilter interface should be implemented by types implementing a filter on project id.
type RemediationFilter ¶ added in v0.0.55
type RemediationFilter interface {
// AddRemediation adds a remediation for inclusion/exclusion
// in the filter.
AddRemediation(string) error
// IncludedRemediations returns the list of included
// remediations.
IncludedRemediations() []string
// ExcludedRemediations returns the list of excluded
// remediations.
ExcludedRemediations() []string
}
RemediationFilter interface should be implemented by types implementing a filter on remediation statuses.
type StatusFilter ¶ added in v0.0.55
type StatusFilter interface {
// AddStatus adds a status for inclusion/exclusion in the
// filter.
AddStatus(string) error
// IncludedStatuses returns the list of included statuses.
IncludedStatuses() []string
// ExcludedStatuses returns the list of excluded statuses.
ExcludedStatuses() []string
}
StatusFilter interface should be implemented by types implementing a filter on statuses.
type TimeRangeFilter ¶ added in v0.0.55
type TimeRangeFilter interface {
// SetFrom sets the start of the time range.
SetFrom(time.Time) error
// SetTo sets the end of the time range.
SetTo(time.Time) error
// GetFrom retrieves the start of the time range.
GetFrom() *time.Time
// GetTo retrieves the end of the time range.
GetTo() *time.Time
}
TimeRangeFilter interface should be implemented by types implementing a filter based on time range.