Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

feat: web format errors #56

Merged
merged 7 commits into from
Oct 25, 2023
9 changes: 7 additions & 2 deletions pkg/container/allowed_base_image_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,22 @@ func (a *AllowedBaseImage) Test() *txqualitychecks.QualityResult {
}
}

return &txqualitychecks.QualityResult{Passed: checkPassed, ErrorDescription: buildErrorDescription(deniedBaseImages)}
return &txqualitychecks.QualityResult{Passed: checkPassed, ErrorDescription: buildErrorDescription(deniedBaseImages, "cli"), ErrorDescriptionWeb: buildErrorDescription(deniedBaseImages, "web") }
}

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 string) string {
tomaszbarwicki marked this conversation as resolved.
Show resolved Hide resolved
if len(deniedImages) == 0 {
return ""
}
if strings.EqualFold(errorFormat, "web") {
return "Dockerfile(s) use not approved images:<br>"+strings.Join(deniedImages,"<br>")
}
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 - ")
Expand Down
8 changes: 4 additions & 4 deletions pkg/helm/helmchart_structure_exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ 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
return &tractusx.QualityResult{ErrorDescription: errMsg, ErrorDescriptionWeb: strings.ReplaceAll(errMsg, "\n", "<br>")}
}
return &tractusx.QualityResult{Passed: true}
}
Expand All @@ -105,14 +105,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()

Expand Down
5 changes: 3 additions & 2 deletions pkg/tractusx/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ type QualityGuideline interface {
// QualityResult implements test result via Passed bool and in case of error a
// ErrorDescription.
type QualityResult struct {
Passed bool
ErrorDescription string
Passed bool
ErrorDescription string
ErrorDescriptionWeb string
tomaszbarwicki marked this conversation as resolved.
Show resolved Hide resolved
}

type Printer interface {
Expand Down
Loading