forked from redhat-developer/odo
/
apiVersion.go
47 lines (38 loc) · 1.14 KB
/
apiVersion.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
package parser
import (
"encoding/json"
"fmt"
"github.com/golang/glog"
"github.com/openshift/odo/pkg/devfile/parser/data"
"github.com/pkg/errors"
)
// SetDevfileAPIVersion returns the devfile APIVersion
func (d *DevfileCtx) SetDevfileAPIVersion() error {
// Unmarshal JSON into map
var r map[string]interface{}
err := json.Unmarshal(d.rawContent, &r)
if err != nil {
return errors.Wrapf(err, "failed to decode devfile json")
}
// Get "apiVersion" value from the map
apiVersion, ok := r["apiVersion"]
if !ok {
return fmt.Errorf("apiVersion not present in devfile")
}
// apiVersion cannot be empty
if apiVersion.(string) == "" {
return fmt.Errorf("apiVersion in devfile cannot be empty")
}
// Successful
d.apiVersion = apiVersion.(string)
glog.V(4).Infof("devfile apiVersion: '%s'", d.apiVersion)
return nil
}
// GetApiVersion returns apiVersion stored in devfile context
func (d *DevfileCtx) GetApiVersion() string {
return d.apiVersion
}
// IsApiVersionSupported return true if the apiVersion in DevfileCtx is supported in odo
func (d *DevfileCtx) IsApiVersionSupported() bool {
return data.IsApiVersionSupported(d.apiVersion)
}