diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index 31ac57b81..77c142779 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -196,25 +196,25 @@ func TestStoreManifest(t *testing.T) { }{ { name: "embedded manifest", - bundle: cnab.ExtendedBundle{bundle.Bundle{ + bundle: cnab.NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ "sh.porter": map[string]interface{}{ "manifest": "bmFtZTogSEVMTE9fQ1VTVE9NCnZlcnNpb246IDAuMS4wCmRlc2NyaXB0aW9uOiAiQSBidW5kbGUgd2l0aCBhIGN1c3RvbSBhY3Rpb24iCnRhZzogZ2V0cG9ydGVyL3BvcnRlci1oZWxsbzp2MC4xLjAKaW52b2NhdGlvbkltYWdlOiBnZXRwb3J0ZXIvcG9ydGVyLWhlbGxvLWluc3RhbGxlcjowLjEuMAoKY3JlZGVudGlhbHM6CiAgLSBuYW1lOiBteS1maXJzdC1jcmVkCiAgICBlbnY6IE1ZX0ZJUlNUX0NSRUQKICAtIG5hbWU6IG15LXNlY29uZC1jcmVkCiAgICBkZXNjcmlwdGlvbjogIk15IHNlY29uZCBjcmVkIgogICAgcGF0aDogL3BhdGgvdG8vbXktc2Vjb25kLWNyZWQKCmltYWdlczogCiAgIHNvbWV0aGluZzoKICAgICAgZGVzY3JpcHRpb246ICJhbiBpbWFnZSIKICAgICAgaW1hZ2VUeXBlOiAiZG9ja2VyIgogICAgICByZXBvc2l0b3J5OiAiZ2V0cG9ydGVyL2JvbyIKCnBhcmFtZXRlcnM6CiAgLSBuYW1lOiBteS1maXJzdC1wYXJhbQogICAgdHlwZTogaW50ZWdlcgogICAgZGVmYXVsdDogOQogICAgZW52OiBNWV9GSVJTVF9QQVJBTQogICAgYXBwbHlUbzoKICAgICAgLSAiaW5zdGFsbCIKICAtIG5hbWU6IG15LXNlY29uZC1wYXJhbQogICAgZGVzY3JpcHRpb246ICJNeSBzZWNvbmQgcGFyYW1ldGVyIgogICAgdHlwZTogc3RyaW5nCiAgICBkZWZhdWx0OiBzcHJpbmctbXVzaWMtZGVtbwogICAgcGF0aDogL3BhdGgvdG8vbXktc2Vjb25kLXBhcmFtCiAgICBzZW5zaXRpdmU6IHRydWUKCm91dHB1dHM6CiAgLSBuYW1lOiBteS1maXJzdC1vdXRwdXQKICAgIHR5cGU6IHN0cmluZwogICAgYXBwbHlUbzoKICAgICAgLSAiaW5zdGFsbCIKICAgICAgLSAidXBncmFkZSIKICAgIHNlbnNpdGl2ZTogdHJ1ZQogIC0gbmFtZTogbXktc2Vjb25kLW91dHB1dAogICAgZGVzY3JpcHRpb246ICJNeSBzZWNvbmQgb3V0cHV0IgogICAgdHlwZTogYm9vbGVhbgogICAgc2Vuc2l0aXZlOiBmYWxzZQogIC0gbmFtZToga3ViZWNvbmZpZwogICAgdHlwZTogZmlsZQogICAgcGF0aDogL3Jvb3QvLmt1YmUvY29uZmlnCgptaXhpbnM6CiAgLSBleGVjCgppbnN0YWxsOgogIC0gZXhlYzoKICAgICAgZGVzY3JpcHRpb246ICJJbnN0YWxsIEhlbGxvIFdvcmxkIgogICAgICBjb21tYW5kOiBiYXNoCiAgICAgIGZsYWdzOgogICAgICAgIGM6IGVjaG8gSGVsbG8gV29ybGQKCnVwZ3JhZGU6CiAgLSBleGVjOgogICAgICBkZXNjcmlwdGlvbjogIldvcmxkIDIuMCIKICAgICAgY29tbWFuZDogYmFzaAogICAgICBmbGFnczoKICAgICAgICBjOiBlY2hvIFdvcmxkIDIuMAoKem9tYmllczoKICAtIGV4ZWM6CiAgICAgIGRlc2NyaXB0aW9uOiAiVHJpZ2dlciB6b21iaWUgYXBvY2FseXBzZSIKICAgICAgY29tbWFuZDogYmFzaAogICAgICBmbGFnczoKICAgICAgICBjOiBlY2hvIG9oIG5vZXMgbXkgYnJhaW5zCgp1bmluc3RhbGw6CiAgLSBleGVjOgogICAgICBkZXNjcmlwdGlvbjogIlVuaW5zdGFsbCBIZWxsbyBXb3JsZCIKICAgICAgY29tbWFuZDogYmFzaAogICAgICBmbGFnczoKICAgICAgICBjOiBlY2hvIEdvb2RieWUgV29ybGQK", }, }, - }}, + }), tag: kahn1dot01, shouldCacheManifest: true, }, { name: "porter stamp, no manifest", - bundle: cnab.ExtendedBundle{bundle.Bundle{ + bundle: cnab.NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ "sh.porter": map[string]interface{}{ "manifestDigest": "abc123", }, }, - }}, + }), tag: kahn1dot01, shouldCacheManifest: false, }, diff --git a/pkg/cnab/cnab-to-oci/registry.go b/pkg/cnab/cnab-to-oci/registry.go index 2d77ff894..2999124a4 100644 --- a/pkg/cnab/cnab-to-oci/registry.go +++ b/pkg/cnab/cnab-to-oci/registry.go @@ -76,7 +76,7 @@ func (r *Registry) PullBundle(ref cnab.OCIReference, insecureRegistry bool) (cna bundleRef := cnab.BundleReference{ Reference: ref, Digest: digest, - Definition: cnab.ExtendedBundle{*bun}, + Definition: cnab.NewBundle(*bun), RelocationMap: reloMap, } diff --git a/pkg/cnab/config-adapter/adapter.go b/pkg/cnab/config-adapter/adapter.go index 32c281222..98f6f3e80 100644 --- a/pkg/cnab/config-adapter/adapter.go +++ b/pkg/cnab/config-adapter/adapter.go @@ -48,14 +48,14 @@ func (c *ManifestConverter) ToBundle(ctx context.Context) (cnab.ExtendedBundle, return cnab.ExtendedBundle{}, span.Error(err) } - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ SchemaVersion: SchemaVersion, Name: c.Manifest.Name, Description: c.Manifest.Description, Version: c.Manifest.Version, Maintainers: c.generateBundleMaintainers(), Custom: make(map[string]interface{}, 1), - }} + }) image := bundle.InvocationImage{ BaseImage: bundle.BaseImage{ Image: c.Manifest.Image, diff --git a/pkg/cnab/config-adapter/adapter_test.go b/pkg/cnab/config-adapter/adapter_test.go index 8f75a5bd5..13ee026a2 100644 --- a/pkg/cnab/config-adapter/adapter_test.go +++ b/pkg/cnab/config-adapter/adapter_test.go @@ -659,7 +659,7 @@ func TestNewManifestConverter_generateOutputWiringParameter(t *testing.T) { outputDef := definition.Schema{ Type: "string", } - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ Outputs: map[string]bundle.Output{ "msg": { Definition: "stringDef", @@ -671,7 +671,7 @@ func TestNewManifestConverter_generateOutputWiringParameter(t *testing.T) { Definitions: map[string]*definition.Schema{ "stringDef": &outputDef, }, - }} + }) t.Run("generate parameter", func(t *testing.T) { t.Parallel() diff --git a/pkg/cnab/config-adapter/stamp_test.go b/pkg/cnab/config-adapter/stamp_test.go index d39fb1a0c..a9a3526c6 100644 --- a/pkg/cnab/config-adapter/stamp_test.go +++ b/pkg/cnab/config-adapter/stamp_test.go @@ -50,7 +50,7 @@ func TestConfig_GenerateStamp(t *testing.T) { func TestConfig_LoadStamp(t *testing.T) { t.Parallel() - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ config.CustomPorterKey: map[string]interface{}{ "manifestDigest": "somedigest", @@ -60,7 +60,7 @@ func TestConfig_LoadStamp(t *testing.T) { }, }, }, - }} + }) stamp, err := LoadStamp(bun) require.NoError(t, err) @@ -72,13 +72,13 @@ func TestConfig_LoadStamp(t *testing.T) { func TestConfig_LoadStamp_Invalid(t *testing.T) { t.Parallel() - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ config.CustomPorterKey: []string{ "somedigest", }, }, - }} + }) stamp, err := LoadStamp(bun) require.Error(t, err) diff --git a/pkg/cnab/dependencies_test.go b/pkg/cnab/dependencies_test.go index 327116308..0c12694a4 100644 --- a/pkg/cnab/dependencies_test.go +++ b/pkg/cnab/dependencies_test.go @@ -18,7 +18,7 @@ func TestReadDependencyProperties(t *testing.T) { b, err := bundle.Unmarshal(data) require.NoError(t, err, "could not unmarshal the bundle") - bun := ExtendedBundle{*b} + bun := NewBundle(*b) assert.True(t, bun.HasDependencies()) deps, err := bun.ReadDependencies() @@ -44,7 +44,7 @@ func TestDependencies_ListBySequence(t *testing.T) { sequenceMock := []string{"nginx", "storage", "mysql"} - bun := ExtendedBundle{bundle.Bundle{ + bun := NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ DependenciesExtensionKey: Dependencies{ Sequence: sequenceMock, @@ -68,7 +68,7 @@ func TestDependencies_ListBySequence(t *testing.T) { }, }, }, - }} + }) rawDeps, err := bun.ReadDependencies() orderedDeps := rawDeps.ListBySequence() @@ -92,9 +92,9 @@ func TestSupportsDependencies(t *testing.T) { t.Parallel() t.Run("supported", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ RequiredExtensions: []string{DependenciesExtensionKey}, - }} + }) assert.True(t, b.SupportsDependencies()) }) @@ -109,19 +109,19 @@ func TestHasDependencies(t *testing.T) { t.Parallel() t.Run("has dependencies", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ RequiredExtensions: []string{DependenciesExtensionKey}, Custom: map[string]interface{}{ DependenciesExtensionKey: struct{}{}, }, - }} + }) assert.True(t, b.HasDependencies()) }) t.Run("no dependencies", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ RequiredExtensions: []string{DependenciesExtensionKey}, - }} + }) assert.False(t, b.HasDependencies()) }) diff --git a/pkg/cnab/docker_test.go b/pkg/cnab/docker_test.go index 83f563256..59338725e 100644 --- a/pkg/cnab/docker_test.go +++ b/pkg/cnab/docker_test.go @@ -55,14 +55,14 @@ func TestSupportsDocker(t *testing.T) { t.Parallel() t.Run("supported", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ RequiredExtensions: []string{DockerExtensionKey}, - }} + }) assert.True(t, b.SupportsDocker()) }) t.Run("unsupported", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{}} + b := NewBundle(bundle.Bundle{}) assert.False(t, b.SupportsDocker()) }) diff --git a/pkg/cnab/extended_bundle.go b/pkg/cnab/extended_bundle.go index 16f45de70..04d3a13b1 100644 --- a/pkg/cnab/extended_bundle.go +++ b/pkg/cnab/extended_bundle.go @@ -17,6 +17,11 @@ type ExtendedBundle struct { bundle.Bundle } +// NewBundle creates an ExtendedBundle from a given bundle. +func NewBundle(bundle bundle.Bundle) ExtendedBundle { + return ExtendedBundle{bundle} +} + // LoadBundle from the specified filepath. func LoadBundle(c *portercontext.Context, bundleFile string) (ExtendedBundle, error) { bunD, err := c.FileSystem.ReadFile(bundleFile) @@ -29,7 +34,7 @@ func LoadBundle(c *portercontext.Context, bundleFile string) (ExtendedBundle, er return ExtendedBundle{}, errors.Wrapf(err, "cannot load bundle from\n%s at %s", string(bunD), bundleFile) } - return ExtendedBundle{*bun}, nil + return NewBundle(*bun), nil } // IsPorterBundle determines if the bundle was created by Porter. diff --git a/pkg/cnab/extended_bundle_test.go b/pkg/cnab/extended_bundle_test.go index 37cb04a23..b53c22e6d 100644 --- a/pkg/cnab/extended_bundle_test.go +++ b/pkg/cnab/extended_bundle_test.go @@ -11,11 +11,11 @@ import ( func TestExtendedBundle_IsPorterBundle(t *testing.T) { t.Run("made by porter", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ "sh.porter": struct{}{}, }, - }} + }) assert.True(t, b.IsPorterBundle()) }) @@ -35,7 +35,7 @@ func TestExtendedBundle_IsFileType(t *testing.T) { Type: "string", ContentEncoding: "base64", } - bun := ExtendedBundle{bundle.Bundle{ + bun := NewBundle(bundle.Bundle{ RequiredExtensions: []string{ FileParameterExtensionKey, }, @@ -52,7 +52,7 @@ func TestExtendedBundle_IsFileType(t *testing.T) { Definition: "file", }, }, - }} + }) assert.False(t, bun.IsFileType(stringDef), "strings should not be flagged as files") assert.True(t, bun.IsFileType(fileDef), "strings+base64 with the file-parameters extension should be categorized as files") @@ -70,7 +70,7 @@ func TestExtendedBundle_IsFileType(t *testing.T) { } func TestExtendedBundle_IsInternalParameter(t *testing.T) { - bun := ExtendedBundle{bundle.Bundle{ + bun := NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "foo": &definition.Schema{ Type: "string", @@ -91,7 +91,7 @@ func TestExtendedBundle_IsInternalParameter(t *testing.T) { Definition: "porter-debug", }, }, - }} + }) t.Run("empty bundle", func(t *testing.T) { b := ExtendedBundle{} @@ -117,7 +117,7 @@ func TestExtendedBundle_IsInternalParameter(t *testing.T) { func TestExtendedBundle_IsSensitiveParameter(t *testing.T) { sensitive := true - bun := ExtendedBundle{bundle.Bundle{ + bun := NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "foo": &definition.Schema{ Type: "string", @@ -139,7 +139,7 @@ func TestExtendedBundle_IsSensitiveParameter(t *testing.T) { Definition: "porter-debug", }, }, - }} + }) t.Run("empty bundle", func(t *testing.T) { b := ExtendedBundle{} diff --git a/pkg/cnab/extensions_test.go b/pkg/cnab/extensions_test.go index 8fc99b132..4045244d6 100644 --- a/pkg/cnab/extensions_test.go +++ b/pkg/cnab/extensions_test.go @@ -9,13 +9,13 @@ import ( func TestSupportsExtension(t *testing.T) { t.Run("key present", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{RequiredExtensions: []string{"io.test.thing"}}} + b := NewBundle(bundle.Bundle{RequiredExtensions: []string{"io.test.thing"}}) assert.True(t, b.SupportsExtension("io.test.thing")) }) t.Run("key missing", func(t *testing.T) { // We need to match against the full key, not just shorthand - b := ExtendedBundle{bundle.Bundle{RequiredExtensions: []string{"thing"}}} + b := NewBundle(bundle.Bundle{RequiredExtensions: []string{"thing"}}) assert.False(t, b.SupportsExtension("io.test.thing")) }) } diff --git a/pkg/cnab/file_parameter_test.go b/pkg/cnab/file_parameter_test.go index 8b8565d9e..3ac831270 100644 --- a/pkg/cnab/file_parameter_test.go +++ b/pkg/cnab/file_parameter_test.go @@ -35,14 +35,14 @@ func TestSupportsFileParameters(t *testing.T) { t.Parallel() t.Run("supported", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ RequiredExtensions: []string{FileParameterExtensionKey}, - }} + }) assert.True(t, b.SupportsFileParameters()) }) t.Run("unsupported", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{}} + b := NewBundle(bundle.Bundle{}) assert.False(t, b.SupportsFileParameters()) }) diff --git a/pkg/cnab/helpers.go b/pkg/cnab/helpers.go index 020cdbd50..5c330351f 100644 --- a/pkg/cnab/helpers.go +++ b/pkg/cnab/helpers.go @@ -15,5 +15,5 @@ func ReadTestBundle(t *testing.T, path string) ExtendedBundle { bun, err := bundle.Unmarshal(bunD) require.NoError(t, err, "Unmarshal failed for bundle at %s", path) - return ExtendedBundle{*bun} + return NewBundle(*bun) } diff --git a/pkg/cnab/parameter_sources_test.go b/pkg/cnab/parameter_sources_test.go index 6ee613fe5..228878c53 100644 --- a/pkg/cnab/parameter_sources_test.go +++ b/pkg/cnab/parameter_sources_test.go @@ -60,7 +60,7 @@ func TestReadParameterSourcesProperties(t *testing.T) { b, err := bundle.Unmarshal(data) require.NoError(t, err, "could not unmarshal the bundle") - bun := ExtendedBundle{*b} + bun := NewBundle(*b) assert.True(t, bun.HasParameterSources()) ps, err := bun.ReadParameterSources() @@ -88,9 +88,9 @@ func TestSupportsParameterSources(t *testing.T) { t.Parallel() t.Run("supported", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ RequiredExtensions: []string{ParameterSourcesExtensionKey}, - }} + }) assert.True(t, b.SupportsParameterSources()) }) @@ -105,19 +105,19 @@ func TestHasParameterSources(t *testing.T) { t.Parallel() t.Run("has parameter sources", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ RequiredExtensions: []string{ParameterSourcesExtensionKey}, Custom: map[string]interface{}{ ParameterSourcesExtensionKey: struct{}{}, }, - }} + }) assert.True(t, b.HasParameterSources()) }) t.Run("no parameter sources", func(t *testing.T) { - b := ExtendedBundle{bundle.Bundle{ + b := NewBundle(bundle.Bundle{ RequiredExtensions: []string{ParameterSourcesExtensionKey}, - }} + }) assert.False(t, b.HasParameterSources()) }) diff --git a/pkg/cnab/provider/action.go b/pkg/cnab/provider/action.go index ddf4c017d..d0f257f71 100644 --- a/pkg/cnab/provider/action.go +++ b/pkg/cnab/provider/action.go @@ -198,7 +198,7 @@ func (r *Runtime) CreateRun(ctx context.Context, args ActionArguments, b cnab.Ex currentRun.BundleDigest = args.BundleReference.Digest.String() var err error - extb := cnab.ExtendedBundle{b.Bundle} + extb := cnab.NewBundle(b.Bundle) currentRun.Parameters.Parameters, err = r.sanitizer.CleanRawParameters(ctx, args.Params, extb, currentRun.ID) if err != nil { return storage.Run{}, span.Error(err) @@ -271,7 +271,7 @@ func (r *Runtime) SaveOperationResult(ctx context.Context, opResult driver.Opera for outputName, outputValue := range opResult.Outputs { output := result.NewOutput(outputName, []byte(outputValue)) - output, err = r.sanitizer.CleanOutput(ctx, output, cnab.ExtendedBundle{run.Bundle}) + output, err = r.sanitizer.CleanOutput(ctx, output, cnab.ExtendedBundle{Bundle: run.Bundle}) if err != nil { bigerr = multierror.Append(bigerr, errors.Wrapf(err, "error sanitizing sensitive %s output for %s run of installation %s\n%#v", output.Name, run.Action, installation, output)) } diff --git a/pkg/cnab/provider/credentials_test.go b/pkg/cnab/provider/credentials_test.go index 4f7004bc9..8a03effaf 100644 --- a/pkg/cnab/provider/credentials_test.go +++ b/pkg/cnab/provider/credentials_test.go @@ -34,7 +34,7 @@ func TestRuntime_loadCredentials(t *testing.T) { err := r.credentials.InsertCredentialSet(context.Background(), cs1) require.NoError(t, err, "Save credential set failed") - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ Credentials: map[string]bundle.Credential{ "password": { Location: bundle.Location{ @@ -47,7 +47,7 @@ func TestRuntime_loadCredentials(t *testing.T) { }, }, }, - }} + }) args := ActionArguments{Installation: storage.Installation{CredentialSets: []string{"mycreds"}}, Action: "install"} gotValues, err := r.loadCredentials(context.Background(), b, args) @@ -65,7 +65,7 @@ func TestRuntime_loadCredentials(t *testing.T) { func TestRuntime_loadCredentials_WithApplyTo(t *testing.T) { getBundle := func(required bool) cnab.ExtendedBundle { - return cnab.ExtendedBundle{bundle.Bundle{ + return cnab.ExtendedBundle{Bundle: bundle.Bundle{ Credentials: map[string]bundle.Credential{ "password": { Location: bundle.Location{ diff --git a/pkg/cnab/solver_test.go b/pkg/cnab/solver_test.go index 7bb4018f9..c211f565a 100644 --- a/pkg/cnab/solver_test.go +++ b/pkg/cnab/solver_test.go @@ -11,7 +11,7 @@ import ( func TestDependencySolver_ResolveDependencies(t *testing.T) { t.Parallel() - bun := ExtendedBundle{bundle.Bundle{ + bun := NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ DependenciesExtensionKey: Dependencies{ Requires: map[string]Dependency{ @@ -24,7 +24,7 @@ func TestDependencySolver_ResolveDependencies(t *testing.T) { }, }, }, - }} + }) s := DependencySolver{} locks, err := s.ResolveDependencies(bun) diff --git a/pkg/generator/parameters_test.go b/pkg/generator/parameters_test.go index 2536f3560..9743f8e52 100644 --- a/pkg/generator/parameters_test.go +++ b/pkg/generator/parameters_test.go @@ -33,7 +33,7 @@ func TestGoodParametersName(t *testing.T) { Name: name, Silent: true, }, - Bundle: cnab.ExtendedBundle{bundle.Bundle{ + Bundle: cnab.NewBundle(bundle.Bundle{ Parameters: map[string]bundle.Parameter{ "one": { Definition: "one", @@ -46,7 +46,7 @@ func TestGoodParametersName(t *testing.T) { }, }, }, - }} + )} pset, err := opts.GenerateParameters() require.NoError(t, err, "name should NOT have resulted in an error") @@ -98,7 +98,7 @@ func TestSkipParameters(t *testing.T) { Name: name, Silent: true, }, - Bundle: cnab.ExtendedBundle{bundle.Bundle{ + Bundle: cnab.NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "porter-debug": &definition.Schema{ Comment: cnab.PorterInternal, @@ -110,7 +110,7 @@ func TestSkipParameters(t *testing.T) { }, }, }, - }} + )} pset, err := opts.GenerateParameters() require.NoError(t, err, "parameters generation should not have resulted in an error") diff --git a/pkg/plugins/pluggable/loader_test.go b/pkg/plugins/pluggable/loader_test.go index 882678a12..10b188962 100644 --- a/pkg/plugins/pluggable/loader_test.go +++ b/pkg/plugins/pluggable/loader_test.go @@ -51,7 +51,7 @@ func TestPluginLoader_SelectPlugin(t *testing.T) { c.Data.DefaultStorage = "azure" c.Data.StoragePlugins = []config.StoragePlugin{ { - config.PluginConfig{ + PluginConfig: config.PluginConfig{ Name: "azure", PluginSubKey: "azure.blob", Config: map[string]interface{}{ diff --git a/pkg/porter/dependencies.go b/pkg/porter/dependencies.go index 28a580223..abf5682ba 100644 --- a/pkg/porter/dependencies.go +++ b/pkg/porter/dependencies.go @@ -141,7 +141,7 @@ func (e *dependencyExecutioner) identifyDependencies(ctx context.Context) error return err } - bun = cnab.ExtendedBundle{c.Bundle} + bun = cnab.NewBundle(c.Bundle) } else { // If we hit here, there is a bug somewhere return errors.New("identifyDependencies failed to load the bundle because no bundle was specified. Please report this bug to https://github.com/getporter/porter/issues/new/choose") diff --git a/pkg/porter/examples/capture_output_example_test.go b/pkg/porter/examples/capture_output_example_test.go index ca36d77bb..317ec2ddf 100644 --- a/pkg/porter/examples/capture_output_example_test.go +++ b/pkg/porter/examples/capture_output_example_test.go @@ -9,7 +9,7 @@ import ( "get.porter.sh/porter/pkg/porter" ) -func ExampleCaptureOutput() { +func ExamplePorter_captureOutput() { // Create an instance of the Porter application p := porter.New() diff --git a/pkg/porter/examples/install_example_test.go b/pkg/porter/examples/install_example_test.go index bf33fb2c8..5675d0bb2 100644 --- a/pkg/porter/examples/install_example_test.go +++ b/pkg/porter/examples/install_example_test.go @@ -8,7 +8,7 @@ import ( "get.porter.sh/porter/pkg/porter" ) -func ExampleInstall() { +func ExamplePorter_install() { // Create an instance of the Porter application p := porter.New() diff --git a/pkg/porter/examples/pull_example_test.go b/pkg/porter/examples/pull_example_test.go index 1241dd0d2..bcc858a96 100644 --- a/pkg/porter/examples/pull_example_test.go +++ b/pkg/porter/examples/pull_example_test.go @@ -7,7 +7,7 @@ import ( "get.porter.sh/porter/pkg/porter" ) -func ExamplePullBundle() { +func ExamplePorter_pullBundle() { // Create an instance of the Porter application p := porter.New() diff --git a/pkg/porter/explain_test.go b/pkg/porter/explain_test.go index 152779dbd..6a32e3d1b 100644 --- a/pkg/porter/explain_test.go +++ b/pkg/porter/explain_test.go @@ -110,7 +110,7 @@ func TestExplain_generateYAML(t *testing.T) { } func TestExplain_generatePrintableBundleParams(t *testing.T) { - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ RequiredExtensions: []string{ cnab.FileParameterExtensionKey, }, @@ -140,7 +140,7 @@ func TestExplain_generatePrintableBundleParams(t *testing.T) { "commit": "3b7c85ba", }, }, - }} + }) pb, err := generatePrintable(bun, "") require.NoError(t, err) @@ -160,7 +160,7 @@ func TestExplain_generatePrintableBundleParams(t *testing.T) { } func TestExplain_generatePrintableBundleParamsWithAction(t *testing.T) { - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ RequiredExtensions: []string{ cnab.FileParameterExtensionKey, }, @@ -191,7 +191,7 @@ func TestExplain_generatePrintableBundleParamsWithAction(t *testing.T) { "commit": "3b7c85ba", }, }, - }} + }) t.Run("action applies", func(t *testing.T) { pb, err := generatePrintable(bun, "install") @@ -233,7 +233,7 @@ func TestExplain_generatePrintableBundleParamsWithAction(t *testing.T) { } func TestExplain_generatePrintableBundleOutputs(t *testing.T) { - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "string": &definition.Schema{ Type: "string", @@ -256,7 +256,7 @@ func TestExplain_generatePrintableBundleOutputs(t *testing.T) { "commit": "3b7c85ba", }, }, - }} + }) pb, err := generatePrintable(bun, "") require.NoError(t, err) @@ -288,7 +288,7 @@ func TestExplain_generatePrintableBundleOutputs(t *testing.T) { } func TestExplain_generatePrintableBundleCreds(t *testing.T) { - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Credentials: map[string]bundle.Credential{ "kubeconfig": { Required: true, @@ -306,7 +306,7 @@ func TestExplain_generatePrintableBundleCreds(t *testing.T) { "commit": "3b7c85ba", }, }, - }} + }) t.Run("action applies", func(t *testing.T) { pb, err := generatePrintable(bun, "install") @@ -348,7 +348,7 @@ func TestExplain_generatePrintableBundleCreds(t *testing.T) { } func TestExplain_generatePrintableBundlePorterVersion(t *testing.T) { - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "string": &definition.Schema{ Type: "string", @@ -362,7 +362,7 @@ func TestExplain_generatePrintableBundlePorterVersion(t *testing.T) { "commit": "3b7c85ba", }, }, - }} + }) pb, err := generatePrintable(bun, "") assert.NoError(t, err) @@ -371,14 +371,14 @@ func TestExplain_generatePrintableBundlePorterVersion(t *testing.T) { } func TestExplain_generatePrintableBundlePorterVersionNonPorterBundle(t *testing.T) { - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "string": &definition.Schema{ Type: "string", Default: "clippy", }, }, - }} + }) pb, err := generatePrintable(bun, "") assert.NoError(t, err) @@ -389,7 +389,7 @@ func TestExplain_generatePrintableBundlePorterVersionNonPorterBundle(t *testing. func TestExplain_generatePrintableBundleDependencies(t *testing.T) { sequenceMock := []string{"nginx", "storage", "mysql"} - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ cnab.DependenciesExtensionKey: cnab.Dependencies{ Sequence: sequenceMock, @@ -414,7 +414,7 @@ func TestExplain_generatePrintableBundleDependencies(t *testing.T) { "commit": "3b7c85ba", }, }, - }} + }) pd, err := generatePrintable(bun, "") assert.NoError(t, err) diff --git a/pkg/porter/helpers.go b/pkg/porter/helpers.go index d2bc539e4..f97cb4425 100644 --- a/pkg/porter/helpers.go +++ b/pkg/porter/helpers.go @@ -182,7 +182,7 @@ func (p *TestPorter) ReadBundle(path string) cnab.ExtendedBundle { bun, err := bundle.Unmarshal(bunD) require.NoError(p.T(), err, "Unmarshal failed for bundle at %s", path) - return cnab.ExtendedBundle{*bun} + return cnab.NewBundle(*bun) } func (p *TestPorter) RandomString(len int) string { diff --git a/pkg/porter/lifecycle.go b/pkg/porter/lifecycle.go index edfbfde58..7a61816f6 100644 --- a/pkg/porter/lifecycle.go +++ b/pkg/porter/lifecycle.go @@ -140,7 +140,7 @@ func (p *Porter) resolveBundleReference(ctx context.Context, opts *BundleActionO } bundleRef = cnab.BundleReference{ - Definition: cnab.ExtendedBundle{lastRun.Bundle}, + Definition: cnab.NewBundle(lastRun.Bundle), Digest: digest.Digest(lastRun.BundleDigest)} if lastRun.BundleReference != "" { diff --git a/pkg/porter/list.go b/pkg/porter/list.go index 84b746543..743c685b9 100644 --- a/pkg/porter/list.go +++ b/pkg/porter/list.go @@ -105,7 +105,7 @@ type DisplayInstallation struct { } type DisplayInstallationMetadata struct { - ResolvedParameters DisplayValues `json:"resolvedParameters", yaml:"resolvedParameters"` + ResolvedParameters DisplayValues `json:"resolvedParameters" yaml:"resolvedParameters"` } func NewDisplayInstallation(installation storage.Installation) DisplayInstallation { diff --git a/pkg/porter/outputs.go b/pkg/porter/outputs.go index 94a852811..1570748fa 100644 --- a/pkg/porter/outputs.go +++ b/pkg/porter/outputs.go @@ -135,7 +135,7 @@ func (p *Porter) ListBundleOutputs(ctx context.Context, opts *OutputListOptions) return nil, err } - bun := cnab.ExtendedBundle{c.Bundle} + bun := cnab.NewBundle(c.Bundle) displayOutputs := NewDisplayValuesFromOutputs(bun, resolved) if err != nil { diff --git a/pkg/porter/outputs_test.go b/pkg/porter/outputs_test.go index a4dafa131..43999c622 100644 --- a/pkg/porter/outputs_test.go +++ b/pkg/porter/outputs_test.go @@ -103,7 +103,7 @@ func TestPorter_PrintBundleOutputs(t *testing.T) { }, } - extB := cnab.ExtendedBundle{b} + extB := cnab.NewBundle(b) i := p.TestInstallations.CreateInstallation(storage.NewInstallation("", "test"), func(i *storage.Installation) { i.Parameters.Parameters = p.SanitizeParameters(i.Parameters.Parameters, i.ID, extB) }) diff --git a/pkg/porter/parameters_test.go b/pkg/porter/parameters_test.go index 9186e4ddd..9d02726d7 100644 --- a/pkg/porter/parameters_test.go +++ b/pkg/porter/parameters_test.go @@ -99,9 +99,9 @@ func Test_loadParameters_paramNotDefined(t *testing.T) { r := NewTestPorter(t) defer r.Close() - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ Parameters: map[string]bundle.Parameter{}, - }} + }) overrides := map[string]string{ "foo": "bar", @@ -118,13 +118,13 @@ func Test_loadParameters_definitionNotDefined(t *testing.T) { r := NewTestPorter(t) defer r.Close() - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ Parameters: map[string]bundle.Parameter{ "foo": { Definition: "foo", }, }, - }} + }) overrides := map[string]string{ "foo": "bar", @@ -143,7 +143,7 @@ func Test_loadParameters_applyTo(t *testing.T) { // Here we set default values, but expect nil/empty // values for parameters that do not apply to a given action - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "foo": &definition.Schema{ Type: "string", @@ -175,7 +175,7 @@ func Test_loadParameters_applyTo(t *testing.T) { }, }, }, - }} + }) overrides := map[string]string{ "foo": "FOO", @@ -198,7 +198,7 @@ func Test_loadParameters_applyToBundleDefaults(t *testing.T) { r := NewTestPorter(t) defer r.Close() - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "foo": &definition.Schema{ Type: "string", @@ -213,7 +213,7 @@ func Test_loadParameters_applyToBundleDefaults(t *testing.T) { }, }, }, - }} + }) i := storage.Installation{} params, err := r.resolveParameters(context.Background(), i, b, "action", nil) @@ -228,7 +228,7 @@ func Test_loadParameters_requiredButDoesNotApply(t *testing.T) { r := NewTestPorter(t) defer r.Close() - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ Definitions: definition.Definitions{ "foo": &definition.Schema{ Type: "string", @@ -243,7 +243,7 @@ func Test_loadParameters_requiredButDoesNotApply(t *testing.T) { Required: true, }, }, - }} + }) i := storage.Installation{} params, err := r.resolveParameters(context.Background(), i, b, "action", nil) @@ -260,7 +260,7 @@ func Test_loadParameters_fileParameter(t *testing.T) { r.TestConfig.TestContext.AddTestFile("testdata/file-param", "/path/to/file") - b := cnab.ExtendedBundle{bundle.Bundle{ + b := cnab.NewBundle(bundle.Bundle{ RequiredExtensions: []string{ cnab.FileParameterExtensionKey, }, @@ -279,7 +279,7 @@ func Test_loadParameters_fileParameter(t *testing.T) { }, }, }, - }} + }) overrides := map[string]string{ "foo": "/path/to/file", @@ -527,7 +527,7 @@ func Test_Paramapalooza(t *testing.T) { r := NewTestPorter(t) defer r.Close() - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Name: "mybuns", Version: "1.0.0", SchemaVersion: "v1.0.0", @@ -558,7 +558,7 @@ func Test_Paramapalooza(t *testing.T) { }, }, }, - }} + }) if tc.DefaultExists { bun.Definitions["my-param"].Default = "my-param-default" diff --git a/pkg/porter/publish.go b/pkg/porter/publish.go index 0e53e698d..8f9cf7dae 100644 --- a/pkg/porter/publish.go +++ b/pkg/porter/publish.go @@ -296,7 +296,7 @@ func (p *Porter) extractBundle(tmpDir, source string) (cnab.ExtendedBundle, erro return cnab.ExtendedBundle{}, errors.Wrapf(err, "failed to load bundle from archive %s", source) } - return cnab.ExtendedBundle{*bun}, nil + return cnab.NewBundle(*bun), nil } // pushUpdatedImage uses the provided layout to find the provided origImg, diff --git a/pkg/porter/publish_test.go b/pkg/porter/publish_test.go index 0596fb528..1a23570f0 100644 --- a/pkg/porter/publish_test.go +++ b/pkg/porter/publish_test.go @@ -149,7 +149,7 @@ func TestPublish_UpdateBundleWithNewImage(t *testing.T) { p := NewTestPorter(t) defer p.Close() - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Name: "mybuns", InvocationImages: []bundle.InvocationImage{ { @@ -167,7 +167,7 @@ func TestPublish_UpdateBundleWithNewImage(t *testing.T) { }, }, }, - }} + }) tag := "myneworg/mynewbuns" digest, err := image.NewDigest("sha256:6b5a28ccbb76f12ce771a23757880c6083234255c5ba191fca1c5db1f71c1687") @@ -198,7 +198,7 @@ func TestPublish_RefreshCachedBundle(t *testing.T) { bundleRef := cnab.BundleReference{ Reference: cnab.MustParseOCIReference("myreg/mybuns"), - Definition: cnab.ExtendedBundle{bundle.Bundle{Name: "myreg/mybuns"}}, + Definition: cnab.NewBundle(bundle.Bundle{Name: "myreg/mybuns"}), } // No-Op; bundle does not yet exist in cache @@ -234,7 +234,7 @@ func TestPublish_RefreshCachedBundle_OnlyWarning(t *testing.T) { bundleRef := cnab.BundleReference{ Reference: cnab.MustParseOCIReference("myreg/mybuns"), - Definition: cnab.ExtendedBundle{bundle.Bundle{Name: "myreg/mybuns"}}, + Definition: cnab.NewBundle(bundle.Bundle{Name: "myreg/mybuns"}), } p.TestCache.FindBundleMock = func(ref cnab.OCIReference) (cachedBundle cache.CachedBundle, found bool, err error) { diff --git a/pkg/porter/reconcile.go b/pkg/porter/reconcile.go index 39856ac87..8c0883ec5 100644 --- a/pkg/porter/reconcile.go +++ b/pkg/porter/reconcile.go @@ -221,7 +221,7 @@ func (p *Porter) IsInstallationInSync(ctx context.Context, i storage.Installatio return compParams, nil } - lastRunParams, err := p.Sanitizer.RestoreParameterSet(ctx, lastRun.Parameters, cnab.ExtendedBundle{lastRun.Bundle}) + lastRunParams, err := p.Sanitizer.RestoreParameterSet(ctx, lastRun.Parameters, cnab.NewBundle(lastRun.Bundle)) if err != nil { return false, err } diff --git a/pkg/porter/show.go b/pkg/porter/show.go index b529e4607..e39c2e6fc 100644 --- a/pkg/porter/show.go +++ b/pkg/porter/show.go @@ -175,7 +175,7 @@ func (p *Porter) NewDisplayInstallationWithSecrets(ctx context.Context, installa displayInstallation := NewDisplayInstallation(installation) if run != nil { - bun := cnab.ExtendedBundle{run.Bundle} + bun := cnab.NewBundle(run.Bundle) installParams, err := p.Sanitizer.RestoreParameterSet(ctx, installation.Parameters, bun) if err != nil { return DisplayInstallation{}, err diff --git a/pkg/porter/show_test.go b/pkg/porter/show_test.go index 1a94d40a3..2759a4f84 100644 --- a/pkg/porter/show_test.go +++ b/pkg/porter/show_test.go @@ -83,7 +83,7 @@ func TestPorter_ShowInstallationWithBundle(t *testing.T) { }, } - bun := cnab.ExtendedBundle{b} + bun := cnab.NewBundle(b) i := p.TestInstallations.CreateInstallation(storage.NewInstallation("dev", "mywordpress"), p.TestInstallations.SetMutableInstallationValues, func(i *storage.Installation) { if tc.ref != "" { i.TrackBundle(cnab.MustParseOCIReference(tc.ref)) @@ -198,7 +198,7 @@ func TestPorter_ShowInstallationWithoutRecordedRun(t *testing.T) { }, } - bun := cnab.ExtendedBundle{b} + bun := cnab.NewBundle(b) p.TestInstallations.CreateInstallation(storage.NewInstallation("dev", "mywordpress"), p.TestInstallations.SetMutableInstallationValues, func(i *storage.Installation) { i.TrackBundle(cnab.MustParseOCIReference("getporter/wordpress:v0.1.0")) i.Labels = map[string]string{ diff --git a/pkg/porter/testdata/show/expected-output.yaml b/pkg/porter/testdata/show/expected-output.yaml index 1586f6903..bffef6425 100644 --- a/pkg/porter/testdata/show/expected-output.yaml +++ b/pkg/porter/testdata/show/expected-output.yaml @@ -27,7 +27,7 @@ status: bundleVersion: 0.1.0 bundleDigest: sha256:88d68ef0bdb9cedc6da3a8e341a33e5d2f8bb19d0cf7ec3f1060d3f9eb73cae9 _calculated: - resolvedparameters: + resolvedParameters: - name: logLevel type: integer sensitive: false diff --git a/pkg/runtime/runtime-manifest.go b/pkg/runtime/runtime-manifest.go index 2bd8cb40c..c99b73d7f 100644 --- a/pkg/runtime/runtime-manifest.go +++ b/pkg/runtime/runtime-manifest.go @@ -109,7 +109,7 @@ func (m *RuntimeManifest) loadDependencyDefinitions() error { return errors.Wrapf(err, "error unmarshaling bundle definition for dependency %s", dep.Name) } - m.bundles[dep.Name] = cnab.ExtendedBundle{*bun} + m.bundles[dep.Name] = cnab.NewBundle(*bun) } return nil diff --git a/pkg/runtime/runtime-manifest_test.go b/pkg/runtime/runtime-manifest_test.go index 9b86d0f64..57f30357c 100644 --- a/pkg/runtime/runtime-manifest_test.go +++ b/pkg/runtime/runtime-manifest_test.go @@ -140,11 +140,11 @@ func TestDependencyMetadataAvailableForTemplating(t *testing.T) { require.NoError(t, err, "LoadManifestFrom failed") rm := NewRuntimeManifest(c.Context, cnab.ActionInstall, m) rm.bundles = map[string]cnab.ExtendedBundle{ - "mysql": {bundle.Bundle{ + "mysql": cnab.NewBundle(bundle.Bundle{ Name: "Azure MySQL", Description: "Azure MySQL database as a service", Version: "v1.0.0", - }}, + }), } before, _ := yaml.Marshal(m.Install[0]) @@ -340,15 +340,15 @@ func TestResolveStep_DependencyOutput(t *testing.T) { ps := cnab.ParameterSources{} ps.SetParameterFromDependencyOutput("porter-mysql-password", "mysql", "password") ps.SetParameterFromDependencyOutput("porter-mysql-root-password", "mysql", "root-password") - rm.bundle = cnab.ExtendedBundle{bundle.Bundle{ + rm.bundle = cnab.NewBundle(bundle.Bundle{ Custom: map[string]interface{}{ cnab.ParameterSourcesExtensionKey: ps, }, RequiredExtensions: []string{cnab.ParameterSourcesExtensionKey}, - }} + }) rm.bundles = map[string]cnab.ExtendedBundle{ - "mysql": {bundle.Bundle{ + "mysql": cnab.NewBundle(bundle.Bundle{ Outputs: map[string]bundle.Output{ "password": { Definition: "password", @@ -361,7 +361,7 @@ func TestResolveStep_DependencyOutput(t *testing.T) { "password": {WriteOnly: makeBoolPtr(true)}, "root-password": {WriteOnly: makeBoolPtr(true)}, }, - }}, + }), } s := &manifest.Step{ @@ -858,11 +858,11 @@ func TestResolveImageWithUpdatedBundle(t *testing.T) { img := bundle.Image{} img.Image = "blah/ghost:latest" img.Digest = "sha256:75c495e5ce9c428d482973d72e3ce9925e1db304a97946c9aa0b540d7537e041" - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Images: map[string]bundle.Image{ "machine": img, }, - }} + }) reloMap := relocation.ImageRelocationMap{} @@ -888,11 +888,11 @@ func TestResolveImageWithUpdatedMismatchedBundle(t *testing.T) { img := bundle.Image{} img.Image = "blah/ghost:latest" img.Digest = "sha256:75c495e5ce9c428d482973d72e3ce9925e1db304a97946c9aa0b540d7537e041" - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Images: map[string]bundle.Image{ "ghost": img, }, - }} + }) reloMap := relocation.ImageRelocationMap{} @@ -918,11 +918,11 @@ func TestResolveImageWithRelo(t *testing.T) { img := bundle.Image{} img.Image = "gabrtv/microservice@sha256:cca460afa270d4c527981ef9ca4989346c56cf9b20217dcea37df1ece8120687" img.Digest = "sha256:cca460afa270d4c527981ef9ca4989346c56cf9b20217dcea37df1ece8120687" - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Images: map[string]bundle.Image{ "machine": img, }, - }} + }) reloMap := relocation.ImageRelocationMap{ "gabrtv/microservice@sha256:cca460afa270d4c527981ef9ca4989346c56cf9b20217dcea37df1ece8120687": "my.registry/microservice@sha256:cca460afa270d4c527981ef9ca4989346c56cf9b20217dcea37df1ece8120687", @@ -950,11 +950,11 @@ func TestResolveImageRelocationNoMatch(t *testing.T) { img := bundle.Image{} img.Image = "deislabs/ghost:latest" img.Digest = "sha256:75c495e5ce9c428d482973d72e3ce9925e1db304a97946c9aa0b540d7537e041" - bun := cnab.ExtendedBundle{bundle.Bundle{ + bun := cnab.NewBundle(bundle.Bundle{ Images: map[string]bundle.Image{ "machine": img, }, - }} + }) reloMap := relocation.ImageRelocationMap{ "deislabs/nogood:latest": "cnabio/ghost:latest", diff --git a/pkg/runtime/runtime_test.go b/pkg/runtime/runtime_test.go index eba88d989..d1bb14101 100644 --- a/pkg/runtime/runtime_test.go +++ b/pkg/runtime/runtime_test.go @@ -258,7 +258,7 @@ func TestRuntimeManifest_ApplyUnboundBundleOutputs_File(t *testing.T) { }, } rm := NewRuntimeManifest(c.Context, cnab.ActionInstall, m) - rm.bundle = cnab.ExtendedBundle{bundle.Bundle{ + rm.bundle = cnab.NewBundle(bundle.Bundle{ Definitions: map[string]*definition.Schema{ tc.def.Name: &tc.def.Schema, }, @@ -268,7 +268,7 @@ func TestRuntimeManifest_ApplyUnboundBundleOutputs_File(t *testing.T) { Path: tc.def.Path, }, }, - }} + }) _, err := rm.FileSystem.Create(srcPath) require.NoError(t, err) diff --git a/pkg/storage/grpc_test.go b/pkg/storage/grpc_test.go index 951e3d6fd..575bacab6 100644 --- a/pkg/storage/grpc_test.go +++ b/pkg/storage/grpc_test.go @@ -41,7 +41,7 @@ func TestRoundTripDataOverGRPC(t *testing.T) { // Add an index to support filtering const collection = "things" err = client.EnsureIndex(ctx, plugins.EnsureIndexOptions{Indices: []plugins.Index{ - {Collection: collection, Keys: bson.D{{"namespace", 1}, {"name", 1}}}, + {Collection: collection, Keys: bson.D{{Key: "namespace", Value: 1}, {Key: "name", Value: 1}}}, }}) require.NoError(t, err) @@ -58,7 +58,7 @@ func TestRoundTripDataOverGRPC(t *testing.T) { results, err := client.Find(ctx, plugins.FindOptions{ Collection: collection, Filter: bson.M{"namespace": "dev"}, - Select: bson.D{{"name", 1}, {"namespace", 1}, {"_id", 0}}, + Select: bson.D{{Key: "name", Value: 1}, {Key: "namespace", Value: 1}, {Key: "_id", Value: 0}}, }) require.NoError(t, err) require.Len(t, results, 1) @@ -70,11 +70,11 @@ func TestRoundTripDataOverGRPC(t *testing.T) { opts := plugins.EnsureIndexOptions{ Indices: []plugins.Index{ // query most recent outputs by run (porter installation run show, when we list outputs) - {Collection: CollectionOutputs, Keys: bson.D{{"namespace", 1}, {"installation", 1}, {"-resultId", 1}}}, + {Collection: CollectionOutputs, Keys: bson.D{{Key: "namespace", Value: 1}, {Key: "installation", Value: 1}, {Key: "-resultId", Value: 1}}}, // query outputs by result (list) - {Collection: CollectionOutputs, Keys: bson.D{{"resultId", 1}, {"name", 1}}, Unique: true}, + {Collection: CollectionOutputs, Keys: bson.D{{Key: "resultId", Value: 1}, {Key: "name", Value: 1}}, Unique: true}, // query most recent outputs by name for an installation - {Collection: CollectionOutputs, Keys: bson.D{{"namespace", 1}, {"installation", 1}, {"name", 1}, {"-resultId", 1}}}, + {Collection: CollectionOutputs, Keys: bson.D{{Key: "namespace", Value: 1}, {Key: "installation", Value: 1}, {Key: "name", Value: 1}, {Key: "-resultId", Value: 1}}}, }, } @@ -94,21 +94,21 @@ func TestRoundTripDataOverGRPC(t *testing.T) { Collection: CollectionOutputs, Pipeline: []bson.D{ // List outputs by installation - {{"$match", bson.M{ + {{Key: "$match", Value: bson.M{ "namespace": "dev", "installation": "test", }}}, // Reverse sort them (newest on top) - {{"$sort", bson.D{ - {"namespace", 1}, - {"installation", 1}, - {"name", 1}, - {"resultId", -1}, + {{Key: "$sort", Value: bson.D{ + {Key: "namespace", Value: 1}, + {Key: "installation", Value: 1}, + {Key: "name", Value: 1}, + {Key: "resultId", Value: -1}, }}}, // Group them by output name and select the last value for each output - {{"$group", bson.D{ - {"_id", "$name"}, - {"lastOutput", bson.M{"$first": "$$ROOT"}}, + {{Key: "$group", Value: bson.D{ + {Key: "_id", Value: "$name"}, + {Key: "lastOutput", Value: bson.M{"$first": "$$ROOT"}}, }}}, }, }) diff --git a/pkg/storage/installation.go b/pkg/storage/installation.go index 2997e68b0..20a7ea5d2 100644 --- a/pkg/storage/installation.go +++ b/pkg/storage/installation.go @@ -200,7 +200,7 @@ type InstallationStatus struct { // Uninstalled indicates if the installation has successfully completed the uninstall action. // Once that state is reached, Porter should not allow further stateful actions. - Uninstalled *time.Time `json:"uninstalled" yaml"uninstalled" toml:"uninstalled"` + Uninstalled *time.Time `json:"uninstalled" yaml:"uninstalled" toml:"uninstalled"` // BundleReference of the bundle that last altered the installation state. BundleReference string `json:"bundleReference" yaml:"bundleReference" toml:"bundleReference"` diff --git a/pkg/storage/installation_store.go b/pkg/storage/installation_store.go index bfda84df0..04cc62b6b 100644 --- a/pkg/storage/installation_store.go +++ b/pkg/storage/installation_store.go @@ -212,21 +212,21 @@ func (s InstallationStore) GetLastOutputs(ctx context.Context, namespace string, opts := AggregateOptions{ Pipeline: []bson.D{ // List outputs by installation - {{"$match", bson.M{ + {{Key: "$match", Value: bson.M{ "namespace": namespace, "installation": installation, }}}, // Reverse sort them (newest on top) - {{"$sort", bson.D{ - {"namespace", 1}, - {"installation", 1}, - {"name", 1}, - {"resultId", -1}, + {{Key: "$sort", Value: bson.D{ + {Key: "namespace", Value: 1}, + {Key: "installation", Value: 1}, + {Key: "name", Value: 1}, + {Key: "resultId", Value: -1}, }}}, // Group them by output name and select the last value for each output - {{"$group", bson.D{ - {"_id", "$name"}, - {"lastOutput", bson.M{"$first": "$$ROOT"}}, + {{Key: "$group", Value: bson.D{ + {Key: "_id", Value: "$name"}, + {Key: "lastOutput", Value: bson.M{"$first": "$$ROOT"}}, }}}, }, } diff --git a/pkg/storage/installation_store_test.go b/pkg/storage/installation_store_test.go index 6c2ecaa34..58b4c8f88 100644 --- a/pkg/storage/installation_store_test.go +++ b/pkg/storage/installation_store_test.go @@ -229,7 +229,7 @@ func TestInstallationStorageProvider_Installations(t *testing.T) { t.Run("FindInstallations - project results", func(t *testing.T) { opts := FindOptions{ - Select: bson.D{{"labels", false}}, + Select: bson.D{{Key: "labels", Value: false}}, Sort: []string{"-id"}, Filter: bson.M{ "labels.team": "red", diff --git a/pkg/storage/pluginstore/grpc_test.go b/pkg/storage/pluginstore/grpc_test.go index d4bb775a5..22e530944 100644 --- a/pkg/storage/pluginstore/grpc_test.go +++ b/pkg/storage/pluginstore/grpc_test.go @@ -64,9 +64,9 @@ func TestConvertBsonM(t *testing.T) { func TestConvertBsonD(t *testing.T) { src := bson.D{ - {"a", "1"}, - {"b", bson.D{ - {"c", 1}, + {Key: "a", Value: "1"}, + {Key: "b", Value: bson.D{ + {Key: "c", Value: 1}, }}, } @@ -74,8 +74,8 @@ func TestConvertBsonD(t *testing.T) { dest := AsOrderedMap(tmp, ConvertSliceToBsonD) wantDest := bson.D{ - {"a", "1"}, - {"b", bson.D{{"c", int64(1)}}}, + {Key: "a", Value: "1"}, + {Key: "b", Value: bson.D{{Key: "c", Value: int64(1)}}}, } require.Equal(t, wantDest, dest) } diff --git a/pkg/storage/query.go b/pkg/storage/query.go index f19dab6cb..c6e9f33c6 100644 --- a/pkg/storage/query.go +++ b/pkg/storage/query.go @@ -57,7 +57,7 @@ func convertSortKeys(values []string) bson.D { sortKey = strings.Trim(key, "-") sortOrder = -1 } - keys[i] = bson.E{sortKey, sortOrder} + keys[i] = bson.E{Key: sortKey, Value: sortOrder} } return keys } diff --git a/pkg/storage/query_test.go b/pkg/storage/query_test.go index 133b5e3f0..701b4468e 100644 --- a/pkg/storage/query_test.go +++ b/pkg/storage/query_test.go @@ -69,8 +69,8 @@ func TestFindOptions_ToPluginOptions(t *testing.T) { } po := so.ToPluginOptions("mythings") wantSortDoc := bson.D{ - {"_id", -1}, - {"name", 1}} + {Key: "_id", Value: -1}, + {Key: "name", Value: 1}} require.Equal(t, wantSortDoc, po.Sort) } diff --git a/pkg/storage/run.go b/pkg/storage/run.go index 299e81398..ca1751b11 100644 --- a/pkg/storage/run.go +++ b/pkg/storage/run.go @@ -16,36 +16,36 @@ type Run struct { SchemaVersion schema.Version `json:"schemaVersion" yaml:"schemaVersion" toml:"schemaVersion"` // ID of the Run. - ID string `json:"_id" yaml:"_id", toml:"_id"` + ID string `json:"_id" yaml:"_id" toml:"_id"` // Created timestamp of the Run. - Created time.Time `json:"created" yaml:"created", toml:"created"` + Created time.Time `json:"created" yaml:"created" toml:"created"` // Namespace of the installation. - Namespace string `json:"namespace" yaml:"namespace", toml:"namespace"` + Namespace string `json:"namespace" yaml:"namespace" toml:"namespace"` // Installation name. - Installation string `json:"installation" yaml:"installation", toml:"installation"` + Installation string `json:"installation" yaml:"installation" toml:"installation"` // Revision of the installation. - Revision string `json:"revision" yaml:"revision", toml:"revision"` + Revision string `json:"revision" yaml:"revision" toml:"revision"` // Action executed against the installation. - Action string `json:"action" yaml:"action", toml:"action"` + Action string `json:"action" yaml:"action" toml:"action"` // Bundle is the definition of the bundle. - Bundle bundle.Bundle `json:"bundle" yaml:"bundle", toml:"bundle"` + Bundle bundle.Bundle `json:"bundle" yaml:"bundle" toml:"bundle"` // BundleReference is the canonical reference to the bundle used in the action. - BundleReference string `json:"bundleReference" yaml:"bundleReference", toml:"bundleReference"` + BundleReference string `json:"bundleReference" yaml:"bundleReference" toml:"bundleReference"` // BundleDigest is the digest of the bundle. // TODO(carolynvs): populate this - BundleDigest string `json:"bundleDigest" yaml:"bundleDigest", toml:"bundleDigest"` + BundleDigest string `json:"bundleDigest" yaml:"bundleDigest" toml:"bundleDigest"` // ParameterOverrides are the key/value parameter overrides (taking precedence over // parameters specified in a parameter set) specified during the run. - ParameterOverrides ParameterSet `json:"parameterOverrides, omitempty" yaml:"parameterOverrides, omitempty", toml:"parameterOverrides, omitempty"` + ParameterOverrides ParameterSet `json:"parameterOverrides,omitempty" yaml:"parameterOverrides,omitempty" toml:"parameterOverrides,omitempty"` // CredentialSets is a list of the credential set names used during the run. CredentialSets []string `json:"credentialSets,omitempty" yaml:"credentialSets,omitempty" toml:"credentialSets,omitempty"` @@ -61,7 +61,7 @@ type Run struct { // Custom extension data applicable to a given runtime. // TODO(carolynvs): remove custom and populate it in ToCNAB - Custom interface{} `json:"custom" yaml:"custom", toml:"custom"` + Custom interface{} `json:"custom" yaml:"custom" toml:"custom"` } func (r Run) DefaultDocumentFilter() map[string]interface{} { @@ -118,7 +118,7 @@ func (r Run) ToCNAB() cnab.Claim { // TypedParameterValues returns parameters values that have been converted to // its typed value based on its bundle definition. func (r Run) TypedParameterValues() map[string]interface{} { - bun := cnab.ExtendedBundle{r.Bundle} + bun := cnab.NewBundle(r.Bundle) value := make(map[string]interface{}) for _, param := range r.Parameters.Parameters {