reporter

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FormatIds = map[Format][]string{
	JSON:    {"json"},
	Table:   {"table"},
	Junit:   {"junit"},
	Tap:     {"tap"},
	None:    {"none"},
	Text:    {"text"},
	Compact: {"compact"},
}
View Source
var SeverityIds = map[Severity][]string{
	Unknown:       {"unknown"},
	Informational: {"informational"},
	Low:           {"low"},
	Medium:        {"medium"},
	High:          {"high"},
	Critical:      {"critical"},
	Off:           {"off"},
}

Functions

func CompactReporter added in v1.4.0

func CompactReporter(o *RegulaOutput) (string, error)

TextReporter returns the Regula report in a human-friendly format

func JSONReporter

func JSONReporter(r *RegulaOutput) (string, error)

func JUnitReporter

func JUnitReporter(o *RegulaOutput) (string, error)

func ResultCompare added in v1.0.0

func ResultCompare(resA, resB string) bool

ResultCompare orders "FAIL" > "PASS" > "WAIVED"

func SeverityCompare added in v1.0.0

func SeverityCompare(sevA, sevB string) bool

SeverityCompare returns true if the first severity is more important than the second. E.g. SeverityCompare("High", "Medium") yields true.

func TableReporter

func TableReporter(o *RegulaOutput) (string, error)

func TapReporter

func TapReporter(o *RegulaOutput) (string, error)

func TextReporter added in v1.0.0

func TextReporter(o *RegulaOutput) (string, error)

TextReporter returns the Regula report in a human-friendly format

Types

type FilepathResults

type FilepathResults struct {
	Filepath string
	Results  map[string]ResourceResults
	Pass     bool
}

func (FilepathResults) SortedKeys

func (f FilepathResults) SortedKeys() []string

func (FilepathResults) ToTestSuite

func (r FilepathResults) ToTestSuite() JUnitTestSuite

type Format

type Format int
const (
	JSON Format = iota
	Table
	Junit
	Tap
	None
	Text
	Compact
)

type JUnitFailure

type JUnitFailure struct {
	Message  string `xml:"message,attr"`
	Type     string `xml:"type,attr"`
	Contents string `xml:",chardata"`
}

type JUnitSkipMessage

type JUnitSkipMessage struct {
	Message string `xml:"message,attr"`
}

type JUnitTestCase

type JUnitTestCase struct {
	XMLName     xml.Name            `xml:"testcase"`
	Name        string              `xml:"name,attr"`
	ClassName   string              `xml:"classname,attr"`
	Assertions  int                 `xml:"assertions,attr"`
	SkipMessage *[]JUnitSkipMessage `xml:"skipped,omitempty"`
	Failures    *[]JUnitFailure     `xml:"failure,omitempty"`
}

type JUnitTestSuite

type JUnitTestSuite struct {
	XMLName   xml.Name        `xml:"testsuite"`
	Name      string          `xml:"name,attr"`
	Tests     int             `xml:"tests,attr"`
	TestCases []JUnitTestCase `xml:"testcase"`
}

type JUnitTestSuites

type JUnitTestSuites struct {
	XMLName    xml.Name         `xml:"testsuites"`
	Name       string           `xml:"name,attr"`
	TestSuites []JUnitTestSuite `xml:"testsuite"`
}

type RegulaOutput

type RegulaOutput struct {
	RuleResults []RuleResult `json:"rule_results"`
	Summary     Summary      `json:"summary"`
}

func ParseRegulaOutput

func ParseRegulaOutput(conf loader.LoadedConfigurations, r rego.Result) (*RegulaOutput, error)

func (RegulaOutput) AggregateByFilepath

func (o RegulaOutput) AggregateByFilepath() ResultsByFilepath

func (RegulaOutput) AggregateByRule added in v1.0.0

func (o RegulaOutput) AggregateByRule() ResultsByRule

AggregateByRule returns all rule results grouped by rule

func (RegulaOutput) ExceedsSeverity

func (o RegulaOutput) ExceedsSeverity(severity Severity) bool

func (RegulaOutput) FailuresByRule added in v1.0.0

func (o RegulaOutput) FailuresByRule() ResultsByRule

FailuresByRule returns failing rule results grouped by rule

type Reporter

type Reporter func(r *RegulaOutput) (string, error)

func GetReporter

func GetReporter(format Format) (Reporter, error)

type ResourceResults

type ResourceResults struct {
	Filepath     string
	ResourceID   string
	ResourceType string
	Results      []RuleResult
	Pass         bool
}

func (ResourceResults) ToTestCase

func (r ResourceResults) ToTestCase() JUnitTestCase

type Result added in v1.0.0

type Result int
const (
	WAIVED Result = iota
	PASS
	FAIL
)

type ResultsByFilepath

type ResultsByFilepath map[string]FilepathResults

func (ResultsByFilepath) SortedKeys

func (r ResultsByFilepath) SortedKeys() []string

func (ResultsByFilepath) ToTestSuites

func (r ResultsByFilepath) ToTestSuites() JUnitTestSuites

type ResultsByRule added in v1.0.0

type ResultsByRule []RuleResults

ResultsByRule is used to carry all rule results grouped by rule

type RuleResult

type RuleResult struct {
	Controls           []string `json:"controls"`
	Filepath           string   `json:"filepath"`
	InputType          string   `json:"input_type"`
	Provider           string   `json:"provider"`
	ResourceID         string   `json:"resource_id"`
	ResourceType       string   `json:"resource_type"`
	RuleDescription    string   `json:"rule_description"`
	RuleID             string   `json:"rule_id"`
	RuleMessage        string   `json:"rule_message"`
	RuleName           string   `json:"rule_name"`
	RuleResult         string   `json:"rule_result"`
	RuleSeverity       string   `json:"rule_severity"`
	RuleSummary        string   `json:"rule_summary"`
	RuleRemediationDoc string   `json:"rule_remediation_doc,omitempty"`
	// List of source code locations this rule result pertains to.  The first
	// element of the list always refers to the most specific source code site,
	// and further elements indicate modules in which this was included, like
	// a call stack.
	SourceLocation loader.LocationStack `json:"source_location,omitempty"`
}

func (*RuleResult) EnrichRuleResult added in v1.5.0

func (r *RuleResult) EnrichRuleResult(conf loader.LoadedConfigurations)

func (RuleResult) IsFail

func (r RuleResult) IsFail() bool

func (RuleResult) IsPass

func (r RuleResult) IsPass() bool

func (RuleResult) IsWaived

func (r RuleResult) IsWaived() bool

func (RuleResult) Message

func (r RuleResult) Message() string

func (RuleResult) ToTapRow

func (r RuleResult) ToTapRow(idx int) TapRow

type RuleResults added in v1.0.0

type RuleResults struct {
	RuleID             string
	RuleName           string
	RuleSummary        string
	RuleSeverity       string
	RuleRemediationDoc string
	Results            []*RuleResult
}

RuleResults carries a slice of RuleResults associated with a specific rule. A minimal amount of rule metadata is duplicated here for convenience.

type ScanInput added in v1.5.0

type ScanInput struct {
	Filepath  string                            `json:"filepath"`
	InputType string                            `json:"input_type"`
	Resources map[string]map[string]interface{} `json:"resources"`
}

func (*ScanInput) EnrichResources added in v1.5.0

func (s *ScanInput) EnrichResources(conf loader.LoadedConfigurations)

type ScanReport added in v1.5.0

type ScanReport struct {
	RuleResults []ScanRuleResult `json:"rule_results"`
	Summary     Summary          `json:"summary"`
}

type ScanRuleResult added in v1.5.0

type ScanRuleResult struct {
	RuleResult
	RuleEnabled bool `json:"rule_enabled"`
	RuleValid   bool `json:"rule_valid"`
	RuleWaived  bool `json:"rule_waived"`
}

type ScanView added in v1.5.0

type ScanView struct {
	Inputs          []ScanInput `json:"inputs"`
	RegulaVersion   string      `json:"regula_version"`
	ScanViewVersion string      `json:"scan_view_version"`
	Report          ScanReport  `json:"report"`
}

func ParseScanView added in v1.5.0

func ParseScanView(conf loader.LoadedConfigurations, r rego.Result) (*ScanView, error)

type Severity

type Severity int
const (
	Unknown Severity = iota
	Informational
	Low
	Medium
	High
	Critical
	Off
)

type Summary

type Summary struct {
	Filepaths   []string       `json:"filepaths"`
	RuleResults map[string]int `json:"rule_results"`
	Severities  map[string]int `json:"severities"`
}

type TableRow

type TableRow struct {
	Resource string
	Type     string
	Filepath string
	Severity string
	RuleID   string
	RuleName string
	Message  string
	Result   string
}

type TapRow

type TapRow struct {
	Ok        string
	Index     int
	Message   string
	Directive string
	Resource  string
	RuleID    string
}

func (TapRow) String

func (r TapRow) String(indent string) string

Jump to

Keyboard shortcuts

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