reporter

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func CompactReporter

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

TextReporter returns the Regula report in a human-friendly format

func JSONReporter

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

func JUnitReporter

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

func ResultCompare

func ResultCompare(resA, resB string) bool

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

func SarifReporter

func SarifReporter(o *RegulaReport) (string, error)

func SeverityCompare

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 *RegulaReport) (string, error)

func TapReporter

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

func TextReporter

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

TextReporter returns the Regula report in a human-friendly format

func ToSarifLevel

func ToSarifLevel(r string, s string) string

Constructs sarif level based on rule result and severity.

func ToSarifLocation

func ToSarifLocation(l loader.Location) *sarif.Location

Turns a regula location into a sarif location

func ValidateFormat

func ValidateFormat(name string) error

func ValidateSeverity

func ValidateSeverity(name string) error

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
	Sarif
)

func FormatFromString

func FormatFromString(name string) (Format, error)

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 RegulaReport

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

func (RegulaReport) AggregateByFilepath

func (o RegulaReport) AggregateByFilepath() ResultsByFilepath

func (RegulaReport) AggregateByRule

func (o RegulaReport) AggregateByRule() ResultsByRule

AggregateByRule returns all rule results grouped by rule

func (RegulaReport) ExceedsSeverity

func (o RegulaReport) ExceedsSeverity(severity Severity) bool

func (RegulaReport) FailuresByRule

func (o RegulaReport) FailuresByRule() ResultsByRule

FailuresByRule returns failing rule results grouped by rule

func (*RegulaReport) RecomputeSummary

func (report *RegulaReport) RecomputeSummary()

type Reporter

type Reporter func(r *RegulaReport) (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

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

type ResultsByRule []RuleResults

ResultsByRule is used to carry all rule results grouped by rule

type RuleResult

type RuleResult struct {
	Controls           []string               `json:"controls"`
	Families           []string               `json:"families"`
	Filepath           string                 `json:"filepath"`
	InputType          string                 `json:"input_type"`
	Provider           string                 `json:"provider"`
	ResourceID         string                 `json:"resource_id"`
	ResourceType       string                 `json:"resource_type"`
	ResourceTags       map[string]interface{} `json:"resource_tags"`
	RuleDescription    string                 `json:"rule_description"`
	RuleID             string                 `json:"rule_id"`
	RuleMessage        string                 `json:"rule_message"`
	RuleName           string                 `json:"rule_name"`
	RuleRawResult      bool                   `json:"rule_raw_result"`
	RuleRemediationDoc string                 `json:"rule_remediation_doc,omitempty"`
	RuleResult         string                 `json:"rule_result"`
	RuleSeverity       string                 `json:"rule_severity"`
	RuleSummary        string                 `json:"rule_summary"`
	// 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"`
	ActiveWaivers  []string             `json:"active_waivers,omitempty"`
}

func (*RuleResult) EnrichRuleResult

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

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

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

func (*ScanInput) EnrichResources

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

type ScanView

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

func ParseScanView

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

func (*ScanView) ToJSON

func (s *ScanView) ToJSON() (string, error)

type Severity

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

func SeverityFromString

func SeverityFromString(name string) (Severity, error)

func (Severity) String

func (s Severity) String() string

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