forked from devfile/library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.go
104 lines (87 loc) · 3.05 KB
/
parse.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package devfile
import (
"github.com/devfile/api/v2/pkg/validation/variables"
"github.com/devfile/library/pkg/devfile/parser"
"github.com/devfile/library/pkg/devfile/validate"
)
// ParseFromURLAndValidate func parses the devfile data from the url
// and validates the devfile integrity with the schema
// and validates the devfile data.
// Creates devfile context and runtime objects.
// Deprecated, use ParseDevfileAndValidate() instead
func ParseFromURLAndValidate(url string) (d parser.DevfileObj, err error) {
// read and parse devfile from the given URL
d, err = parser.ParseFromURL(url)
if err != nil {
return d, err
}
// generic validation on devfile content
err = validate.ValidateDevfileData(d.Data)
if err != nil {
return d, err
}
return d, err
}
// ParseFromDataAndValidate func parses the devfile data
// and validates the devfile integrity with the schema
// and validates the devfile data.
// Creates devfile context and runtime objects.
// Deprecated, use ParseDevfileAndValidate() instead
func ParseFromDataAndValidate(data []byte) (d parser.DevfileObj, err error) {
// read and parse devfile from the given bytes
d, err = parser.ParseFromData(data)
if err != nil {
return d, err
}
// generic validation on devfile content
err = validate.ValidateDevfileData(d.Data)
if err != nil {
return d, err
}
return d, err
}
// ParseAndValidate func parses the devfile data
// and validates the devfile integrity with the schema
// and validates the devfile data.
// Creates devfile context and runtime objects.
// Deprecated, use ParseDevfileAndValidate() instead
func ParseAndValidate(path string) (d parser.DevfileObj, err error) {
// read and parse devfile from given path
d, err = parser.Parse(path)
if err != nil {
return d, err
}
// generic validation on devfile content
err = validate.ValidateDevfileData(d.Data)
if err != nil {
return d, err
}
return d, err
}
// ParseDevfileAndValidate func parses the devfile data, validates the devfile integrity with the schema
// replaces the top-level variable keys if present and validates the devfile data.
// It returns devfile context and runtime objects, variable substitution warning if any and an error.
func ParseDevfileAndValidate(args parser.ParserArgs) (d parser.DevfileObj, varWarning variables.VariableWarning, err error) {
d, err = parser.ParseDevfile(args)
if err != nil {
return d, varWarning, err
}
if d.Data.GetSchemaVersion() != "2.0.0" {
// add external variables to spec variables
if d.Data.GetDevfileWorkspaceSpec().Variables == nil {
d.Data.GetDevfileWorkspaceSpec().Variables = map[string]string{}
}
allVariables := d.Data.GetDevfileWorkspaceSpec().Variables
for key, val := range args.ExternalVariables {
allVariables[key] = val
}
// replace the top level variable keys with their values in the devfile
varWarning = variables.ValidateAndReplaceGlobalVariable(d.Data.GetDevfileWorkspaceSpec())
}
// generic validation on devfile content
err = validate.ValidateDevfileData(d.Data)
if err != nil {
return d, varWarning, err
}
return d, varWarning, err
}