-
Notifications
You must be signed in to change notification settings - Fork 243
/
parse.go
44 lines (35 loc) · 949 Bytes
/
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
package parser
import (
"encoding/json"
devfileCtx "github.com/openshift/odo/pkg/devfile/parser/context"
"github.com/openshift/odo/pkg/devfile/parser/data"
"github.com/pkg/errors"
)
// Parse func parses and validates the devfile integrity.
// Creates devfile context and runtime objects
func Parse(path string) (d DevfileObj, err error) {
// NewDevfileCtx
d.Ctx = devfileCtx.NewDevfileCtx(path)
// Fill the fields of DevfileCtx struct
err = d.Ctx.Populate()
if err != nil {
return d, err
}
// Validate devfile
err = d.Ctx.Validate()
if err != nil {
return d, err
}
// Create a new devfile data object
d.Data, err = data.NewDevfileData(d.Ctx.GetApiVersion())
if err != nil {
return d, err
}
// Unmarshal devfile content into devfile struct
err = json.Unmarshal(d.Ctx.GetDevfileContent(), &d.Data)
if err != nil {
return d, errors.Wrapf(err, "failed to decode devfile content")
}
// Successful
return d, nil
}