Skip to content

Commit

Permalink
Merge pull request #302 from gunjan5/yaml-go
Browse files Browse the repository at this point in the history
Use projectcalico/go-yaml-wrapper fork with UnmarshalStrict
  • Loading branch information
gunjan5 authored Dec 12, 2016
2 parents 9725a75 + 030fd65 commit b0fb84b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
14 changes: 11 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import:
subpackages:
- client
- pkg/transport
- package: github.com/ghodss/yaml
- package: github.com/projectcalico/go-yaml-wrapper
- package: github.com/kelseyhightower/envconfig
- package: github.com/onsi/ginkgo
- package: github.com/satori/go.uuid
Expand Down
8 changes: 4 additions & 4 deletions lib/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"errors"

log "github.com/Sirupsen/logrus"
"github.com/ghodss/yaml"
"github.com/kelseyhightower/envconfig"
yaml "github.com/projectcalico/go-yaml-wrapper"
"github.com/projectcalico/libcalico-go/lib/api"
"github.com/projectcalico/libcalico-go/lib/api/unversioned"
"github.com/projectcalico/libcalico-go/lib/backend"
Expand Down Expand Up @@ -122,16 +122,16 @@ func LoadClientConfigFromBytes(b []byte) (*api.CalicoAPIConfig, error) {
},
}

if err := yaml.Unmarshal(b, &c); err != nil {
if err := yaml.UnmarshalStrict(b, &c); err != nil {
return nil, err
}

// Validate the version and kind.
if c.APIVersion != unversioned.VersionCurrent {
return nil, errors.New("unknown APIVersion '" + c.APIVersion + "'")
return nil, errors.New("invalid config file: unknown APIVersion '" + c.APIVersion + "'")
}
if c.Kind != "calicoApiConfig" {
return nil, errors.New("expected kind 'calicoApiConfig', got '" + c.Kind + "'")
return nil, errors.New("invalid config file: expected kind 'calicoApiConfig', got '" + c.Kind + "'")
}

log.Info("Datastore type: ", c.Spec.DatastoreType)
Expand Down
4 changes: 2 additions & 2 deletions lib/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ kind: notCalicoApiConfig

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

DescribeTable("Load client config by environment",
Expand Down

0 comments on commit b0fb84b

Please sign in to comment.