-
Notifications
You must be signed in to change notification settings - Fork 53
/
validate.go
88 lines (81 loc) · 2.07 KB
/
validate.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
package v1
import (
"github.com/rancher/opni/pkg/validation"
)
func (a *PluginArchive) Validate() error {
for _, item := range a.Items {
if err := item.Validate(); err != nil {
return err
}
}
return nil
}
func (a *PluginArchiveEntry) Validate() error {
if a.Metadata.GetDigest() == "" {
return validation.Error("digest is required for plugin archive entries")
}
if a.Metadata.GetPath() == "" {
return validation.Error("path is required for plugin archive entries")
}
if a.Metadata.GetPackage() == "" {
return validation.Error("module is required for plugin archive entries")
}
if a.Metadata.GetId() == "" {
return validation.Error("id is required for plugin archive entries")
}
return nil
}
func (m *UpdateManifestEntry) Validate() error {
if m.Digest == "" {
return validation.Error("digest is required for plugin manifest entries")
}
if m.Path == "" {
return validation.Error("Path is required for plugin manifest entries")
}
if m.Package == "" {
return validation.Error("Package is required for plugin manifest entries")
}
return nil
}
func (m *UpdateManifest) Validate() error {
for _, item := range m.Items {
if err := item.Validate(); err != nil {
return err
}
}
return nil
}
func (a *PatchSpec) Validate() error {
if a.GetPath() == "" {
return validation.Error("filename must be set")
}
if a.GetPackage() == "" {
return validation.Error("module must be set")
}
switch a.GetOp() {
case PatchOp_Update, PatchOp_Rename:
if a.GetOldDigest() == "" {
return validation.Error("OldHash is required for patching")
}
if a.GetNewDigest() == "" {
return validation.Error("NewHash is required for patching")
}
case PatchOp_Create:
if a.GetNewDigest() == "" {
return validation.Error("NewHash is required for creating")
}
case PatchOp_None, PatchOp_Remove:
if len(a.Data) != 0 {
return validation.Error("no data should be sent alongside a None/Remove operation")
}
}
return nil
}
func (a *PatchList) Validate() error {
for _, patch := range a.Items {
if err := patch.Validate(); err != nil {
return err
}
}
return nil
}