diff --git a/pkg/porter/credentials.go b/pkg/porter/credentials.go index d8916509a..3fabf681d 100644 --- a/pkg/porter/credentials.go +++ b/pkg/porter/credentials.go @@ -70,6 +70,8 @@ type CredentialOptions struct { // For example, relative paths are converted to full paths and then checked that // they exist and are accessible. func (g *CredentialOptions) Validate(args []string, cxt *context.Context) error { + g.checkForDeprecatedTagValue() + err := g.validateCredName(args) if err != nil { return err diff --git a/pkg/porter/explain.go b/pkg/porter/explain.go index 087ed8d79..16a861fe0 100644 --- a/pkg/porter/explain.go +++ b/pkg/porter/explain.go @@ -123,6 +123,8 @@ func (s SortPrintableAction) Swap(i, j int) { } func (o *ExplainOpts) Validate(args []string, cxt *context.Context) error { + o.checkForDeprecatedTagValue() + err := o.validateInstallationName(args) if err != nil { return err diff --git a/pkg/porter/lifecycle.go b/pkg/porter/lifecycle.go index 9d04499b4..5373d46b2 100644 --- a/pkg/porter/lifecycle.go +++ b/pkg/porter/lifecycle.go @@ -26,11 +26,7 @@ type BundleActionOptions struct { } func (o *BundleActionOptions) Validate(args []string, porter *Porter) error { - // During the deprecation phase of the --tag flag, just assign reference to - // the supplied value - if o.Tag != "" { - o.Reference = o.Tag - } + o.checkForDeprecatedTagValue() if o.Reference != "" { // Ignore anything set based on the bundle directory we are in, go off of the tag diff --git a/pkg/porter/parameters.go b/pkg/porter/parameters.go index e4667802a..7a25e63fe 100644 --- a/pkg/porter/parameters.go +++ b/pkg/porter/parameters.go @@ -76,6 +76,8 @@ type ParameterOptions struct { // For example, relative paths are converted to full paths and then checked that // they exist and are accessible. func (g *ParameterOptions) Validate(args []string, cxt *context.Context) error { + g.checkForDeprecatedTagValue() + err := g.validateParamName(args) if err != nil { return err diff --git a/pkg/porter/pull.go b/pkg/porter/pull.go index b0d4633c0..84c76b8f2 100644 --- a/pkg/porter/pull.go +++ b/pkg/porter/pull.go @@ -14,6 +14,14 @@ type BundlePullOptions struct { Force bool } +func (b *BundlePullOptions) checkForDeprecatedTagValue() { + // During the deprecation phase of the --tag flag, just assign reference to + // the supplied value + if b.Tag != "" { + b.Reference = b.Tag + } +} + func (b BundlePullOptions) validateReference() error { _, err := cnabtooci.ParseOCIReference(b.Reference) if err != nil { diff --git a/pkg/porter/pull_test.go b/pkg/porter/pull_test.go index f76ac98eb..b2ebe325c 100644 --- a/pkg/porter/pull_test.go +++ b/pkg/porter/pull_test.go @@ -23,3 +23,25 @@ func TestBundlePullOptions_invalidtag(t *testing.T) { err := opts.validateReference() assert.Error(t, err, "invalid tag should produce an error") } + +func TestPull_checkForDeprecatedTagValue(t *testing.T) { + t.Parallel() + + t.Run("tag not set", func(t *testing.T) { + b := BundlePullOptions{} + + b.checkForDeprecatedTagValue() + assert.Equal(t, "", b.Tag) + assert.Equal(t, "", b.Reference) + }) + + t.Run("tag set", func(t *testing.T) { + b := BundlePullOptions{ + Tag: "getporter/hello:v0.1.0", + } + + b.checkForDeprecatedTagValue() + assert.Equal(t, "getporter/hello:v0.1.0", b.Tag) + assert.Equal(t, "getporter/hello:v0.1.0", b.Reference) + }) +}