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
/
attributes_validator.go
117 lines (100 loc) · 4.77 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
113
114
115
116
117
package validation
import (
"context"
"fmt"
"github.com/flyteorg/flyteadmin/pkg/errors"
"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
"github.com/flyteorg/flyteadmin/pkg/repositories"
runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
"github.com/flyteorg/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
} else if attributes.GetExecutionClusterLabel() != nil {
return admin.MatchableResource_EXECUTION_CLUSTER_LABEL, nil
} else if attributes.GetPluginOverrides() != nil {
return admin.MatchableResource_PLUGIN_OVERRIDE, nil
} else if attributes.GetWorkflowExecutionConfig() != nil {
return admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG, nil
}
return defaultMatchableResource, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
"Unrecognized matching attributes type for request %s", identifier)
}
func ValidateProjectDomainAttributesUpdateRequest(ctx context.Context,
db repositories.RepositoryInterface, config runtimeInterfaces.ApplicationConfiguration,
request admin.ProjectDomainAttributesUpdateRequest) (
admin.MatchableResource, error) {
if request.Attributes == nil {
return defaultMatchableResource, shared.GetMissingArgumentError(shared.Attributes)
}
if err := ValidateProjectAndDomain(ctx, db, config, request.Attributes.Project, request.Attributes.Domain); err != nil {
return defaultMatchableResource, err
}
return validateMatchingAttributes(request.Attributes.MatchingAttributes,
fmt.Sprintf("%s-%s", request.Attributes.Project, request.Attributes.Domain))
}
func ValidateProjectDomainAttributesGetRequest(ctx context.Context, db repositories.RepositoryInterface,
config runtimeInterfaces.ApplicationConfiguration, request admin.ProjectDomainAttributesGetRequest) error {
if err := ValidateProjectAndDomain(ctx, db, config, request.Project, request.Domain); err != nil {
return err
}
return nil
}
func ValidateProjectDomainAttributesDeleteRequest(ctx context.Context, db repositories.RepositoryInterface,
config runtimeInterfaces.ApplicationConfiguration, request admin.ProjectDomainAttributesDeleteRequest) error {
if err := ValidateProjectAndDomain(ctx, db, config, request.Project, request.Domain); err != nil {
return err
}
return nil
}
func ValidateWorkflowAttributesUpdateRequest(ctx context.Context, db repositories.RepositoryInterface,
config runtimeInterfaces.ApplicationConfiguration, request admin.WorkflowAttributesUpdateRequest) (
admin.MatchableResource, error) {
if request.Attributes == nil {
return defaultMatchableResource, shared.GetMissingArgumentError(shared.Attributes)
}
if err := ValidateProjectAndDomain(ctx, db, config, request.Attributes.Project, request.Attributes.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(ctx context.Context, db repositories.RepositoryInterface,
config runtimeInterfaces.ApplicationConfiguration, request admin.WorkflowAttributesGetRequest) error {
if err := ValidateProjectAndDomain(ctx, db, config, request.Project, request.Domain); err != nil {
return err
}
if err := ValidateEmptyStringField(request.Workflow, shared.Name); err != nil {
return err
}
return nil
}
func ValidateWorkflowAttributesDeleteRequest(ctx context.Context, db repositories.RepositoryInterface,
config runtimeInterfaces.ApplicationConfiguration, request admin.WorkflowAttributesDeleteRequest) error {
if err := ValidateProjectAndDomain(ctx, db, config, request.Project, request.Domain); err != nil {
return err
}
if err := ValidateEmptyStringField(request.Workflow, shared.Name); err != nil {
return err
}
return nil
}
func ValidateListAllMatchableAttributesRequest(request admin.ListMatchableAttributesRequest) error {
if _, ok := admin.MatchableResource_name[int32(request.ResourceType)]; !ok {
return shared.GetInvalidArgumentError(shared.ResourceType)
}
return nil
}