MCPcopy Create free account
hub / github.com/devfile/api / ValidateAndReplaceForCommands

Function ValidateAndReplaceForCommands

pkg/validation/variables/variables_command.go:25–56  ·  view source on GitHub ↗

ValidateAndReplaceForCommands validates the commands data for global variable references and replaces them with the variable value. Returns a map of command ids and invalid variable references if present.

(variables map[string]string, commands []v1alpha2.Command)

Source from the content-addressed store, hash-verified

23// ValidateAndReplaceForCommands validates the commands data for global variable references and replaces them with the variable value.
24// Returns a map of command ids and invalid variable references if present.
25func ValidateAndReplaceForCommands(variables map[string]string, commands []v1alpha2.Command) map[string][]string {
26
27 commandsWarningMap := make(map[string][]string)
28
29 for i := range commands {
30 var err error
31
32 // Validate various command types
33 switch {
34 case commands[i].Exec != nil:
35 if err = validateAndReplaceForExecCommand(variables, commands[i].Exec); err != nil {
36 if verr, ok := err.(*InvalidKeysError); ok {
37 commandsWarningMap[commands[i].Id] = verr.Keys
38 }
39 }
40 case commands[i].Composite != nil:
41 if err = validateAndReplaceForCompositeCommand(variables, commands[i].Composite); err != nil {
42 if verr, ok := err.(*InvalidKeysError); ok {
43 commandsWarningMap[commands[i].Id] = verr.Keys
44 }
45 }
46 case commands[i].Apply != nil:
47 if err = validateAndReplaceForApplyCommand(variables, commands[i].Apply); err != nil {
48 if verr, ok := err.(*InvalidKeysError); ok {
49 commandsWarningMap[commands[i].Id] = verr.Keys
50 }
51 }
52 }
53 }
54
55 return commandsWarningMap
56}
57
58// validateAndReplaceForExecCommand validates the exec command data for global variable references and replaces them with the variable value
59func validateAndReplaceForExecCommand(variables map[string]string, exec *v1alpha2.ExecCommand) error {

Callers 1

Tested by

no test coverage detected