controlexecute

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const RootResultGroupName = "root_result_group"

Variables

This section is empty.

Functions

func IsValidControlStatus

func IsValidControlStatus(status string) bool

Types

type ControlProgressRenderer

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

func NewControlProgressRenderer

func NewControlProgressRenderer(total int) *ControlProgressRenderer

func (*ControlProgressRenderer) Finish

func (p *ControlProgressRenderer) Finish(ctx context.Context)

func (*ControlProgressRenderer) OnControlComplete added in v0.10.0

func (p *ControlProgressRenderer) OnControlComplete(ctx context.Context)

func (*ControlProgressRenderer) OnControlError added in v0.10.0

func (p *ControlProgressRenderer) OnControlError(ctx context.Context)

func (*ControlProgressRenderer) OnControlFinish added in v0.10.0

func (p *ControlProgressRenderer) OnControlFinish(ctx context.Context)

func (*ControlProgressRenderer) OnControlStart

func (p *ControlProgressRenderer) OnControlStart(ctx context.Context, control *modconfig.Control)

func (*ControlProgressRenderer) Start

func (p *ControlProgressRenderer) Start(ctx context.Context)

type ControlRun

type ControlRun struct {
	// the control being run
	Control *modconfig.Control `json:"-"`
	// control summary
	Summary StatusSummary `json:"-"`
	// result rows
	Rows []*ResultRow `json:"results"`
	// a list of distinct dimension keys from the results of this control
	DimensionKeys []string `json:"-"`
	// execution duration
	Duration time.Duration `json:"-"`

	// properties from control
	ControlId   string            `json:"control_id"`
	Description string            `json:"description"`
	Severity    string            `json:"severity"`
	Tags        map[string]string `json:"tags"`
	Title       string            `json:"title"`

	// parent result group
	Group *ResultGroup `json:"-"`
	// execution tree
	Tree *ExecutionTree `json:"-"`
	// used to trace the events within the duration of a control execution
	Lifecycle *utils.LifecycleTimer `json:"-"`
	// contains filtered or unexported fields
}

ControlRun is a struct representing the execution of a control run. It will contain one or more result items (i.e. for one or more resources).

func NewControlRun

func NewControlRun(control *modconfig.Control, group *ResultGroup, executionTree *ExecutionTree) *ControlRun

func (*ControlRun) Finished

func (r *ControlRun) Finished() bool

func (*ControlRun) GetError

func (r *ControlRun) GetError() error

func (*ControlRun) GetRunStatus

func (r *ControlRun) GetRunStatus() ControlRunStatus

func (*ControlRun) MatchTag added in v0.12.0

func (r *ControlRun) MatchTag(key string, value string) bool

MatchTag returns the value corresponding to the input key. Returns 'false' if not found

type ControlRunStatus

type ControlRunStatus uint32
const (
	ControlRunReady ControlRunStatus = 1 << iota
	ControlRunStarted
	ControlRunComplete
	ControlRunError
)

type Dimension

type Dimension struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Dimension is a struct representing an attribute returned by a control run. An attribute is stored as a dimension if it's not a standard attribute (reason, resource, status).

type DimensionColorGenerator

type DimensionColorGenerator struct {
	Map map[string]map[string]uint8
	// contains filtered or unexported fields
}

func NewDimensionColorGenerator

func NewDimensionColorGenerator(startingRow, startingColumn uint8) (*DimensionColorGenerator, error)

NewDimensionColorGenerator creates a new NewDimensionColorGenerator

func (*DimensionColorGenerator) GetDimensionProperties

func (g *DimensionColorGenerator) GetDimensionProperties() []string

type ExecutionTree

type ExecutionTree struct {
	// root node of the execution tree
	Root      *ResultGroup
	StartTime time.Time
	EndTime   time.Time
	// map of dimension property name to property value to color map
	DimensionColorGenerator *DimensionColorGenerator
	// flat list of all control runs
	ControlRuns []*ControlRun
	// contains filtered or unexported fields
}

ExecutionTree is a structure representing the control execution hierarchy

func NewExecutionTree

func NewExecutionTree(ctx context.Context, workspace *workspace.Workspace, client db_common.Client, arg string) (*ExecutionTree, error)

func (*ExecutionTree) AddControl

func (e *ExecutionTree) AddControl(ctx context.Context, control *modconfig.Control, group *ResultGroup)

AddControl checks whether control should be included in the tree if so, creates a ControlRun, which is added to the parent group

func (*ExecutionTree) Execute

func (e *ExecutionTree) Execute(ctx context.Context, client db_common.Client) int

func (*ExecutionTree) GetAllTags

func (e *ExecutionTree) GetAllTags() []string

func (*ExecutionTree) ShouldIncludeControl

func (e *ExecutionTree) ShouldIncludeControl(controlName string) bool

type GroupSummary

type GroupSummary struct {
	Status   StatusSummary            `json:"status"`
	Severity map[string]StatusSummary `json:"-"`
}

func NewGroupSummary added in v0.9.0

func NewGroupSummary() *GroupSummary

type ResultGroup

type ResultGroup struct {
	GroupId     string            `json:"group_id" csv:"group_id"`
	Title       string            `json:"title" csv:"title"`
	Description string            `json:"description" csv:"description"`
	Tags        map[string]string `json:"tags"`
	// the overall summary of the group
	Summary *GroupSummary `json:"summary"`
	// child result groups
	Groups []*ResultGroup `json:"groups"`
	// child control runs
	ControlRuns []*ControlRun            `json:"controls"`
	Severity    map[string]StatusSummary `json:"-"`

	// the control tree item associated with this group(i.e. a mod/benchmark)
	GroupItem modconfig.ModTreeItem `json:"-"`
	Parent    *ResultGroup          `json:"-"`
	Duration  time.Duration         `json:"-"`
	// a list of distinct dimension keys from descendant controls
	DimensionKeys []string `json:"-"`
	// contains filtered or unexported fields
}

ResultGroup is a struct representing a grouping of control results It may correspond to a Benchmark, or some other arbitrary grouping

func NewResultGroup

func NewResultGroup(ctx context.Context, executionTree *ExecutionTree, treeItem modconfig.ModTreeItem, parent *ResultGroup) *ResultGroup

NewResultGroup creates a result group from a ModTreeItem

func NewRootResultGroup

func NewRootResultGroup(ctx context.Context, executionTree *ExecutionTree, rootItems ...modconfig.ModTreeItem) *ResultGroup

NewRootResultGroup creates a ResultGroup to act as the root node of a control execution tree

func (*ResultGroup) AllTagKeys added in v0.12.0

func (r *ResultGroup) AllTagKeys() []string

func (*ResultGroup) ControlRunCount

func (r *ResultGroup) ControlRunCount() int

func (*ResultGroup) GetChildGroupByName

func (r *ResultGroup) GetChildGroupByName(name string) *ResultGroup

GetChildGroupByName finds a nested child ResultGroup with a specific name

func (*ResultGroup) GetControlRunByName

func (r *ResultGroup) GetControlRunByName(name string) *ControlRun

GetControlRunByName finds a child ControlRun with a specific control name

func (*ResultGroup) GetGroupByName

func (r *ResultGroup) GetGroupByName(name string) *ResultGroup

GetGroupByName finds an immediate child ResultGroup with a specific name

type ResultRow

type ResultRow struct {
	// reason for the status
	Reason string `json:"reason" csv:"reason"`
	// resource name
	Resource string `json:"resource" csv:"resource"`
	// status of the row (ok, info, alarm, error, skip)
	Status string `json:"status" csv:"status"`
	// dimensions for this row
	Dimensions []Dimension `json:"dimensions"`
	// parent control run
	Run *ControlRun `json:"-"`
	// source control
	Control *modconfig.Control `json:"-" csv:"control_id:UnqualifiedName,control_title:Title,control_description:Description"`
}

ResultRow is the result of a control execution for a single resource

func NewResultRow

func NewResultRow(run *ControlRun, row *queryresult.RowResult, colTypes []*sql.ColumnType) (*ResultRow, error)

func (*ResultRow) AddDimension

func (r *ResultRow) AddDimension(c *sql.ColumnType, val interface{})

AddDimension checks whether a column value is a scalar type, and if so adds it to the Dimensions map

func (*ResultRow) GetDimensionValue added in v0.12.0

func (r *ResultRow) GetDimensionValue(key string) string

GetDimensionValue returns the value for a dimension key. Returns an empty string with 'false' if not found

type StatusSummary

type StatusSummary struct {
	Alarm int `json:"alarm"`
	Ok    int `json:"ok"`
	Info  int `json:"info"`
	Skip  int `json:"skip"`
	Error int `json:"error"`
}

StatusSummary is a struct containing the counts of each possible control status

func (*StatusSummary) FailedCount

func (s *StatusSummary) FailedCount() int

func (*StatusSummary) PassedCount added in v0.12.0

func (s *StatusSummary) PassedCount() int

func (*StatusSummary) TotalCount

func (s *StatusSummary) TotalCount() int

Jump to

Keyboard shortcuts

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