Skip to content

Commit b0fb84b

Browse files
authored
Merge pull request #302 from gunjan5/yaml-go
Use projectcalico/go-yaml-wrapper fork with UnmarshalStrict
2 parents 9725a75 + 030fd65 commit b0fb84b

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

glide.lock

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import:
1111
subpackages:
1212
- client
1313
- pkg/transport
14-
- package: github.com/ghodss/yaml
14+
- package: github.com/projectcalico/go-yaml-wrapper
1515
- package: github.com/kelseyhightower/envconfig
1616
- package: github.com/onsi/ginkgo
1717
- package: github.com/satori/go.uuid

lib/client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"errors"
2222

2323
log "github.com/Sirupsen/logrus"
24-
"github.com/ghodss/yaml"
2524
"github.com/kelseyhightower/envconfig"
25+
yaml "github.com/projectcalico/go-yaml-wrapper"
2626
"github.com/projectcalico/libcalico-go/lib/api"
2727
"github.com/projectcalico/libcalico-go/lib/api/unversioned"
2828
"github.com/projectcalico/libcalico-go/lib/backend"
@@ -122,16 +122,16 @@ func LoadClientConfigFromBytes(b []byte) (*api.CalicoAPIConfig, error) {
122122
},
123123
}
124124

125-
if err := yaml.Unmarshal(b, &c); err != nil {
125+
if err := yaml.UnmarshalStrict(b, &c); err != nil {
126126
return nil, err
127127
}
128128

129129
// Validate the version and kind.
130130
if c.APIVersion != unversioned.VersionCurrent {
131-
return nil, errors.New("unknown APIVersion '" + c.APIVersion + "'")
131+
return nil, errors.New("invalid config file: unknown APIVersion '" + c.APIVersion + "'")
132132
}
133133
if c.Kind != "calicoApiConfig" {
134-
return nil, errors.New("expected kind 'calicoApiConfig', got '" + c.Kind + "'")
134+
return nil, errors.New("invalid config file: expected kind 'calicoApiConfig', got '" + c.Kind + "'")
135135
}
136136

137137
log.Info("Datastore type: ", c.Spec.DatastoreType)

lib/client/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ kind: notCalicoApiConfig
192192

193193
Entry("valid etcd configuration", data1, cfg1data, nil),
194194
Entry("valid k8s configuration", data2, cfg2data, nil),
195-
Entry("invalid version", data3, nil, errors.New("unknown APIVersion 'v2'")),
196-
Entry("invalid kind", data4, nil, errors.New("expected kind 'calicoApiConfig', got 'notCalicoApiConfig'")),
195+
Entry("invalid version", data3, nil, errors.New("invalid config file: unknown APIVersion 'v2'")),
196+
Entry("invalid kind", data4, nil, errors.New("invalid config file: expected kind 'calicoApiConfig', got 'notCalicoApiConfig'")),
197197
)
198198

199199
DescribeTable("Load client config by environment",

0 commit comments

Comments
 (0)