diff --git a/pkg/container/allowed_base_image_check.go b/pkg/container/allowed_base_image_check.go
index 8954f05..b4ba6fb 100644
--- a/pkg/container/allowed_base_image_check.go
+++ b/pkg/container/allowed_base_image_check.go
@@ -23,7 +23,7 @@ import (
"fmt"
"strings"
- txqualitychecks "github.com/eclipse-tractusx/tractusx-quality-checks/pkg/tractusx"
+ "github.com/eclipse-tractusx/tractusx-quality-checks/pkg/tractusx"
)
var baseImageAllowList = []string{
@@ -38,7 +38,7 @@ type AllowedBaseImage struct {
baseDir string
}
-func NewAllowedBaseImage(baseDir string) txqualitychecks.QualityGuideline {
+func NewAllowedBaseImage(baseDir string) tractusx.QualityGuideline {
return &AllowedBaseImage{baseDir: baseDir}
}
@@ -54,7 +54,7 @@ func (a *AllowedBaseImage) ExternalDescription() string {
return "https://eclipse-tractusx.github.io/docs/release/trg-4/trg-4-02"
}
-func (a *AllowedBaseImage) Test() *txqualitychecks.QualityResult {
+func (a *AllowedBaseImage) Test() *tractusx.QualityResult {
foundDockerFiles := findDockerfilesAt(a.baseDir)
checkPassed := true
@@ -70,18 +70,25 @@ func (a *AllowedBaseImage) Test() *txqualitychecks.QualityResult {
deniedBaseImages = append(deniedBaseImages, file.baseImage())
}
}
-
- return &txqualitychecks.QualityResult{Passed: checkPassed, ErrorDescription: buildErrorDescription(deniedBaseImages)}
+ if tractusx.ErrorOutputFormat == tractusx.WebErrOutputFormat {
+ return &tractusx.QualityResult{Passed: checkPassed, ErrorDescription: buildErrorDescription(deniedBaseImages, tractusx.WebErrOutputFormat)}
+ }
+ return &tractusx.QualityResult{Passed: checkPassed, ErrorDescription: buildErrorDescription(deniedBaseImages, tractusx.CliErrOutputFormat)}
}
func (a *AllowedBaseImage) IsOptional() bool {
return false
}
-func buildErrorDescription(deniedImages []string) string {
+// Function to return error message of failed test.
+// There are two types of formatting: cli (default) and web
+func buildErrorDescription(deniedImages []string, errorFormat int) string {
if len(deniedImages) == 0 {
return ""
}
+ if errorFormat == tractusx.WebErrOutputFormat {
+ return "Dockerfile(s) use not approved images:
" + strings.Join(deniedImages, "
")
+ }
return "We want to align on docker base images. We detected a Dockerfile specifying " +
strings.Join(deniedImages, ", ") + "\n\tAllowed images are: \n\t - " +
strings.Join(baseImageAllowList, "\n\t - ")
diff --git a/pkg/helm/helmchart_structure_exists.go b/pkg/helm/helmchart_structure_exists.go
index 6aeab2a..4cb33da 100644
--- a/pkg/helm/helmchart_structure_exists.go
+++ b/pkg/helm/helmchart_structure_exists.go
@@ -89,8 +89,11 @@ func (r *HelmStructureExists) Test() *tractusx.QualityResult {
}
if len(missingFiles) > 0 || !chartsValid {
- return &tractusx.QualityResult{ErrorDescription: "+ Following Helm Chart structure files are missing: " + strings.Join(missingFiles, ", ") +
- errorDescriptionCharts}
+ errMsg := "+ Following Helm Chart structure files are missing: " + strings.Join(missingFiles, ", ") + errorDescriptionCharts
+ if tractusx.ErrorOutputFormat == tractusx.WebErrOutputFormat {
+ return &tractusx.QualityResult{ErrorDescription: strings.ReplaceAll(errMsg, "\n", "
")}
+ }
+ return &tractusx.QualityResult{ErrorDescription: errMsg}
}
return &tractusx.QualityResult{Passed: true}
}
@@ -105,14 +108,14 @@ func getMissingChartFiles(chartPath string, missingFiles *[]string) {
for _, fileToCheck := range helmStructureFiles {
missingFile := filesystem.CheckMissingFiles([]string{path.Join(chartPath, fileToCheck)})
if missingFile != nil {
- *missingFiles = append(*missingFiles, missingFile...)
+ *missingFiles = append(*missingFiles, []string{strings.Split(missingFile[0], "charts")[1][1:]}...)
}
}
}
func validateChart(chartyamlfile string) (bool, string) {
isValid := true
- returnMessage := "\n\t+ Analysis for " + chartyamlfile + ": "
+ returnMessage := "\n\t+ Analysis for " + strings.Split(chartyamlfile, "charts")[1][1:] + ": "
cyf := helm.ChartYamlFromFile(chartyamlfile)
missingFields := cyf.GetMissingMandatoryFields()
diff --git a/pkg/tractusx/types.go b/pkg/tractusx/types.go
index febe516..62b1abc 100644
--- a/pkg/tractusx/types.go
+++ b/pkg/tractusx/types.go
@@ -49,3 +49,10 @@ type Printer interface {
LogWarning(warning string)
LogError(err string)
}
+
+var ErrorOutputFormat = CliErrOutputFormat
+
+const (
+ CliErrOutputFormat = iota
+ WebErrOutputFormat = iota
+)