-
Notifications
You must be signed in to change notification settings - Fork 53
/
validation.go
112 lines (101 loc) · 2.51 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package v1
import (
"encoding/json"
"fmt"
"github.com/rancher/opni/pkg/validation"
)
func (r *CreateBootstrapTokenRequest) Validate() error {
if err := r.GetTtl().CheckValid(); err != nil {
return fmt.Errorf("%w (ttl): %s", validation.ErrInvalidValue, err.Error())
}
if r.GetTtl().AsDuration() <= 0 {
return fmt.Errorf("%w: %s", validation.ErrInvalidValue, "ttl cannot be negative or zero")
}
if err := validation.ValidateLabels(r.GetLabels()); err != nil {
return err
}
for _, cap := range r.GetCapabilities() {
if err := validation.Validate(cap); err != nil {
return err
}
}
return nil
}
func (r *ListClustersRequest) Validate() error {
if r.MatchLabels != nil {
if err := validation.Validate(r.MatchLabels); err != nil {
return err
}
}
if err := validation.Validate(r.MatchOptions); err != nil {
return err
}
return nil
}
func (r *EditClusterRequest) Validate() error {
if r.Cluster == nil {
return fmt.Errorf("%w: %s", validation.ErrMissingRequiredField, "cluster")
}
if err := validation.Validate(r.Cluster); err != nil {
return err
}
if err := validation.ValidateLabels(r.GetLabels()); err != nil {
return err
}
return nil
}
func (r *WatchClustersRequest) Validate() error {
for _, c := range r.GetKnownClusters().GetItems() {
if err := validation.Validate(c); err != nil {
return err
}
}
return nil
}
func (r *UpdateConfigRequest) Validate() error {
if len(r.Documents) == 0 {
return fmt.Errorf("%w: %s", validation.ErrMissingRequiredField, "documents")
}
for i, doc := range r.Documents {
if ok := json.Valid(doc.Json); !ok {
return fmt.Errorf("%w: malformed json in document %d", validation.ErrInvalidValue, i)
}
}
return nil
}
func (r *CapabilityInstallRequest) Validate() error {
if err := validation.ValidateID(r.Name); err != nil {
return err
}
if err := validation.Validate(r.Target); err != nil {
return err
}
return nil
}
func (r *CapabilityUninstallRequest) Validate() error {
if err := validation.ValidateID(r.Name); err != nil {
return err
}
if err := validation.Validate(r.Target); err != nil {
return err
}
return nil
}
func (r *CapabilityStatusRequest) Validate() error {
if err := validation.ValidateID(r.Name); err != nil {
return err
}
if err := validation.Validate(r.Cluster); err != nil {
return err
}
return nil
}
func (r *CapabilityUninstallCancelRequest) Validate() error {
if err := validation.ValidateID(r.Name); err != nil {
return err
}
if err := validation.Validate(r.Cluster); err != nil {
return err
}
return nil
}