MCPcopy Create free account
hub / github.com/conforma/cli / PopulateResultFromOutput

Function PopulateResultFromOutput

internal/validate/report.go:44–92  ·  view source on GitHub ↗

PopulateResultFromOutput decomposes an output.Output object into a Result object. This is used to convert validation output into a consistent result structure that can be used for report generation.

(
	out *output.Output,
	err error,
	comp app.SnapshotComponent,
	showSuccesses bool,
	outputFormats []string,
)

Source from the content-addressed store, hash-verified

42// This is used to convert validation output into a consistent result structure
43// that can be used for report generation.
44func PopulateResultFromOutput(
45 out *output.Output,
46 err error,
47 comp app.SnapshotComponent,
48 showSuccesses bool,
49 outputFormats []string,
50) Result {
51 res := Result{
52 Err: err,
53 Component: applicationsnapshot.Component{
54 SnapshotComponent: comp,
55 Success: err == nil,
56 },
57 }
58
59 // Only populate from output if there's no error and output exists
60 if err == nil {
61 if out != nil {
62 // Normal validation completed
63 res.Component.Violations = out.Violations()
64 res.Component.Warnings = out.Warnings()
65
66 successes := out.Successes()
67 res.Component.SuccessCount = len(successes)
68 if showSuccesses {
69 res.Component.Successes = successes
70 }
71
72 res.Component.Signatures = out.Signatures
73 // Create a new result object for attestations. The point is to only keep the data that's needed.
74 // For example, the Statement is only needed when the full attestation is printed.
75 for _, att := range out.Attestations {
76 attResult := applicationsnapshot.NewAttestationResult(att)
77 if ContainsOutputFormat(outputFormats, "attestation") {
78 attResult.Statement = att.Statement()
79 }
80 res.Component.Attestations = append(res.Component.Attestations, attResult)
81 }
82 res.Component.ContainerImage = out.ImageURL
83 res.PolicyInput = out.PolicyInput
84 } else {
85 // Validation was skipped due to valid VSA - no violations, no processing needed
86 res.Component.ContainerImage = comp.ContainerImage
87 }
88 }
89 res.Component.Success = err == nil && len(res.Component.Violations) == 0
90
91 return res
92}
93
94// ContainsOutputFormat checks if the specified output format is in the output formats list.
95// It handles formats that may include file paths (e.g., "attestation=/path/to/file").

Callers 2

Calls 6

NewAttestationResultFunction · 0.92
ContainsOutputFormatFunction · 0.85
ViolationsMethod · 0.80
WarningsMethod · 0.80
SuccessesMethod · 0.80
StatementMethod · 0.65

Tested by 1