-
Notifications
You must be signed in to change notification settings - Fork 1
/
validation.go
44 lines (39 loc) · 1.12 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
package validation
import (
"fmt"
"git.containerum.net/ch/solutions/pkg/solerrors"
"github.com/containerum/cherry"
kube_types "github.com/containerum/kube-client/pkg/model"
)
const (
fieldShouldExist = "field %v should be provided"
)
func ValidateTemplate(template kube_types.SolutionTemplate) *cherry.Err {
valerrs := []error{}
if template.Name == "" {
valerrs = append(valerrs, fmt.Errorf(fieldShouldExist, "Name"))
}
if len(template.URL) == 0 {
valerrs = append(valerrs, fmt.Errorf(fieldShouldExist, "URL"))
}
if len(valerrs) > 0 {
return solerrors.ErrRequestValidationFailed().AddDetailsErr(valerrs...)
}
return nil
}
func ValidateSolution(solution kube_types.Solution) *cherry.Err {
valerrs := []error{}
if solution.Template == "" {
valerrs = append(valerrs, fmt.Errorf(fieldShouldExist, "Template"))
}
if solution.Name == "" {
valerrs = append(valerrs, fmt.Errorf(fieldShouldExist, "Name"))
}
if solution.Namespace == "" {
valerrs = append(valerrs, fmt.Errorf(fieldShouldExist, "Namespace"))
}
if len(valerrs) > 0 {
return solerrors.ErrRequestValidationFailed().AddDetailsErr(valerrs...)
}
return nil
}