Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

Commit a297616

Browse files
committed
Replace viper with standard JSON decoding
Fixes #817
1 parent 335839b commit a297616

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+36
-21378
lines changed

Gopkg.lock

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

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
name = "github.com/spf13/cobra"
33
version = "0.0.3"
44

5-
[[constraint]]
6-
name = "github.com/spf13/viper"
7-
version = "v1.2"
8-
95
[[constraint]]
106
name = "github.com/Masterminds/semver"
117
version = "1.4.2"

cmd/duffle/install.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"io"
67
"io/ioutil"
@@ -16,7 +17,6 @@ import (
1617
"github.com/deislabs/cnab-go/bundle/definition"
1718
"github.com/deislabs/cnab-go/claim"
1819
"github.com/spf13/cobra"
19-
"github.com/spf13/viper"
2020
)
2121

2222
const installUsage = `Installs a Cloud Native Application Bundle (CNAB)
@@ -218,13 +218,15 @@ func overrides(overrides []string, paramDefs definition.Definitions) (map[string
218218
}
219219

220220
func parseValues(file string) (map[string]interface{}, error) {
221-
v := viper.New()
222-
v.SetConfigFile(file)
223-
err := v.ReadInConfig()
221+
vals := map[string]interface{}{}
222+
f, err := ioutil.ReadFile(file)
224223
if err != nil {
225224
return nil, err
226225
}
227-
return v.AllSettings(), nil
226+
if err := json.Unmarshal(f, &vals); err != nil {
227+
return nil, err
228+
}
229+
return vals, nil
228230
}
229231

230232
func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setFilePaths []string, prevVals map[string]interface{}) (map[string]interface{}, error) {

pkg/duffle/manifest/load.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
package manifest
22

33
import (
4-
"fmt"
4+
"encoding/json"
5+
"os"
56
"path/filepath"
67

7-
"github.com/spf13/viper"
8-
98
"github.com/deislabs/duffle/pkg/duffle"
109
)
1110

12-
// Load opens the named file for reading. If successful, the manifest is returned.
11+
// Load parses the named file into a manifest.
1312
func Load(name, dir string) (*Manifest, error) {
14-
v := viper.New()
1513
if name == "" {
16-
v.SetConfigName(duffle.DuffleFilename)
17-
} else {
18-
v.SetConfigFile(filepath.Join(dir, name))
14+
name = duffle.DuffleFilename + ".json"
1915
}
20-
v.AddConfigPath(dir)
21-
err := v.ReadInConfig()
16+
f, err := os.Open(filepath.Join(dir, name))
2217
if err != nil {
23-
return nil, fmt.Errorf("Error finding duffle config file: %s", err)
18+
return nil, err
2419
}
2520

26-
m := New()
27-
err = v.Unmarshal(m)
28-
if err != nil {
21+
manifest := New()
22+
if err := json.NewDecoder(f).Decode(&manifest); err != nil {
2923
return nil, err
3024
}
31-
return m, nil
25+
26+
return manifest, nil
3227
}

pkg/duffle/manifest/manifest.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ import (
1212

1313
// Manifest represents a duffle manifest.
1414
type Manifest struct {
15-
Name string `json:"name" mapstructure:"name"`
16-
Version string `json:"version" mapstructure:"version"`
17-
SchemaVersion string `json:"schemaVersion" mapstructure:"schemaVersion"`
18-
Description string `json:"description,omitempty" mapstructure:"description"`
19-
Keywords []string `json:"keywords,omitempty" mapstructure:"keywords"`
20-
Maintainers []bundle.Maintainer `json:"maintainers,omitempty" mapstructure:"maintainers"`
21-
InvocationImages map[string]*InvocationImage `json:"invocationImages,omitempty" mapstructure:"invocationImages"`
22-
Images map[string]bundle.Image `json:"images,omitempty" mapstructure:"images"`
23-
Actions map[string]bundle.Action `json:"actions,omitempty" mapstructure:"actions"`
24-
Parameters *bundle.ParametersDefinition `json:"parameters,omitempty" mapstructure:"parameters"`
25-
Credentials map[string]bundle.Credential `json:"credentials,omitempty" mapstructure:"credentials"`
26-
Definitions definition.Definitions `json:"definitions,omitempty" mapstructure:"definitions"`
27-
Outputs *bundle.OutputsDefinition `json:"outputs,omitempty" mapstructure:"outputs"`
28-
Custom map[string]interface{} `json:"custom,omitempty" mapstructure:"custom"`
15+
Name string `json:"name"`
16+
Version string `json:"version"`
17+
SchemaVersion string `json:"schemaVersion"`
18+
Description string `json:"description,omitempty"`
19+
Keywords []string `json:"keywords,omitempty"`
20+
Maintainers []bundle.Maintainer `json:"maintainers,omitempty"`
21+
InvocationImages map[string]*InvocationImage `json:"invocationImages,omitempty"`
22+
Images map[string]bundle.Image `json:"images,omitempty"`
23+
Actions map[string]bundle.Action `json:"actions,omitempty"`
24+
Parameters *bundle.ParametersDefinition `json:"parameters,omitempty"`
25+
Credentials map[string]bundle.Credential `json:"credentials,omitempty"`
26+
Definitions definition.Definitions `json:"definitions,omitempty"`
27+
Outputs *bundle.OutputsDefinition `json:"outputs,omitempty"`
28+
Custom map[string]interface{} `json:"custom,omitempty"`
2929
}
3030

3131
// InvocationImage represents an invocation image component of a CNAB bundle
3232
type InvocationImage struct {
33-
Name string `json:"name" mapstructure:"name"`
34-
Builder string `json:"builder" mapstructure:"builder"`
35-
Configuration map[string]string `json:"configuration" mapstructure:"configuration"`
33+
Name string `json:"name"`
34+
Builder string `json:"builder"`
35+
Configuration map[string]string `json:"configuration"`
3636
}
3737

3838
// New creates a new manifest with the Environments intialized.

pkg/duffle/manifest/manifest_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ func TestInvalidLoad(t *testing.T) {
110110
if err == nil {
111111
t.Errorf("expected an error to be thrown")
112112
}
113-
if !strings.Contains(err.Error(), "error(s) decoding") {
114-
t.Errorf("expected err to contain %s but was %s", "error(s) decoding", err.Error())
113+
if !strings.Contains(err.Error(), "json: cannot unmarshal array into Go struct field") {
114+
t.Errorf("expected err to contain %s but was %s", "json: cannot unmarshal array into Go struct field", err.Error())
115115
}
116116
})
117117
}

vendor/github.com/fsnotify/fsnotify/AUTHORS

Lines changed: 0 additions & 52 deletions
This file was deleted.

vendor/github.com/fsnotify/fsnotify/LICENSE

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)