diff --git a/plugins/ci/CHANGELOG.md b/plugins/ci/CHANGELOG.md index 6c58c9ed7..cc75a8d3e 100644 --- a/plugins/ci/CHANGELOG.md +++ b/plugins/ci/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 5.3.1 +* Print soft-errors to output to increase error awareness + ## 5.3.0 * Added files that were modified to CI scan response diff --git a/plugins/ci/pkg/ci/ci.go b/plugins/ci/pkg/ci/ci.go index a6fbcea45..74a9e5dee 100644 --- a/plugins/ci/pkg/ci/ci.go +++ b/plugins/ci/pkg/ci/ci.go @@ -687,6 +687,7 @@ func (ci *CIScan) ProcessRepository() ([]*models.ReportInfo, error) { } if len(scanErrorsReportProperties.Items) > 0 { + printScanErrors(scanErrorsReportProperties) scanErrorsReport, err := ci.processScanErrorsReportProperties(scanErrorsReportProperties) if err != nil { return nil, fmt.Errorf("unable to process scan errors report items: %w", err) @@ -806,3 +807,10 @@ func createFileFromConfig(path, filename string, cfg models.Configuration) error } return nil } + +func printScanErrors(scanErrorReport models.ScanErrorsReportProperties) { + fmt.Println("Scan Errors(these are soft errors that do not prevent the scan from completing):") + for _, r := range scanErrorReport.Items { + fmt.Println("\t- " + createErrorItemMessage(r)) + } +} diff --git a/plugins/ci/pkg/ci/scan-errors.go b/plugins/ci/pkg/ci/scan-errors.go index c3231ea07..c6227478c 100644 --- a/plugins/ci/pkg/ci/scan-errors.go +++ b/plugins/ci/pkg/ci/scan-errors.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/fairwindsops/insights-plugins/plugins/ci/pkg/models" ) @@ -30,3 +31,28 @@ func (ci *CIScan) processScanErrorsReportProperties(reportProperties models.Scan } return report, nil } + +func createErrorItemMessage(r models.ScanErrorsReportResult) string { + var sb strings.Builder + if r.ErrorContext != "" { + sb.WriteString(r.ErrorContext) + sb.WriteString("/") + } + if r.Kind != "" { + sb.WriteString(r.Kind) + sb.WriteString("/") + } + if r.ResourceName != "" { + sb.WriteString(r.ResourceName) + } + if sb.Len() > 0 { + sb.WriteString(" - ") + } + sb.WriteString(r.ErrorMessage) + if r.Filename != "" { + sb.WriteString(" (") + sb.WriteString(r.Filename) + sb.WriteString(")") + } + return sb.String() +} diff --git a/plugins/ci/pkg/ci/scan-errors_test.go b/plugins/ci/pkg/ci/scan-errors_test.go new file mode 100644 index 000000000..dcdc7abee --- /dev/null +++ b/plugins/ci/pkg/ci/scan-errors_test.go @@ -0,0 +1,22 @@ +package ci + +import ( + "testing" + + "github.com/fairwindsops/insights-plugins/plugins/ci/pkg/models" + "github.com/stretchr/testify/assert" +) + +func TestAddScanErrorsReportResultFromAMultiError(t *testing.T) { + assert.Equal(t, "context from the first error/deployment/myapp - an error with additional context (deployment.yaml)", + createErrorItemMessage(models.ScanErrorsReportResult{ + ErrorMessage: "an error with additional context", + ErrorContext: "context from the first error", + Kind: "deployment", + ResourceName: "myapp", + Severity: 2.0, + Category: "Security", + Remediation: "fix the deployment", + Filename: "deployment.yaml", + })) +} diff --git a/plugins/ci/version.txt b/plugins/ci/version.txt index 03f488b07..c7cb1311a 100644 --- a/plugins/ci/version.txt +++ b/plugins/ci/version.txt @@ -1 +1 @@ -5.3.0 +5.3.1