-
Notifications
You must be signed in to change notification settings - Fork 21
/
validation.go
54 lines (43 loc) · 1.26 KB
/
validation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package validation
import (
"github.com/suse-edge/edge-image-builder/pkg/image"
)
type FailedValidation struct {
UserMessage string
Error error
}
type validateComponent func(ctx *image.Context) []FailedValidation
func ValidateDefinition(ctx *image.Context) map[string][]FailedValidation {
failures := map[string][]FailedValidation{}
schemaValidationFailure := validateAPIVersion(ctx)
if schemaValidationFailure != nil {
// If the schema is invalid, there's no reason to even attempt the rest of
// the validation
failures[apiVersionComponent] = []FailedValidation{*schemaValidationFailure}
return failures
}
validations := map[string]validateComponent{
imageComponent: validateImage,
osComponent: validateOperatingSystem,
registryComponent: validateEmbeddedArtifactRegistry,
k8sComponent: validateKubernetes,
}
for componentName, v := range validations {
componentFailures := v(ctx)
if len(componentFailures) > 0 {
failures[componentName] = componentFailures
}
}
return failures
}
func findDuplicates(items []string) []string {
var duplicates []string
seen := make(map[string]bool)
for _, item := range items {
if seen[item] {
duplicates = append(duplicates, item)
}
seen[item] = true
}
return duplicates
}