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

Commit

Permalink
Merge pull request #818 from glyn/817-allow-arbitrary-image-names
Browse files Browse the repository at this point in the history
Replace viper with standard JSON decoding
  • Loading branch information
carolynvs-msft committed Aug 2, 2019
2 parents 335839b + a297616 commit 29e4fad
Show file tree
Hide file tree
Showing 93 changed files with 36 additions and 21,378 deletions.
87 changes: 0 additions & 87 deletions Gopkg.lock

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

4 changes: 0 additions & 4 deletions Gopkg.toml
Expand Up @@ -2,10 +2,6 @@
name = "github.com/spf13/cobra"
version = "0.0.3"

[[constraint]]
name = "github.com/spf13/viper"
version = "v1.2"

[[constraint]]
name = "github.com/Masterminds/semver"
version = "1.4.2"
Expand Down
12 changes: 7 additions & 5 deletions cmd/duffle/install.go
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/deislabs/cnab-go/bundle/definition"
"github.com/deislabs/cnab-go/claim"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

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

func parseValues(file string) (map[string]interface{}, error) {
v := viper.New()
v.SetConfigFile(file)
err := v.ReadInConfig()
vals := map[string]interface{}{}
f, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
return v.AllSettings(), nil
if err := json.Unmarshal(f, &vals); err != nil {
return nil, err
}
return vals, nil
}

func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setFilePaths []string, prevVals map[string]interface{}) (map[string]interface{}, error) {
Expand Down
25 changes: 10 additions & 15 deletions pkg/duffle/manifest/load.go
@@ -1,32 +1,27 @@
package manifest

import (
"fmt"
"encoding/json"
"os"
"path/filepath"

"github.com/spf13/viper"

"github.com/deislabs/duffle/pkg/duffle"
)

// Load opens the named file for reading. If successful, the manifest is returned.
// Load parses the named file into a manifest.
func Load(name, dir string) (*Manifest, error) {
v := viper.New()
if name == "" {
v.SetConfigName(duffle.DuffleFilename)
} else {
v.SetConfigFile(filepath.Join(dir, name))
name = duffle.DuffleFilename + ".json"
}
v.AddConfigPath(dir)
err := v.ReadInConfig()
f, err := os.Open(filepath.Join(dir, name))
if err != nil {
return nil, fmt.Errorf("Error finding duffle config file: %s", err)
return nil, err
}

m := New()
err = v.Unmarshal(m)
if err != nil {
manifest := New()
if err := json.NewDecoder(f).Decode(&manifest); err != nil {
return nil, err
}
return m, nil

return manifest, nil
}
34 changes: 17 additions & 17 deletions pkg/duffle/manifest/manifest.go
Expand Up @@ -12,27 +12,27 @@ import (

// Manifest represents a duffle manifest.
type Manifest struct {
Name string `json:"name" mapstructure:"name"`
Version string `json:"version" mapstructure:"version"`
SchemaVersion string `json:"schemaVersion" mapstructure:"schemaVersion"`
Description string `json:"description,omitempty" mapstructure:"description"`
Keywords []string `json:"keywords,omitempty" mapstructure:"keywords"`
Maintainers []bundle.Maintainer `json:"maintainers,omitempty" mapstructure:"maintainers"`
InvocationImages map[string]*InvocationImage `json:"invocationImages,omitempty" mapstructure:"invocationImages"`
Images map[string]bundle.Image `json:"images,omitempty" mapstructure:"images"`
Actions map[string]bundle.Action `json:"actions,omitempty" mapstructure:"actions"`
Parameters *bundle.ParametersDefinition `json:"parameters,omitempty" mapstructure:"parameters"`
Credentials map[string]bundle.Credential `json:"credentials,omitempty" mapstructure:"credentials"`
Definitions definition.Definitions `json:"definitions,omitempty" mapstructure:"definitions"`
Outputs *bundle.OutputsDefinition `json:"outputs,omitempty" mapstructure:"outputs"`
Custom map[string]interface{} `json:"custom,omitempty" mapstructure:"custom"`
Name string `json:"name"`
Version string `json:"version"`
SchemaVersion string `json:"schemaVersion"`
Description string `json:"description,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Maintainers []bundle.Maintainer `json:"maintainers,omitempty"`
InvocationImages map[string]*InvocationImage `json:"invocationImages,omitempty"`
Images map[string]bundle.Image `json:"images,omitempty"`
Actions map[string]bundle.Action `json:"actions,omitempty"`
Parameters *bundle.ParametersDefinition `json:"parameters,omitempty"`
Credentials map[string]bundle.Credential `json:"credentials,omitempty"`
Definitions definition.Definitions `json:"definitions,omitempty"`
Outputs *bundle.OutputsDefinition `json:"outputs,omitempty"`
Custom map[string]interface{} `json:"custom,omitempty"`
}

// InvocationImage represents an invocation image component of a CNAB bundle
type InvocationImage struct {
Name string `json:"name" mapstructure:"name"`
Builder string `json:"builder" mapstructure:"builder"`
Configuration map[string]string `json:"configuration" mapstructure:"configuration"`
Name string `json:"name"`
Builder string `json:"builder"`
Configuration map[string]string `json:"configuration"`
}

// New creates a new manifest with the Environments intialized.
Expand Down
4 changes: 2 additions & 2 deletions pkg/duffle/manifest/manifest_test.go
Expand Up @@ -110,8 +110,8 @@ func TestInvalidLoad(t *testing.T) {
if err == nil {
t.Errorf("expected an error to be thrown")
}
if !strings.Contains(err.Error(), "error(s) decoding") {
t.Errorf("expected err to contain %s but was %s", "error(s) decoding", err.Error())
if !strings.Contains(err.Error(), "json: cannot unmarshal array into Go struct field") {
t.Errorf("expected err to contain %s but was %s", "json: cannot unmarshal array into Go struct field", err.Error())
}
})
}
Expand Down
52 changes: 0 additions & 52 deletions vendor/github.com/fsnotify/fsnotify/AUTHORS

This file was deleted.

28 changes: 0 additions & 28 deletions vendor/github.com/fsnotify/fsnotify/LICENSE

This file was deleted.

0 comments on commit 29e4fad

Please sign in to comment.