This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathvalidate.go
More file actions
58 lines (47 loc) · 1.5 KB
/
validate.go
File metadata and controls
58 lines (47 loc) · 1.5 KB
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
54
55
56
57
58
package validate
import (
"fmt"
"strings"
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
v2 "github.com/devfile/library/v2/pkg/devfile/parser/data/v2"
parsercommon "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
"k8s.io/klog/v2"
)
// ValidateDevfileData validates whether sections of devfile are odo compatible
// after invoking the generic devfile validation
func ValidateDevfileData(data interface{}) error {
switch d := data.(type) {
case *v2.DevfileV2:
components, err := d.GetComponents(parsercommon.DevfileOptions{})
if err != nil {
return err
}
commands, err := d.GetCommands(parsercommon.DevfileOptions{})
if err != nil {
return err
}
commandsMap := getCommandsMap(commands)
// Validate all the devfile components before validating commands
if err := validateComponents(components); err != nil {
return err
}
// Validate all the devfile commands before validating events
if err := validateCommands(commandsMap); err != nil {
return err
}
default:
return fmt.Errorf("unknown devfile type %T", d)
}
// Successful
klog.V(2).Info("Successfully validated devfile sections")
return nil
}
// getCommandsMap returns a map of the command Id to the command
func getCommandsMap(commands []devfilev1.Command) map[string]devfilev1.Command {
commandMap := make(map[string]devfilev1.Command, len(commands))
for _, command := range commands {
command.Id = strings.ToLower(command.Id)
commandMap[command.Id] = command
}
return commandMap
}