-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated artifact registry into new validation framework
- Loading branch information
Showing
6 changed files
with
405 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package validation | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/suse-edge/edge-image-builder/pkg/combustion" | ||
"github.com/suse-edge/edge-image-builder/pkg/image" | ||
) | ||
|
||
const ( | ||
registryComponent = "Artifact Registry" | ||
) | ||
|
||
func validateEmbeddedArtefactRegistry(ctx *image.Context) []FailedValidation { | ||
var failures []FailedValidation | ||
def := ctx.ImageDefinition | ||
|
||
if combustion.IsEmbeddedArtifactRegistryEmpty(def.EmbeddedArtifactRegistry) { | ||
return failures | ||
} | ||
|
||
failures = append(failures, validateContainerImages(&ctx.ImageDefinition.EmbeddedArtifactRegistry)...) | ||
failures = append(failures, validateHelmCharts(&ctx.ImageDefinition.EmbeddedArtifactRegistry)...) | ||
|
||
return failures | ||
} | ||
|
||
func validateContainerImages(ear *image.EmbeddedArtifactRegistry) []FailedValidation { | ||
var failures []FailedValidation | ||
|
||
seenContainerImages := make(map[string]bool) | ||
for _, cImage := range ear.ContainerImages { | ||
if cImage.Name == "" { | ||
failures = append(failures, FailedValidation{ | ||
userMessage: "The 'name' field is required for each entry in 'images'.", | ||
component: registryComponent, | ||
}) | ||
} | ||
|
||
if seenContainerImages[cImage.Name] { | ||
msg := fmt.Sprintf("Duplicate image name '%s' found in the 'images' section.", cImage.Name) | ||
failures = append(failures, FailedValidation{ | ||
userMessage: msg, | ||
component: registryComponent, | ||
}) | ||
} | ||
seenContainerImages[cImage.Name] = true | ||
} | ||
|
||
return failures | ||
} | ||
|
||
func validateHelmCharts(ear *image.EmbeddedArtifactRegistry) []FailedValidation { | ||
var failures []FailedValidation | ||
|
||
charts := ear.HelmCharts | ||
seenCharts := make(map[string]bool) | ||
for _, chart := range charts { | ||
if chart.Name == "" { | ||
failures = append(failures, FailedValidation{ | ||
userMessage: "The 'name' field is required for each entry in 'charts'.", | ||
component: registryComponent, | ||
}) | ||
} | ||
|
||
if chart.RepoURL == "" { | ||
failures = append(failures, FailedValidation{ | ||
userMessage: "The 'repoURL' field is required for each entry in 'charts'.", | ||
component: registryComponent, | ||
}) | ||
} else if !strings.HasPrefix(chart.RepoURL, "http") { | ||
failures = append(failures, FailedValidation{ | ||
userMessage: "The 'repoURL' field must begin with either 'http://' or 'https://'.", | ||
component: registryComponent, | ||
}) | ||
} | ||
|
||
if chart.Version == "" { | ||
failures = append(failures, FailedValidation{ | ||
userMessage: "The 'version' field is required for each entry in 'charts'.", | ||
component: registryComponent, | ||
}) | ||
} | ||
|
||
if seenCharts[chart.Name] { | ||
msg := fmt.Sprintf("Duplicate chart name '%s' found in the 'charts' section.", chart.Name) | ||
failures = append(failures, FailedValidation{ | ||
userMessage: msg, | ||
component: registryComponent, | ||
}) | ||
} | ||
seenCharts[chart.Name] = true | ||
} | ||
|
||
return failures | ||
} |
Oops, something went wrong.