This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathattributes_validator.go
112 lines (96 loc) · 3.9 KB
/
attributes_validator.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 validation
import (
"fmt"
"github.com/lyft/flyteadmin/pkg/errors"
"github.com/lyft/flyteadmin/pkg/manager/impl/shared"
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin"
"google.golang.org/grpc/codes"
)
var defaultMatchableResource = admin.MatchableResource(-1)
func validateMatchingAttributes(attributes *admin.MatchingAttributes, identifier string) (admin.MatchableResource, error) {
if attributes == nil {
return defaultMatchableResource, shared.GetMissingArgumentError(shared.MatchingAttributes)
}
if attributes.GetTaskResourceAttributes() != nil {
return admin.MatchableResource_TASK_RESOURCE, nil
} else if attributes.GetClusterResourceAttributes() != nil {
return admin.MatchableResource_CLUSTER_RESOURCE, nil
} else if attributes.GetExecutionQueueAttributes() != nil {
return admin.MatchableResource_EXECUTION_QUEUE, nil
}
return defaultMatchableResource, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
"Unrecognized matching attributes type for request %s", identifier)
}
func ValidateProjectDomainAttributesUpdateRequest(request admin.ProjectDomainAttributesUpdateRequest) (
admin.MatchableResource, error) {
if request.Attributes == nil {
return defaultMatchableResource, shared.GetMissingArgumentError(shared.Attributes)
}
if err := ValidateEmptyStringField(request.Attributes.Project, shared.Project); err != nil {
return defaultMatchableResource, err
}
if err := ValidateEmptyStringField(request.Attributes.Domain, shared.Domain); err != nil {
return defaultMatchableResource, err
}
return validateMatchingAttributes(request.Attributes.MatchingAttributes,
fmt.Sprintf("%s-%s", request.Attributes.Project, request.Attributes.Domain))
}
func ValidateProjectDomainAttributesGetRequest(request admin.ProjectDomainAttributesGetRequest) error {
if err := ValidateEmptyStringField(request.Project, shared.Project); err != nil {
return err
}
if err := ValidateEmptyStringField(request.Domain, shared.Domain); err != nil {
return err
}
return nil
}
func ValidateProjectDomainAttributesDeleteRequest(request admin.ProjectDomainAttributesDeleteRequest) error {
if err := ValidateEmptyStringField(request.Project, shared.Project); err != nil {
return err
}
if err := ValidateEmptyStringField(request.Domain, shared.Domain); err != nil {
return err
}
return nil
}
func ValidateWorkflowAttributesUpdateRequest(request admin.WorkflowAttributesUpdateRequest) (
admin.MatchableResource, error) {
if request.Attributes == nil {
return defaultMatchableResource, shared.GetMissingArgumentError(shared.Attributes)
}
if err := ValidateEmptyStringField(request.Attributes.Project, shared.Project); err != nil {
return defaultMatchableResource, err
}
if err := ValidateEmptyStringField(request.Attributes.Domain, shared.Domain); err != nil {
return defaultMatchableResource, err
}
if err := ValidateEmptyStringField(request.Attributes.Workflow, shared.Name); err != nil {
return defaultMatchableResource, err
}
return validateMatchingAttributes(request.Attributes.MatchingAttributes,
fmt.Sprintf("%s-%s-%s", request.Attributes.Project, request.Attributes.Domain, request.Attributes.Workflow))
}
func ValidateWorkflowAttributesGetRequest(request admin.WorkflowAttributesGetRequest) error {
if err := ValidateEmptyStringField(request.Project, shared.Project); err != nil {
return err
}
if err := ValidateEmptyStringField(request.Domain, shared.Domain); err != nil {
return err
}
if err := ValidateEmptyStringField(request.Workflow, shared.Name); err != nil {
return err
}
return nil
}
func ValidateWorkflowAttributesDeleteRequest(request admin.WorkflowAttributesDeleteRequest) error {
if err := ValidateEmptyStringField(request.Project, shared.Project); err != nil {
return err
}
if err := ValidateEmptyStringField(request.Domain, shared.Domain); err != nil {
return err
}
if err := ValidateEmptyStringField(request.Workflow, shared.Name); err != nil {
return err
}
return nil
}