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 62
/
named_entity_validator.go
58 lines (52 loc) · 1.81 KB
/
named_entity_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
package validation
import (
"github.com/flyteorg/flyteadmin/pkg/errors"
"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"google.golang.org/grpc/codes"
"k8s.io/apimachinery/pkg/util/sets"
)
var archivableResourceTypes = sets.NewInt32(int32(core.ResourceType_WORKFLOW), int32(core.ResourceType_TASK))
func ValidateNamedEntityGetRequest(request admin.NamedEntityGetRequest) error {
if err := ValidateResourceType(request.ResourceType); err != nil {
return err
}
if err := ValidateNamedEntityIdentifier(request.Id); err != nil {
return err
}
return nil
}
func ValidateNamedEntityUpdateRequest(request admin.NamedEntityUpdateRequest) error {
if err := ValidateResourceType(request.ResourceType); err != nil {
return err
}
if err := ValidateNamedEntityIdentifier(request.Id); err != nil {
return err
}
if request.Metadata == nil {
return shared.GetMissingArgumentError(shared.Metadata)
}
// Only tasks and workflow resources can be modified from the default state.
if request.Metadata.State != admin.NamedEntityState_NAMED_ENTITY_ACTIVE &&
!archivableResourceTypes.Has(int32(request.ResourceType)) {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument,
"Resource [%s] cannot have its state updated", request.ResourceType.String())
}
return nil
}
func ValidateNamedEntityListRequest(request admin.NamedEntityListRequest) 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 := ValidateResourceType(request.ResourceType); err != nil {
return err
}
if err := ValidateLimit(request.Limit); err != nil {
return err
}
return nil
}