/
parse.go
53 lines (43 loc) · 1.37 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
package devfile
import (
"github.com/openshift/odo/pkg/devfile/parser"
"github.com/openshift/odo/pkg/devfile/validate"
)
// This is the top level parse code which has validation code specific to odo hence it cannot be kept inside the
// devfile/parser package. That package is supposed to be independent of odo.
// 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.
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
}
// odo specific validation on devfile content
err = validate.ValidateDevfileData(d.Data)
if err != nil {
return d, err
}
// Successful
return d, nil
}
// 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.
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
}
// odo specific validation on devfile content
err = validate.ValidateDevfileData(d.Data)
if err != nil {
return d, err
}
// Successful
return d, nil
}