evaluation

package
v1.8.38-rc Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SKIP_RULE_PREFIX string = "datree.skip/"
)

Variables

View Source
var ExplicitOutputOptions = []string{"simple", "yaml", "json", "xml", "JUnit", "sarif"}
View Source
var FormattedOutputOptions = []string{"yaml", "json", "xml", "JUnit", "sarif"}
View Source
var InteractiveOutputOptions = []string{"", "simple"}
View Source
var OSInfoFn = utils.NewOSInfo

Functions

func GetResultsText added in v1.5.0

func GetResultsText(resultsData *PrintResultsData) (string, error)

func GetWarningExtraMessages

func GetWarningExtraMessages(invalidFile *extractor.InvalidFile) []printer.ExtraMessage

func GetjsonResult added in v1.6.12

func GetjsonResult(resultsData *PrintResultsData) (string, error)

func IsFormattedOutputOption

func IsFormattedOutputOption(option string) bool

func IsHelmFile

func IsHelmFile(filePath string) bool

func IsKustomizationFile

func IsKustomizationFile(filePath string) bool

func IsValidOutputOption

func IsValidOutputOption(option string) bool

func OutputFormats

func OutputFormats() string

func PrintResults

func PrintResults(resultsData *PrintResultsData) error

func SaveLastResultToJson added in v1.6.12

func SaveLastResultToJson(resultsData *PrintResultsData)

Types

type AdditionalJUnitData

type AdditionalJUnitData struct {
	AllEnabledRules            []cliClient.RuleData
	AllFilesThatRanPolicyCheck []string
}

type CLIClient

type CLIClient interface {
	SendEvaluationResult(request *cliClient.EvaluationResultRequest) (*cliClient.SendEvaluationResultsResponse, error)
}

type EvaluationRequestData

type EvaluationRequestData struct {
	Token                     string
	ClientId                  string
	CliVersion                string
	K8sVersion                string
	PolicyName                string
	CiContext                 *ciContext.CIContext
	RulesData                 []cliClient.RuleData
	FilesData                 []cliClient.FileData
	FailedYamlFiles           []string
	FailedK8sFiles            []string
	PolicyCheckResults        FailedRulesByFiles
	EvaluationDurationSeconds float64
}

type EvaluationResults

type EvaluationResults struct {
	FileNameRuleMapper FileNameRuleMapper
	Summary            EvaluationResultsSummery
}

type EvaluationResultsSummery

type EvaluationResultsSummery struct {
	TotalFailedRules  int
	TotalSkippedRules int
	TotalPassedRules  int
	FilesCount        int
	FilesPassedCount  int
}

type Evaluator

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

func New

func New(c CLIClient, ciContext *ciContext.CIContext) *Evaluator

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(policyCheckData PolicyCheckData) (PolicyCheckResultData, error)

func (*Evaluator) SendEvaluationResult

func (e *Evaluator) SendEvaluationResult(evaluationRequestData EvaluationRequestData) (*cliClient.SendEvaluationResultsResponse, error)

type FailedRulesByFiles

type FailedRulesByFiles map[string]map[string]*cliClient.FailedRule

type FileNameRuleMapper

type FileNameRuleMapper map[string]map[string]*Rule

type FormattedEvaluationResults

type FormattedEvaluationResults struct {
	FileName    string        `yaml:"fileName" json:"fileName" xml:"fileName"`
	RuleResults []*RuleResult `yaml:"ruleResults" json:"ruleResults" xml:"ruleResults"`
}

type FormattedOutput

type FormattedOutput struct {
	PolicyValidationResults []*FormattedEvaluationResults   `yaml:"policyValidationResults" json:"policyValidationResults" xml:"policyValidationResults"`
	PolicySummary           *PolicySummary                  `yaml:"policySummary" json:"policySummary" xml:"policySummary"`
	EvaluationSummary       NonInteractiveEvaluationSummary `yaml:"evaluationSummary" json:"evaluationSummary" xml:"evaluationSummary"`
	YamlValidationResults   []*extractor.InvalidFile        `yaml:"yamlValidationResults" json:"yamlValidationResults" xml:"yamlValidationResults"`
	K8sValidationResults    []*extractor.InvalidFile        `yaml:"k8sValidationResults" json:"k8sValidationResults" xml:"k8sValidationResults"`
	LoginUrl                string                          `yaml:"loginUrl" json:"loginUrl" xml:"loginUrl"`
}

type FormattedResults

type FormattedResults struct {
	EvaluationResults               *EvaluationResults
	NonInteractiveEvaluationResults *NonInteractiveEvaluationResults
}

type JUnitOutput

type JUnitOutput struct {
	XMLName    xml.Name    `xml:"testsuites"`
	Name       string      `xml:"name,attr"`
	Tests      int         `xml:"tests,attr"`
	Failures   int         `xml:"failures,attr"`
	Skipped    int         `xml:"skipped,attr"`
	TestSuites []testSuite `xml:"testsuite"`
}

func FormattedOutputToJUnitOutput

func FormattedOutputToJUnitOutput(formattedOutput FormattedOutput, additionalJUnitData AdditionalJUnitData, verbose bool) JUnitOutput

type NonInteractiveEvaluationResults

type NonInteractiveEvaluationResults struct {
	FormattedEvaluationResults []*FormattedEvaluationResults
	PolicySummary              *PolicySummary
}

type NonInteractiveEvaluationSummary

type NonInteractiveEvaluationSummary struct {
	ConfigsCount                int    `yaml:"configsCount" json:"configsCount" xml:"configsCount"`
	FilesCount                  int    `yaml:"filesCount" json:"filesCount" xml:"filesCount"`
	PassedYamlValidationCount   int    `yaml:"passedYamlValidationCount" json:"passedYamlValidationCount" xml:"passedYamlValidationCount"`
	K8sValidation               string `yaml:"k8sValidation" json:"k8sValidation" xml:"k8sValidation"`
	PassedPolicyValidationCount int    `yaml:"passedPolicyValidationCount" json:"passedPolicyValidationCount" xml:"passedPolicyValidationCount"`
}

type OccurrenceDetails

type OccurrenceDetails struct {
	MetadataName     string                      `yaml:"metadataName" json:"metadataName" xml:"metadataName"`
	Kind             string                      `yaml:"kind" json:"kind" xml:"kind"`
	SkipMessage      string                      `yaml:"skipMessage" json:"skipMessage" xml:"skipMessage"`
	Occurrences      int                         `yaml:"occurrences" json:"occurrences" xml:"occurrences"`
	IsSkipped        bool                        `yaml:"isSkipped" json:"isSkipped" xml:"isSkipped"`
	FailureLocations []cliClient.FailureLocation `yaml:"failureLocations" json:"failureLocations" xml:"failureLocations"`
}

type OutputTitle

type OutputTitle int
const (
	EvaluatedConfigurations OutputTitle = iota
	TotalRulesEvaluated
	SeeAll
	TotalRulesPassed
	TotalSkippedRules
	TotalRulesFailed
)

func (OutputTitle) String

func (t OutputTitle) String() string

type PolicyCheckData

type PolicyCheckData struct {
	FilesConfigurations []*extractor.FileConfigurations
	IsInteractiveMode   bool
	PolicyName          string
	Policy              policy_factory.Policy
	Verbose             bool
}

type PolicyCheckResultData

type PolicyCheckResultData struct {
	FormattedResults FormattedResults
	RulesData        []cliClient.RuleData
	FilesData        []cliClient.FileData
	RawResults       FailedRulesByFiles
	RulesCount       int
}

type PolicySummary

type PolicySummary struct {
	PolicyName         string `yaml:"policyName" json:"policyName" xml:"policyName"`
	TotalRulesInPolicy int    `yaml:"totalRulesInPolicy" json:"totalRulesInPolicy" xml:"totalRulesInPolicy"`
	TotalSkippedRules  int    `yaml:"totalSkippedRules" json:"totalSkippedRules" xml:"totalSkippedRules"`
	TotalRulesFailed   int    `yaml:"totalRulesFailed"  json:"totalRulesFailed" xml:"totalRulesFailed"`
	TotalPassedCount   int    `yaml:"totalPassedCount"  json:"totalPassedCount" xml:"totalPassedCount"`
}

type PrintResultsData

type PrintResultsData struct {
	Results               FormattedResults
	AdditionalJUnitData   AdditionalJUnitData
	InvalidYamlFiles      []*extractor.InvalidFile
	InvalidK8sFiles       []*extractor.InvalidFile
	EvaluationSummary     printer.EvaluationSummary
	LoginURL              string
	OutputFormat          string
	Printer               Printer
	K8sVersion            string
	Verbose               bool
	PolicyName            string
	K8sValidationWarnings validation.K8sValidationWarningPerValidFile
	CliVersion            string
	IsCI                  bool
	Quiet                 bool
}

type Printer

type Printer interface {
	GetWarningsText(warnings []printer.Warning, quiet bool) string
	GetSummaryTableText(summary printer.Summary) string
	GetEvaluationSummaryText(summary printer.EvaluationSummary, k8sVersion string) string
}

type Result

type Result = gojsonschema.Result

type Rule

type Rule struct {
	Identifier         string
	Name               string
	MessageOnFailure   string
	DocumentationUrl   string
	OccurrencesDetails []OccurrenceDetails
}

func (*Rule) GetFailedOccurrencesCount

func (rp *Rule) GetFailedOccurrencesCount() int

type RuleResult

type RuleResult struct {
	Identifier         string              `yaml:"identifier" json:"identifier" xml:"identifier"`
	Name               string              `yaml:"name" json:"name" xml:"name"`
	MessageOnFailure   string              `yaml:"messageOnFailure" json:"messageOnFailure" xml:"messageOnFailure"`
	OccurrencesDetails []OccurrenceDetails `yaml:"occurrencesDetails" json:"occurrencesDetails" xml:"occurrencesDetails"`
	DocumentationUrl   string              `yaml:"documentationUrl,omitempty" json:"documentationUrl,omitempty" xml:"documentationUrl,omitempty"`
}

Jump to

Keyboard shortcuts

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