output

package
v0.49.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const (
	OutputStandard    = "stdout"
	OutputJSON        = "json"
	OutputTAP         = "tap"
	OutputTable       = "table"
	OutputJUnit       = "junit"
	OutputGitHub      = "github"
	OutputAzureDevOps = "azuredevops"
)

The defined output formats represent all of the supported formats that can be used to format and render results.

Variables

This section is empty.

Functions

func ExitCode added in v0.22.0

func ExitCode(results []CheckResult) int

ExitCode returns the exit code that should be returned given all of the returned results.

func ExitCodeFailOnWarn added in v0.22.0

func ExitCodeFailOnWarn(results []CheckResult) int

ExitCodeFailOnWarn returns the exit code that should be returned given all of the returned results, and will consider warnings as failures.

func Outputs added in v0.22.0

func Outputs() []string

Outputs returns the available output formats.

Types

type AzureDevOps added in v0.45.0

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

AzureDevOps represents an Outputter that outputs results in AzureDevOps Pipelines format. https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands

func NewAzureDevOps added in v0.45.0

func NewAzureDevOps(w io.Writer) *AzureDevOps

NewAzureDevOps creates a new AzureDevOps with the given writer.

func (*AzureDevOps) Output added in v0.45.0

func (t *AzureDevOps) Output(checkResults []CheckResult) error

Output outputs the results.

func (*AzureDevOps) Report added in v0.45.0

func (t *AzureDevOps) Report(_ []*tester.Result, _ string) error

type CheckResult

type CheckResult struct {
	FileName   string        `json:"filename"`
	Namespace  string        `json:"namespace"`
	Successes  int           `json:"successes"`
	Skipped    []Result      `json:"skipped,omitempty"`
	Warnings   []Result      `json:"warnings,omitempty"`
	Failures   []Result      `json:"failures,omitempty"`
	Exceptions []Result      `json:"exceptions,omitempty"`
	Queries    []QueryResult `json:"queries,omitempty"`
}

CheckResult describes the result of a conftest policy evaluation. Errors produced by rego should be considered separate from other classes of exceptions.

type GitHub added in v0.27.0

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

GitHub represents an Outputter that outputs results in GitHub workflow format. https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions

func NewGitHub added in v0.27.0

func NewGitHub(w io.Writer) *GitHub

NewGitHub creates a new GitHub with the given writer.

func (*GitHub) Output added in v0.27.0

func (t *GitHub) Output(checkResults []CheckResult) error

Output outputs the results.

func (*GitHub) Report added in v0.27.0

func (t *GitHub) Report(_ []*tester.Result, _ string) error

type JSON added in v0.22.0

type JSON struct {
	Writer io.Writer
}

JSON represents an Outputter that outputs results in JSON format.

func NewJSON added in v0.22.0

func NewJSON(w io.Writer) *JSON

NewJSON creates a new JSON with the given writer.

func (*JSON) Output added in v0.22.0

func (j *JSON) Output(results []CheckResult) error

Output outputs the results.

func (*JSON) Report added in v0.26.0

func (j *JSON) Report(_ []*tester.Result, _ string) error

type JUnit added in v0.22.0

type JUnit struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

JUnit represents an Outputter that outputs results in JUnit format.

func NewJUnit added in v0.22.0

func NewJUnit(w io.Writer, hideMessage bool) *JUnit

NewJUnit creates a new JUnit with the given writer.

func (*JUnit) Output added in v0.22.0

func (j *JUnit) Output(results []CheckResult) error

Output outputs the results.

func (*JUnit) Report added in v0.26.0

func (j *JUnit) Report(_ []*tester.Result, _ string) error

type Options added in v0.22.0

type Options struct {
	Tracing            bool
	NoColor            bool
	SuppressExceptions bool
	ShowSkipped        bool
	JUnitHideMessage   bool
	File               *os.File
}

Options represents the options available when configuring an Outputter.

type Outputter added in v0.22.0

type Outputter interface {
	Output([]CheckResult) error
	Report([]*tester.Result, string) error
}

Outputter controls how results of an evaluation will be recorded and reported to the end user.

func Get added in v0.22.0

func Get(format string, options Options) Outputter

Get returns a type that can render output in the given format.

type QueryResult added in v0.22.0

type QueryResult struct {

	// Query is the fully qualified query that was used
	// to determine the result. Ex: (data.main.deny)
	Query string `json:"query"`

	// Results are the individual results of the query.
	// When querying data.main.deny, multiple deny rules can
	// exist, producing multiple results.
	Results []Result `json:"results"`

	// Traces represents a single trace of how the query was
	// evaluated. Each trace value is a trace line.
	Traces []string `json:"traces"`

	// Output represents anything print()'ed during the query
	// evaluation. Each value is a print() call's result.
	Outputs []string `json:"outputs,omitempty"`
}

QueryResult describes the result of evaluting a query.

func (QueryResult) Passed added in v0.22.0

func (q QueryResult) Passed() bool

Passed returns true if all of the results in the query passed and no failures were found.

type Result

type Result struct {
	Message  string                 `json:"msg"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
	Outputs  []string               `json:"outputs,omitempty"`
}

Result describes the result of a single rule evaluation.

func NewResult

func NewResult(metadata map[string]interface{}) (Result, error)

NewResult creates a new result. An error is returned if the metadata could not be successfully parsed.

func (Result) Passed added in v0.22.0

func (r Result) Passed() bool

Passed returns true if the result did not fail a policy.

type Standard added in v0.22.0

type Standard struct {
	Writer io.Writer

	// Tracing will render the trace results of the
	// queries when set to true.
	Tracing bool

	// NoColor will disable all coloring when
	// set to true.
	NoColor bool

	// SuppressExceptions will disable output for exceptions when set to true.
	SuppressExceptions bool

	// ShowSkipped whether to show skipped tests
	// in the output.
	ShowSkipped bool
}

Standard represents an Outputter that outputs results in a human readable format.

func NewStandard added in v0.22.0

func NewStandard(w io.Writer) *Standard

NewStandard creates a new Standard with the given writer.

func (*Standard) Output added in v0.22.0

func (s *Standard) Output(results []CheckResult) error

Output outputs the results.

func (*Standard) Report added in v0.26.0

func (s *Standard) Report(results []*tester.Result, flag string) error

Report outputs results similar to OPA test output

type TAP added in v0.22.0

type TAP struct {
	Writer io.Writer
}

TAP represents an Outputter that outputs results in TAP format.

func NewTAP added in v0.22.0

func NewTAP(w io.Writer) *TAP

NewTAP creates a new TAP with the given writer.

func (*TAP) Output added in v0.22.0

func (t *TAP) Output(checkResults []CheckResult) error

Output outputs the results.

func (*TAP) Report added in v0.26.0

func (t *TAP) Report(_ []*tester.Result, _ string) error

type Table added in v0.22.0

type Table struct {
	Writer io.Writer
}

Table represents an Outputter that outputs results in a tabular format.

func NewTable added in v0.22.0

func NewTable(w io.Writer) *Table

NewTable creates a new Table with the given writer.

func (*Table) Output added in v0.22.0

func (t *Table) Output(checkResults []CheckResult) error

Output outputs the results.

func (*Table) Report added in v0.26.0

func (t *Table) Report(_ []*tester.Result, _ string) error

Jump to

Keyboard shortcuts

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