This repository was archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathsignal_validator.go
More file actions
87 lines (75 loc) · 2.65 KB
/
signal_validator.go
File metadata and controls
87 lines (75 loc) · 2.65 KB
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
package validation
import (
"context"
"github.com/flyteorg/flyteadmin/pkg/errors"
"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
repositoryInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
"github.com/flyteorg/flyteidl/clients/go/coreutils"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"google.golang.org/grpc/codes"
)
func ValidateSignalGetOrCreateRequest(ctx context.Context, request admin.SignalGetOrCreateRequest) error {
if request.Id == nil {
return shared.GetMissingArgumentError("id")
}
if err := ValidateSignalIdentifier(*request.Id); err != nil {
return err
}
if request.Type == nil {
return shared.GetMissingArgumentError("type")
}
return nil
}
func ValidateSignalIdentifier(identifier core.SignalIdentifier) error {
if identifier.ExecutionId == nil {
return shared.GetMissingArgumentError(shared.ExecutionID)
}
if identifier.SignalId == "" {
return shared.GetMissingArgumentError("signal_id")
}
return ValidateWorkflowExecutionIdentifier(identifier.ExecutionId)
}
func ValidateSignalListRequest(ctx context.Context, request admin.SignalListRequest) error {
if err := ValidateWorkflowExecutionIdentifier(request.WorkflowExecutionId); err != nil {
return shared.GetMissingArgumentError(shared.ExecutionID)
}
if err := ValidateLimit(request.Limit); err != nil {
return err
}
return nil
}
func ValidateSignalSetRequest(ctx context.Context, db repositoryInterfaces.Repository, request admin.SignalSetRequest) error {
if request.Id == nil {
return shared.GetMissingArgumentError("id")
}
if err := ValidateSignalIdentifier(*request.Id); err != nil {
return err
}
if request.Value == nil {
return shared.GetMissingArgumentError("value")
}
// validate that signal value matches type of existing signal
signalModel, err := transformers.CreateSignalModel(request.Id, nil, nil)
if err != nil {
return nil
}
lookupSignalModel, err := db.SignalRepo().Get(ctx, signalModel.SignalKey)
if err != nil {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument,
"failed to validate that signal [%v] exists, err: [%+v]",
signalModel.SignalKey, err)
}
valueType := coreutils.LiteralTypeForLiteral(request.Value)
lookupSignal, err := transformers.FromSignalModel(lookupSignalModel)
if err != nil {
return err
}
if !coreutils.AreTypesCastable(lookupSignal.Type, valueType) {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument,
"requested signal value [%v] is not castable to existing signal type [%v]",
request.Value, lookupSignalModel.Type)
}
return nil
}