ValidateCommands validates the devfile commands and checks: 1. there are no duplicate command ids 2. the command type is not invalid 3. if a command is part of a command group, there is a single default command
(commands []v1alpha2.Command, components []v1alpha2.Component)
| 29 | // 2. the command type is not invalid |
| 30 | // 3. if a command is part of a command group, there is a single default command |
| 31 | func ValidateCommands(commands []v1alpha2.Command, components []v1alpha2.Component) (returnedErr error) { |
| 32 | groupKindCommandMap := make(map[v1alpha2.CommandGroupKind][]v1alpha2.Command) |
| 33 | commandMap := getCommandsMap(commands) |
| 34 | |
| 35 | err := v1alpha2.CheckDuplicateKeys(commands) |
| 36 | if err != nil { |
| 37 | returnedErr = multierror.Append(returnedErr, err) |
| 38 | } |
| 39 | |
| 40 | for _, command := range commands { |
| 41 | // parentCommands is a map to keep a track of all the parent commands when validating the composite command's subcommands recursively |
| 42 | parentCommands := make(map[string]string) |
| 43 | err := validateCommand(command, parentCommands, commandMap, components) |
| 44 | if err != nil { |
| 45 | returnedErr = multierror.Append(returnedErr, resolveErrorMessageWithImportAttributes(err, command.Attributes)) |
| 46 | } |
| 47 | |
| 48 | commandGroup := getGroup(command) |
| 49 | if commandGroup != nil { |
| 50 | groupKindCommandMap[commandGroup.Kind] = append(groupKindCommandMap[commandGroup.Kind], command) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | for groupKind, commands := range groupKindCommandMap { |
| 55 | if err := validateGroup(commands, groupKind); err != nil { |
| 56 | returnedErr = multierror.Append(returnedErr, err) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return returnedErr |
| 61 | } |
| 62 | |
| 63 | // validateCommand validates a given devfile command where parentCommands is a map to track all the parent commands when validating |
| 64 | // the composite command's subcommands recursively and devfileCommands is a map of command id to the devfile command |