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

Bump cnab-go dependency to reflect the Bundle structure changes #788

Merged
merged 2 commits into from Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 35 additions & 3 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Expand Up @@ -59,6 +59,10 @@
name = "github.com/pivotal/image-relocation"
revision = "532dd0b42e7a50010d7868364309cd314a2bb376"

[[constraint]]
name = "github.com/deislabs/cnab-go"
version = "v0.1.2-beta1"

[[override]]
name = "github.com/google/go-containerregistry"
revision = "5296537b6d5d12241dd0a8b1ef70a59cba62f48c"
Expand Down
2 changes: 1 addition & 1 deletion cmd/duffle/credential_generate.go
Expand Up @@ -103,7 +103,7 @@ const (

type credentialGenerator func(name string) (credentials.CredentialStrategy, error)

func genCredentialSet(name string, creds map[string]bundle.Location, fn credentialGenerator) (credentials.CredentialSet, error) {
func genCredentialSet(name string, creds map[string]bundle.Credential, fn credentialGenerator) (credentials.CredentialSet, error) {
cs := credentials.CredentialSet{
Name: name,
}
Expand Down
16 changes: 11 additions & 5 deletions cmd/duffle/credential_generate_test.go
Expand Up @@ -10,16 +10,22 @@ import (

func TestGenCredentialSet(t *testing.T) {
name := "zed"
credlocs := map[string]bundle.Location{
credlocs := map[string]bundle.Credential{
"first": {
EnvironmentVariable: "FIRST_VAR",
Location: bundle.Location{
EnvironmentVariable: "FIRST_VAR",
},
},
"second": {
EnvironmentVariable: "SECOND_VAR",
Path: "/second/path",
Location: bundle.Location{
EnvironmentVariable: "SECOND_VAR",
Path: "/second/path",
},
},
"third": {
Path: "/third/path",
Location: bundle.Location{
Path: "/third/path",
},
},
}
is := assert.New(t)
Expand Down
7 changes: 4 additions & 3 deletions cmd/duffle/install.go
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/deislabs/cnab-go/action"
"github.com/deislabs/cnab-go/bundle"
"github.com/deislabs/cnab-go/bundle/definition"
"github.com/deislabs/cnab-go/claim"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -182,7 +183,7 @@ func getBundleFilepath(bun, homePath string) (string, error) {
}

// overrides parses the --set data and returns values that should override other params.
func overrides(overrides []string, paramDefs map[string]bundle.ParameterDefinition) (map[string]interface{}, error) {
func overrides(overrides []string, paramDefs definition.Definitions) (map[string]interface{}, error) {
res := map[string]interface{}{}
for _, p := range overrides {
pair := strings.SplitN(p, "=", 2)
Expand Down Expand Up @@ -230,7 +231,7 @@ func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setF
}

}
overridden, err := overrides(setParams, bun.Parameters)
overridden, err := overrides(setParams, bun.Definitions)
if err != nil {
return vals, err
}
Expand All @@ -246,7 +247,7 @@ func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setF
}

// Check that this is a known param
if _, ok := bun.Parameters[parts[0]]; !ok {
if _, ok := bun.Parameters.Fields[parts[0]]; !ok {
return vals, fmt.Errorf("bundle does not have a parameter named %q", parts[0])
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/duffle/install_test.go
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"testing"

"github.com/deislabs/cnab-go/bundle"
"github.com/deislabs/cnab-go/bundle/definition"
"github.com/stretchr/testify/assert"

"github.com/deislabs/duffle/pkg/duffle/home"
Expand Down Expand Up @@ -57,10 +57,10 @@ func TestGetBundle(t *testing.T) {
func TestOverrides(t *testing.T) {
is := assert.New(t)
// overrides(overrides []string, paramDefs map[string]bundle.ParameterDefinition)
defs := map[string]bundle.ParameterDefinition{
"first": {DataType: "string"},
"second": {DataType: "bool"},
"third": {DataType: "int"},
defs := definition.Definitions{
"first": {Type: "string"},
"second": {Type: "boolean"},
"third": {Type: "integer"},
}

setVals := []string{"first=foo", "second=true", "third=2", "fourth"}
Expand Down
14 changes: 10 additions & 4 deletions cmd/duffle/main_test.go
Expand Up @@ -102,15 +102,21 @@ func TestLoadCredentials(t *testing.T) {

bun := bundle.Bundle{
Name: "test-load-creds",
Credentials: map[string]bundle.Location{
Credentials: map[string]bundle.Credential{
"knapsack": {
EnvironmentVariable: "KNAP",
Location: bundle.Location{
EnvironmentVariable: "KNAP",
},
},
"haversack": {
EnvironmentVariable: "HAVER",
Location: bundle.Location{
EnvironmentVariable: "HAVER",
},
},
"gym-bag": {
EnvironmentVariable: "GYM",
Location: bundle.Location{
EnvironmentVariable: "GYM",
},
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/duffle/testdata/relocate/bundle.json
@@ -1,4 +1,5 @@
{
"schemaVersion": "v1.0.0-WD",
"name": "testrelocate",
"version": "0.1",
"description": "a bundle with images",
Expand Down Expand Up @@ -27,4 +28,4 @@
"imageType": "c"
}
}
}
}
22 changes: 12 additions & 10 deletions pkg/duffle/manifest/manifest.go
Expand Up @@ -5,22 +5,24 @@ import (
"path/filepath"

"github.com/deislabs/cnab-go/bundle"
"github.com/deislabs/cnab-go/bundle/definition"

"github.com/technosophos/moniker"
)

// Manifest represents a duffle manifest.
type Manifest struct {
Name string `json:"name" mapstructure:"name"`
Version string `json:"version" mapstructure:"version"`
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 map[string]bundle.ParameterDefinition `json:"parameters,omitempty" mapstructure:"parameters"`
Credentials map[string]bundle.Location `json:"credentials,omitempty" mapstructure:"credentials"`
Name string `json:"name" mapstructure:"name"`
Version string `json:"version" mapstructure:"version"`
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"`
}

// InvocationImage represents an invocation image component of a CNAB bundle
Expand Down
12 changes: 6 additions & 6 deletions pkg/duffle/manifest/manifest_test.go
Expand Up @@ -12,7 +12,7 @@ func TestNew(t *testing.T) {
// Testing to make sure maps are initialized
is := assert.New(t)
is.Len(m.InvocationImages, 0)
is.Len(m.Parameters, 0)
is.Nil(m.Parameters)
is.Len(m.Credentials, 0)

}
Expand Down Expand Up @@ -63,17 +63,17 @@ func TestLoad(t *testing.T) {
t.Errorf("exp docker but was \"%v\"", img.ImageType)
}

if len(m.Parameters) != 1 {
t.Fatalf("expected 1 parameter but got %d", len(m.Parameters))
if len(m.Parameters.Fields) != 1 {
t.Fatalf("expected 1 parameter but got %d", len(m.Parameters.Fields))
}

param, ok := m.Parameters["foo"]
_, ok := m.Parameters.Fields["foo"]
if !ok {
t.Errorf("expected a parameter named foo but got %v", m.Parameters)
}

if param.DataType != "string" {
t.Errorf("expected foo parameter to have a type of string but got %v", param.DataType)
if m.Definitions["foo"].Type != "string" {
t.Errorf("expected foo parameter to have a type of string but got %v", m.Definitions["foo"].Type)
}

if len(m.Credentials) != 1 {
Expand Down
9 changes: 8 additions & 1 deletion pkg/duffle/manifest/testdata/duffle.json
Expand Up @@ -17,11 +17,18 @@
"digest": "sha256:ca4050c9fed3a2ddcaef32140686613c4110ed728f53262d0a23a7e17da73111"
}
},
"parameters": {
"definitions": {
"foo": {
"type": "string"
}
},
"parameters": {
"fields": {
"foo": {
"definition": "foo"
}
}
},
"credentials": {
"bar": {
"path": "/tmp"
Expand Down
5 changes: 3 additions & 2 deletions pkg/duffle/manifest/testdata/duffle.toml
Expand Up @@ -10,9 +10,10 @@ name = "testbundle"
imageType = "docker"
image = "docker.io/istio/citadel:1.0.2"
digest = "sha256:ca4050c9fed3a2ddcaef32140686613c4110ed728f53262d0a23a7e17da73111"
[parameters.foo]
[definitions.foo]
type = "string"

[parameters.fields.foo]
definition = "foo"
[credentials.bar]
path = "/tmp"

Expand Down
6 changes: 5 additions & 1 deletion pkg/duffle/manifest/testdata/duffle.yaml
Expand Up @@ -11,9 +11,13 @@ images:
imageType: "docker"
image: "docker.io/istio/citadel:1.0.2"
digest: "sha256:ca4050c9fed3a2ddcaef32140686613c4110ed728f53262d0a23a7e17da73111"
parameters:
definitions:
foo:
type: string
parameters:
Fields:
foo:
definition: foo
credentials:
bar:
path: /tmp
Expand Down