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 60
/
inputs.go
53 lines (44 loc) · 1.49 KB
/
inputs.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
package k8s
import (
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core"
"github.com/lyft/flytepropeller/pkg/compiler/common"
"github.com/lyft/flytepropeller/pkg/compiler/errors"
"github.com/lyft/flytepropeller/pkg/compiler/validators"
"k8s.io/apimachinery/pkg/util/sets"
)
func validateInputs(nodeID common.NodeID, iface *core.TypedInterface, inputs core.LiteralMap, errs errors.CompileErrors) (ok bool) {
if iface == nil {
errs.Collect(errors.NewValueRequiredErr(nodeID, "interface"))
return
}
if iface.Inputs == nil {
errs.Collect(errors.NewValueRequiredErr(nodeID, "interface.InputsRef"))
return
}
varMap := make(map[string]*core.Variable, len(iface.Inputs.Variables))
requiredInputsSet := sets.String{}
for name, v := range iface.Inputs.Variables {
varMap[name] = v
requiredInputsSet.Insert(name)
}
boundInputsSet := sets.String{}
for inputVar, inputVal := range inputs.Literals {
v, exists := varMap[inputVar]
if !exists {
errs.Collect(errors.NewVariableNameNotFoundErr(nodeID, "", inputVar))
continue
}
inputType := validators.LiteralTypeForLiteral(inputVal)
if !validators.AreTypesCastable(inputType, v.Type) {
errs.Collect(errors.NewMismatchingTypesErr(nodeID, inputVar, v.Type.String(), inputType.String()))
continue
}
boundInputsSet.Insert(inputVar)
}
if diff := requiredInputsSet.Difference(boundInputsSet); len(diff) > 0 {
for param := range diff {
errs.Collect(errors.NewParameterNotBoundErr(nodeID, param))
}
}
return !errs.HasErrors()
}