forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 6
/
validation.go
40 lines (30 loc) · 1.11 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
package validation
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/openshift/origin/pkg/image/api"
)
// ValidateImage tests required fields for an Image.
func ValidateImage(image *api.Image) errors.ErrorList {
result := errors.ErrorList{}
if len(image.ID) == 0 {
result = append(result, errors.NewFieldRequired("ID", image.ID))
}
if len(image.DockerImageReference) == 0 {
result = append(result, errors.NewFieldRequired("DockerImageReference", image.DockerImageReference))
}
return result
}
// ValidateImageRepositoryMapping tests required fields for an ImageRepositoryMapping.
func ValidateImageRepositoryMapping(mapping *api.ImageRepositoryMapping) errors.ErrorList {
result := errors.ErrorList{}
if len(mapping.DockerImageRepository) == 0 {
result = append(result, errors.NewFieldRequired("DockerImageRepository", mapping.DockerImageRepository))
}
if len(mapping.Tag) == 0 {
result = append(result, errors.NewFieldRequired("Tag", mapping.Tag))
}
for _, err := range ValidateImage(&mapping.Image).Prefix("image") {
result = append(result, err)
}
return result
}