validateCommandComponent validates the given exec or apply command, the command should map to a valid container component
(command v1alpha2.Command, components []v1alpha2.Component)
| 132 | |
| 133 | // validateCommandComponent validates the given exec or apply command, the command should map to a valid container component |
| 134 | func validateCommandComponent(command v1alpha2.Command, components []v1alpha2.Component) error { |
| 135 | |
| 136 | if command.Exec == nil && command.Apply == nil { |
| 137 | return &InvalidCommandError{commandId: command.Id, reason: "should be of type exec or apply"} |
| 138 | } |
| 139 | |
| 140 | var commandComponent string |
| 141 | if command.Exec != nil { |
| 142 | commandComponent = command.Exec.Component |
| 143 | } else if command.Apply != nil { |
| 144 | commandComponent = command.Apply.Component |
| 145 | } |
| 146 | |
| 147 | // exec command must map to a container component |
| 148 | // apply command must map to a container/kubernetes/openshift/image component |
| 149 | for _, component := range components { |
| 150 | if commandComponent == component.Name { |
| 151 | if component.Container != nil { |
| 152 | return nil |
| 153 | } |
| 154 | if command.Apply != nil && (component.Image != nil || component.Kubernetes != nil || component.Openshift != nil) { |
| 155 | return nil |
| 156 | } |
| 157 | break |
| 158 | } |
| 159 | } |
| 160 | return &InvalidCommandError{commandId: command.Id, reason: "command does not map to a valid component"} |
| 161 | } |
| 162 | |
| 163 | // validateCompositeCommand checks that the specified composite command is valid. The command: |
| 164 | // 1. should not reference itself via a subcommand |
no outgoing calls