Documentation
¶
Overview ¶
Package output holds various output options
Package output provides formatters for Reglet execution results.
Index ¶
- type BaseOutputOption
- type ControlResult
- type EvidenceMeta
- type ExecutionResult
- type ExpectationResult
- type FactoryOptions
- type FormatterFactory
- type JSONFormatter
- type JSONOption
- type JUnitError
- type JUnitFailure
- type JUnitFormatter
- type JUnitOption
- type JUnitSkipped
- type JUnitTestCase
- type JUnitTestSuite
- type JUnitTestSuites
- type ObservationResult
- type PluginError
- type SARIFFormatter
- type SARIFOption
- type Summary
- type TableFormatter
- type TableOption
- type YAMLFormatter
- type YAMLOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseOutputOption ¶
type BaseOutputOption func(*baseOutputConfig)
BaseOutputOption configures common formatter behavior.
func WithIndent ¶
func WithIndent(enabled bool) BaseOutputOption
WithIndent enables indented/pretty-printed output.
type ControlResult ¶
type ControlResult struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Severity string `json:"severity,omitempty" yaml:"severity,omitempty"`
Status values.Status `json:"status" yaml:"status"`
Message string `json:"message,omitempty" yaml:"message,omitempty"`
SkipReason string `json:"skip_reason,omitempty" yaml:"skip_reason,omitempty"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
Observations []ObservationResult `json:"observations" yaml:"observations"`
Index int `json:"index" yaml:"index"`
Duration time.Duration `json:"duration_ms" yaml:"duration_ms"`
}
ControlResult represents the serialization format for a control result.
type EvidenceMeta ¶
type EvidenceMeta struct {
Reason string `json:"reason,omitempty" yaml:"reason,omitempty"`
OriginalSize int `json:"original_size_bytes" yaml:"original_size_bytes"`
TruncatedAt int `json:"truncated_at_bytes" yaml:"truncated_at_bytes"`
Truncated bool `json:"truncated" yaml:"truncated"`
}
EvidenceMeta represents the serialization format for evidence metadata.
type ExecutionResult ¶
type ExecutionResult struct {
StartTime time.Time `json:"start_time" yaml:"start_time"`
EndTime time.Time `json:"end_time" yaml:"end_time"`
RegletVersion string `json:"reglet_version,omitempty" yaml:"reglet_version,omitempty"`
ProfileName string `json:"profile_name" yaml:"profile_name"`
ProfileVersion string `json:"profile_version" yaml:"profile_version"`
Controls []ControlResult `json:"controls" yaml:"controls"`
Summary Summary `json:"summary" yaml:"summary"`
Version int `json:"version" yaml:"version"`
Duration time.Duration `json:"duration_ms" yaml:"duration_ms"`
ExecutionID values.ExecutionID `json:"execution_id" yaml:"execution_id"`
}
ExecutionResult represents the serialization format for execution results. This is the wire format for JSON/YAML output.
func FromDomain ¶
func FromDomain(r *execution.ExecutionResult) *ExecutionResult
FromDomain converts a domain ExecutionResult to an output DTO.
type ExpectationResult ¶
type ExpectationResult struct {
Expression string `json:"expression" yaml:"expression"`
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Passed bool `json:"passed" yaml:"passed"`
}
ExpectationResult represents the serialization format for an expectation result.
type FactoryOptions ¶
type FactoryOptions struct {
ProfilePath string
EvidenceDir string
Indent bool
Verbose bool
NoColor bool
}
FactoryOptions holds CLI-provided options for formatter creation. This is an infrastructure concern, not exposed through ports.
type FormatterFactory ¶
type FormatterFactory struct{}
FormatterFactory implements ports.OutputFormatterFactory.
func NewFormatterFactory ¶
func NewFormatterFactory() *FormatterFactory
NewFormatterFactory creates a new formatter factory.
func (*FormatterFactory) Create ¶
func (f *FormatterFactory) Create( format string, writer io.Writer, options interface{}, ) (ports.OutputFormatter, error)
Create returns a formatter for the given format name. options should be of type FactoryOptions or nil.
func (*FormatterFactory) SupportedFormats ¶
func (f *FormatterFactory) SupportedFormats() []string
SupportedFormats returns list of available format names.
type JSONFormatter ¶
type JSONFormatter struct {
// contains filtered or unexported fields
}
JSONFormatter formats execution results as JSON.
func NewJSONFormatter ¶
func NewJSONFormatter(w io.Writer, opts ...JSONOption) *JSONFormatter
NewJSONFormatter creates a new JSON formatter. If no options are provided, defaults to indented output.
func (*JSONFormatter) Format ¶
func (f *JSONFormatter) Format(result *execution.ExecutionResult) error
Format writes the execution result as JSON.
type JSONOption ¶
type JSONOption func(*JSONFormatter)
JSONOption configures the JSON formatter.
func WithJSONIndent ¶
func WithJSONIndent(enabled bool) JSONOption
WithJSONIndent sets indentation for JSON output.
type JUnitError ¶
JUnitError represents a test case that encountered an error.
type JUnitFailure ¶
JUnitFailure represents a failed test case.
type JUnitFormatter ¶
type JUnitFormatter struct {
// contains filtered or unexported fields
}
JUnitFormatter formats execution results as JUnit XML.
func NewJUnitFormatter ¶
func NewJUnitFormatter(w io.Writer, opts ...JUnitOption) *JUnitFormatter
NewJUnitFormatter creates a new JUnit formatter.
func (*JUnitFormatter) Format ¶
func (f *JUnitFormatter) Format(result *execution.ExecutionResult) error
Format writes the execution result as JUnit XML.
type JUnitOption ¶
type JUnitOption func(*JUnitFormatter)
JUnitOption configures the JUnit formatter.
type JUnitSkipped ¶
type JUnitSkipped struct {
Message string `xml:"message,attr,omitempty"`
}
JUnitSkipped represents a skipped test case.
type JUnitTestCase ¶
type JUnitTestCase struct {
Failure *JUnitFailure `xml:"failure,omitempty"`
Error *JUnitError `xml:"error,omitempty"`
Skipped *JUnitSkipped `xml:"skipped,omitempty"`
XMLName xml.Name `xml:"testcase"`
Name string `xml:"name,attr"`
ClassName string `xml:"classname,attr"`
Time float64 `xml:"time,attr"`
}
JUnitTestCase represents a single test case in JUnit XML.
type JUnitTestSuite ¶
type JUnitTestSuite struct {
XMLName xml.Name `xml:"testsuite"`
Name string `xml:"name,attr"`
TestCases []JUnitTestCase `xml:"testcase"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Errors int `xml:"errors,attr"`
Skipped int `xml:"skipped,attr"`
Time float64 `xml:"time,attr"`
}
JUnitTestSuite represents a single test suite in JUnit XML.
type JUnitTestSuites ¶
type JUnitTestSuites struct {
XMLName xml.Name `xml:"testsuites"`
Name string `xml:"name,attr"`
TestSuites []JUnitTestSuite `xml:"testsuite"`
Tests int `xml:"tests,attr"`
Failures int `xml:"failures,attr"`
Errors int `xml:"errors,attr"`
Time float64 `xml:"time,attr"`
}
JUnitTestSuites JUnit XML structures
type ObservationResult ¶
type ObservationResult struct {
Config map[string]any `json:"config" yaml:"config"`
Evidence *execution.Evidence `json:"evidence,omitempty" yaml:"evidence,omitempty"`
EvidenceMeta *EvidenceMeta `json:"evidence_meta,omitempty" yaml:"evidence_meta,omitempty"`
Error *PluginError `json:"error,omitempty" yaml:"error,omitempty"`
Plugin string `json:"plugin" yaml:"plugin"`
Status values.Status `json:"status" yaml:"status"`
Expectations []ExpectationResult `json:"expectations,omitempty" yaml:"expectations,omitempty"`
Duration time.Duration `json:"duration_ms" yaml:"duration_ms"`
}
ObservationResult represents the serialization format for an observation result.
type PluginError ¶
type PluginError struct {
Code string `json:"code" yaml:"code"`
Message string `json:"message" yaml:"message"`
}
PluginError represents the serialization format for plugin errors.
type SARIFFormatter ¶
type SARIFFormatter struct {
// contains filtered or unexported fields
}
SARIFFormatter formats execution results as SARIF 2.1.0 JSON. It maps Reglet controls to SARIF rules and observations to results with locations.
Usage:
formatter := output.NewSARIFFormatter(os.Stdout, WithProfilePath("profile.yaml"))
if err := formatter.Format(result); err != nil {
log.Fatal(err)
}
func NewSARIFFormatter ¶
func NewSARIFFormatter(w io.Writer, opts ...SARIFOption) *SARIFFormatter
NewSARIFFormatter creates a new SARIF formatter.
func (*SARIFFormatter) Format ¶
func (f *SARIFFormatter) Format(result *execution.ExecutionResult) error
Format writes the execution result as SARIF 2.1.0 JSON. Returns error if SARIF creation or marshaling fails.
type SARIFOption ¶
type SARIFOption func(*SARIFFormatter)
SARIFOption configures the SARIF formatter.
func WithProfilePath ¶
func WithProfilePath(path string) SARIFOption
WithProfilePath sets the profile path for SARIF location resolution.
type Summary ¶
type Summary struct {
TotalControls int `json:"total_controls" yaml:"total_controls"`
PassedControls int `json:"passed_controls" yaml:"passed_controls"`
FailedControls int `json:"failed_controls" yaml:"failed_controls"`
ErrorControls int `json:"error_controls" yaml:"error_controls"`
SkippedControls int `json:"skipped_controls" yaml:"skipped_controls"`
TotalObservations int `json:"total_observations" yaml:"total_observations"`
PassedObservations int `json:"passed_observations" yaml:"passed_observations"`
FailedObservations int `json:"failed_observations" yaml:"failed_observations"`
ErrorObservations int `json:"error_observations" yaml:"error_observations"`
}
Summary represents the serialization format for execution summary.
type TableFormatter ¶
type TableFormatter struct {
EnableColor bool
// contains filtered or unexported fields
}
TableFormatter formats execution results as a human-readable table.
func NewTableFormatter ¶
func NewTableFormatter(w io.Writer, opts ...TableOption) *TableFormatter
NewTableFormatter creates a new table formatter.
func (*TableFormatter) Format ¶
func (f *TableFormatter) Format(result *execution.ExecutionResult) error
Format writes the execution result as a table.
type TableOption ¶
type TableOption func(*TableFormatter)
TableOption configures the table formatter.
func WithNoColor ¶
func WithNoColor(disabled bool) TableOption
WithNoColor disables color output in the table formatter.
type YAMLFormatter ¶
type YAMLFormatter struct {
// contains filtered or unexported fields
}
YAMLFormatter formats execution results as YAML.
func NewYAMLFormatter ¶
func NewYAMLFormatter(w io.Writer, opts ...YAMLOption) *YAMLFormatter
NewYAMLFormatter creates a new YAML formatter.
func (*YAMLFormatter) Format ¶
func (f *YAMLFormatter) Format(result *execution.ExecutionResult) error
Format writes the execution result as YAML.