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

Function validateCommandComponent

pkg/validation/commands.go:134–161  ·  view source on GitHub ↗

validateCommandComponent validates the given exec or apply command, the command should map to a valid container component

(command v1alpha2.Command, components []v1alpha2.Component)

Source from the content-addressed store, hash-verified

132
133// validateCommandComponent validates the given exec or apply command, the command should map to a valid container component
134func 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

Callers 2

validateCommandFunction · 0.85

Calls

no outgoing calls

Tested by 1