diff --git a/cmd/oras/internal/display/handler.go b/cmd/oras/internal/display/handler.go index 7aeef4dc6..96a7ed68f 100644 --- a/cmd/oras/internal/display/handler.go +++ b/cmd/oras/internal/display/handler.go @@ -33,7 +33,7 @@ import ( ) // NewPushHandler returns status and metadata handlers for push command. -func NewPushHandler(format string, tty *os.File, out io.Writer, verbose bool) (status.PushHandler, metadata.PushHandler) { +func NewPushHandler(out io.Writer, format string, tty *os.File, verbose bool) (status.PushHandler, metadata.PushHandler) { var statusHandler status.PushHandler if tty != nil { statusHandler = status.NewTTYPushHandler(tty) @@ -56,7 +56,7 @@ func NewPushHandler(format string, tty *os.File, out io.Writer, verbose bool) (s } // NewAttachHandler returns status and metadata handlers for attach command. -func NewAttachHandler(format string, tty *os.File, out io.Writer, verbose bool) (status.AttachHandler, metadata.AttachHandler) { +func NewAttachHandler(out io.Writer, format string, tty *os.File, verbose bool) (status.AttachHandler, metadata.AttachHandler) { var statusHandler status.AttachHandler if tty != nil { statusHandler = status.NewTTYAttachHandler(tty) @@ -79,7 +79,7 @@ func NewAttachHandler(format string, tty *os.File, out io.Writer, verbose bool) } // NewPullHandler returns status and metadata handlers for pull command. -func NewPullHandler(format string, path string, tty *os.File, out io.Writer, verbose bool) (status.PullHandler, metadata.PullHandler) { +func NewPullHandler(out io.Writer, format string, path string, tty *os.File, verbose bool) (status.PullHandler, metadata.PullHandler) { var statusHandler status.PullHandler if tty != nil { statusHandler = status.NewTTYPullHandler(tty) diff --git a/cmd/oras/internal/display/metadata/json/attach.go b/cmd/oras/internal/display/metadata/json/attach.go index 15304d40e..3c224a798 100644 --- a/cmd/oras/internal/display/metadata/json/attach.go +++ b/cmd/oras/internal/display/metadata/json/attach.go @@ -39,5 +39,5 @@ func NewAttachHandler(out io.Writer) metadata.AttachHandler { // OnCompleted is called when the attach command is completed. func (ah *AttachHandler) OnCompleted(opts *option.Target, root, subject ocispec.Descriptor) error { - return utils.PrintPrettyJSON(ah.out, model.NewPush(root, opts.Path)) + return utils.PrintPrettyJSON(ah.out, model.NewAttach(root, opts.Path)) } diff --git a/cmd/oras/internal/display/metadata/json/push.go b/cmd/oras/internal/display/metadata/json/push.go index 86c86859f..9d1863a38 100644 --- a/cmd/oras/internal/display/metadata/json/push.go +++ b/cmd/oras/internal/display/metadata/json/push.go @@ -23,12 +23,14 @@ import ( "oras.land/oras/cmd/oras/internal/display/metadata/model" "oras.land/oras/cmd/oras/internal/display/utils" "oras.land/oras/cmd/oras/internal/option" + "oras.land/oras/internal/contentutil" ) // PushHandler handles JSON metadata output for push events. type PushHandler struct { - path string - out io.Writer + path string + out io.Writer + tagged model.Tagged } // NewPushHandler creates a new handler for push events. @@ -40,16 +42,20 @@ func NewPushHandler(out io.Writer) metadata.PushHandler { // OnTagged implements metadata.TagHandler. func (ph *PushHandler) OnTagged(desc ocispec.Descriptor, tag string) error { + ph.tagged.AddTag(tag) return nil } // OnCopied is called after files are copied. func (ph *PushHandler) OnCopied(opts *option.Target) error { + if opts.RawReference != "" && !contentutil.IsDigest(opts.Reference) { + ph.tagged.AddTag(opts.Reference) + } ph.path = opts.Path return nil } // OnCompleted is called after the push is completed. func (ph *PushHandler) OnCompleted(root ocispec.Descriptor) error { - return utils.PrintPrettyJSON(ph.out, model.NewPush(root, ph.path)) + return utils.PrintPrettyJSON(ph.out, model.NewPush(root, ph.path, ph.tagged.Tags())) } diff --git a/cmd/oras/internal/display/metadata/model/attach.go b/cmd/oras/internal/display/metadata/model/attach.go new file mode 100644 index 000000000..4323946b1 --- /dev/null +++ b/cmd/oras/internal/display/metadata/model/attach.go @@ -0,0 +1,28 @@ +/* +Copyright The ORAS Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package model + +import ocispec "github.com/opencontainers/image-spec/specs-go/v1" + +// attach contains metadata formatted by oras attach. +type attach struct { + Descriptor +} + +// NewAttach returns a metadata getter for attach command. +func NewAttach(desc ocispec.Descriptor, path string) any { + return attach{FromDescriptor(path, desc)} +} diff --git a/cmd/oras/internal/display/metadata/model/descriptor.go b/cmd/oras/internal/display/metadata/model/descriptor.go index 242d0ee4e..6e8a69bfd 100644 --- a/cmd/oras/internal/display/metadata/model/descriptor.go +++ b/cmd/oras/internal/display/metadata/model/descriptor.go @@ -21,13 +21,13 @@ import ( // DigestReference is a reference to an artifact with digest. type DigestReference struct { - Ref string `json:"ref"` + Reference string `json:"reference"` } // NewDigestReference creates a new digest reference. func NewDigestReference(name string, digest string) DigestReference { return DigestReference{ - Ref: name + "@" + digest, + Reference: name + "@" + digest, } } diff --git a/cmd/oras/internal/display/metadata/model/pull.go b/cmd/oras/internal/display/metadata/model/pull.go index 0b10fb752..9392902c2 100644 --- a/cmd/oras/internal/display/metadata/model/pull.go +++ b/cmd/oras/internal/display/metadata/model/pull.go @@ -63,7 +63,7 @@ type pull struct { func NewPull(digestReference string, files []File) any { return pull{ DigestReference: DigestReference{ - Ref: digestReference, + Reference: digestReference, }, Files: files, } diff --git a/cmd/oras/internal/display/metadata/model/push.go b/cmd/oras/internal/display/metadata/model/push.go index c07f53c75..bca7cf526 100644 --- a/cmd/oras/internal/display/metadata/model/push.go +++ b/cmd/oras/internal/display/metadata/model/push.go @@ -15,14 +15,24 @@ limitations under the License. package model -import ocispec "github.com/opencontainers/image-spec/specs-go/v1" +import ( + ocispec "github.com/opencontainers/image-spec/specs-go/v1" +) // push contains metadata formatted by oras push. type push struct { Descriptor + ReferenceAsTags []string `json:"referenceAsTags"` } // NewPush returns a metadata getter for push command. -func NewPush(desc ocispec.Descriptor, path string) any { - return push{FromDescriptor(path, desc)} +func NewPush(desc ocispec.Descriptor, path string, tags []string) any { + var refAsTags []string + for _, tag := range tags { + refAsTags = append(refAsTags, path+":"+tag) + } + return push{ + Descriptor: FromDescriptor(path, desc), + ReferenceAsTags: refAsTags, + } } diff --git a/cmd/oras/internal/display/metadata/model/tag.go b/cmd/oras/internal/display/metadata/model/tag.go new file mode 100644 index 000000000..fdfd1608c --- /dev/null +++ b/cmd/oras/internal/display/metadata/model/tag.go @@ -0,0 +1,43 @@ +/* +Copyright The ORAS Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package model + +import ( + "slices" + "sync" +) + +// Tagged contains metadata formatted by oras Tagged. +type Tagged struct { + tags []string + lock sync.RWMutex +} + +// AddTag adds a tag to the metadata. +func (tag *Tagged) AddTag(t string) { + tag.lock.Lock() + defer tag.lock.Unlock() + + tag.tags = append(tag.tags, t) +} + +// Tags returns the tags. +func (tag *Tagged) Tags() []string { + tag.lock.RLock() + defer tag.lock.RUnlock() + slices.Sort(tag.tags) + return tag.tags +} diff --git a/cmd/oras/internal/display/metadata/template/attach.go b/cmd/oras/internal/display/metadata/template/attach.go index 724a8a50f..b18b3a285 100644 --- a/cmd/oras/internal/display/metadata/template/attach.go +++ b/cmd/oras/internal/display/metadata/template/attach.go @@ -40,5 +40,5 @@ func NewAttachHandler(out io.Writer, template string) metadata.AttachHandler { // OnCompleted formats the metadata of attach command. func (ah *AttachHandler) OnCompleted(opts *option.Target, root, subject ocispec.Descriptor) error { - return parseAndWrite(ah.out, model.NewPush(root, opts.Path), ah.template) + return parseAndWrite(ah.out, model.NewAttach(root, opts.Path), ah.template) } diff --git a/cmd/oras/internal/display/metadata/template/push.go b/cmd/oras/internal/display/metadata/template/push.go index ba2212dd5..2829ee274 100644 --- a/cmd/oras/internal/display/metadata/template/push.go +++ b/cmd/oras/internal/display/metadata/template/push.go @@ -22,12 +22,14 @@ import ( "oras.land/oras/cmd/oras/internal/display/metadata" "oras.land/oras/cmd/oras/internal/display/metadata/model" "oras.land/oras/cmd/oras/internal/option" + "oras.land/oras/internal/contentutil" ) // PushHandler handles go-template metadata output for push events. type PushHandler struct { template string path string + tagged model.Tagged out io.Writer } @@ -41,16 +43,20 @@ func NewPushHandler(out io.Writer, template string) metadata.PushHandler { // OnTagged implements metadata.TagHandler. func (ph *PushHandler) OnTagged(desc ocispec.Descriptor, tag string) error { + ph.tagged.AddTag(tag) return nil } // OnStarted is called after files are copied. func (ph *PushHandler) OnCopied(opts *option.Target) error { + if opts.RawReference != "" && !contentutil.IsDigest(opts.Reference) { + ph.tagged.AddTag(opts.Reference) + } ph.path = opts.Path return nil } // OnCompleted is called after the push is completed. func (ph *PushHandler) OnCompleted(root ocispec.Descriptor) error { - return parseAndWrite(ph.out, model.NewPush(root, ph.path), ph.template) + return parseAndWrite(ph.out, model.NewPush(root, ph.path, ph.tagged.Tags()), ph.template) } diff --git a/cmd/oras/root/attach.go b/cmd/oras/root/attach.go index 7b9662ce4..f86c6a0a1 100644 --- a/cmd/oras/root/attach.go +++ b/cmd/oras/root/attach.go @@ -119,7 +119,7 @@ func runAttach(cmd *cobra.Command, opts *attachOptions) error { Recommendation: `To attach to an existing artifact, please provide files via argument or annotations via flag "--annotation". Run "oras attach -h" for more options and examples`, } } - displayStatus, displayMetadata := display.NewAttachHandler(opts.Template, opts.TTY, cmd.OutOrStdout(), opts.Verbose) + displayStatus, displayMetadata := display.NewAttachHandler(cmd.OutOrStdout(), opts.Template, opts.TTY, opts.Verbose) // prepare manifest store, err := file.New("") diff --git a/cmd/oras/root/discover.go b/cmd/oras/root/discover.go index b3e7b695a..89e439837 100644 --- a/cmd/oras/root/discover.go +++ b/cmd/oras/root/discover.go @@ -96,11 +96,11 @@ Example - Discover referrers of the manifest tagged 'v1' in an OCI image layout cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "artifact type") cmd.Flags().StringVarP(&opts.Template, "output", "o", "tree", "[Deprecated] format in which to display referrers (table, json, or tree). tree format will also show indirect referrers") - cmd.Flags().StringVarP(&opts.Template, "format", "", "tree", `[Experimental] Format output using a custom template: + cmd.Flags().StringVarP(&opts.Template, "format", "", "", `[Experimental] Format output using a custom template: 'tree': Get referrers recursively and print in tree format (default) 'table': Get direct referrers and output in table format 'json': Get direct referrers and output in JSON format -'$TEMPLATE': Print direct referrers using the given Go template.`) +'$TEMPLATE': Print direct referrers using the given Go template`) opts.EnableDistributionSpecFlag() option.ApplyFlags(&opts, cmd.Flags()) return oerrors.Command(cmd, &opts.Target) diff --git a/cmd/oras/root/pull.go b/cmd/oras/root/pull.go index 9dc62cbb1..1ed0ef4de 100644 --- a/cmd/oras/root/pull.go +++ b/cmd/oras/root/pull.go @@ -135,7 +135,7 @@ func runPull(cmd *cobra.Command, opts *pullOptions) error { dst.AllowPathTraversalOnWrite = opts.PathTraversal dst.DisableOverwrite = opts.KeepOldFiles - statusHandler, metadataHandler := display.NewPullHandler(opts.Template, opts.Path, opts.TTY, cmd.OutOrStdout(), opts.Verbose) + statusHandler, metadataHandler := display.NewPullHandler(cmd.OutOrStdout(), opts.Template, opts.Path, opts.TTY, opts.Verbose) desc, err := doPull(ctx, src, dst, copyOptions, metadataHandler, statusHandler, opts) if err != nil { if errors.Is(err, file.ErrPathTraversalDisallowed) { diff --git a/cmd/oras/root/push.go b/cmd/oras/root/push.go index cab1b3c74..6cf4c44f8 100644 --- a/cmd/oras/root/push.go +++ b/cmd/oras/root/push.go @@ -155,7 +155,7 @@ func runPush(cmd *cobra.Command, opts *pushOptions) error { if err != nil { return err } - displayStatus, displayMetadata := display.NewPushHandler(opts.Template, opts.TTY, cmd.OutOrStdout(), opts.Verbose) + displayStatus, displayMetadata := display.NewPushHandler(cmd.OutOrStdout(), opts.Template, opts.TTY, opts.Verbose) // prepare pack packOpts := oras.PackManifestOptions{ diff --git a/cmd/oras/root/repo/tags.go b/cmd/oras/root/repo/tags.go index 62b5714af..b3daaffb1 100644 --- a/cmd/oras/root/repo/tags.go +++ b/cmd/oras/root/repo/tags.go @@ -25,6 +25,7 @@ import ( "oras.land/oras/cmd/oras/internal/command" oerrors "oras.land/oras/cmd/oras/internal/errors" "oras.land/oras/cmd/oras/internal/option" + "oras.land/oras/internal/contentutil" ) type showTagsOptions struct { @@ -87,8 +88,7 @@ func showTags(cmd *cobra.Command, opts *showTagsOptions) error { } filter := "" if opts.Reference != "" { - _, err := digest.Parse(opts.Reference) - if err == nil { + if contentutil.IsDigest(opts.Reference) { filter = opts.Reference } else { desc, err := finder.Resolve(ctx, opts.Reference) diff --git a/internal/contentutil/reference.go b/internal/contentutil/reference.go new file mode 100644 index 000000000..4a374b234 --- /dev/null +++ b/internal/contentutil/reference.go @@ -0,0 +1,24 @@ +/* +Copyright The ORAS Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package contentutil + +import "github.com/opencontainers/go-digest" + +// IsDigest checks if the given string is a valid digest. +func IsDigest(tagOrDigest string) bool { + _, err := digest.Parse(tagOrDigest) + return err == nil +} diff --git a/test/e2e/suite/command/attach.go b/test/e2e/suite/command/attach.go index b6af282c4..4d9f4dc11 100644 --- a/test/e2e/suite/command/attach.go +++ b/test/e2e/suite/command/attach.go @@ -121,7 +121,7 @@ var _ = Describe("1.1 registry users:", func() { subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag) CopyZOTRepo(ImageRepo, testRepo) // test - ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName, "--format", "{{.ref}}"). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName, "--format", "{{.reference}}"). WithWorkDir(tempDir).Exec().Out.Contents() // validate fetched := ORAS("manifest", "fetch", string(ref)).Exec().Out.Contents() @@ -137,7 +137,7 @@ var _ = Describe("1.1 registry users:", func() { CopyZOTRepo(ImageRepo, testRepo) // test delimitter := "---" - output := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName, "--format", fmt.Sprintf("{{.ref}}%s{{.artifactType}}", delimitter)). + output := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName, "--format", fmt.Sprintf("{{.reference}}%s{{.artifactType}}", delimitter)). WithWorkDir(tempDir).Exec().Out.Contents() ref, artifactType, _ := strings.Cut(string(output), delimitter) // validate @@ -167,12 +167,12 @@ var _ = Describe("1.1 registry users:", func() { subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag) CopyZOTRepo(ImageRepo, testRepo) // test - ref1 := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.ref}}"). + ref1 := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.reference}}"). WithWorkDir(tempDir).Exec().Out.Contents() - ref2 := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.ref}}"). + ref2 := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.reference}}"). WithWorkDir(tempDir).Exec().Out.Contents() // validate - ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .ref}}{{end}}").MatchKeyWords(string(ref1), string(ref2)).Exec() + ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .reference}}{{end}}").MatchKeyWords(string(ref1), string(ref2)).Exec() }) It("should attach a file via a OCI Image", func() { @@ -181,10 +181,10 @@ var _ = Describe("1.1 registry users:", func() { subjectRef := RegistryRef(ZOTHost, testRepo, foobar.Tag) CopyZOTRepo(ImageRepo, testRepo) // test - ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.ref}}"). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.reference}}"). WithWorkDir(tempDir).Exec().Out.Contents() // validate - out := ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .ref}}{{end}}").Exec().Out + out := ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .reference}}{{end}}").Exec().Out Expect(out).To(gbytes.Say(string(ref))) }) @@ -222,10 +222,10 @@ var _ = Describe("1.0 registry users:", func() { subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag) prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef) // test - ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.ref}}"). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.reference}}"). WithWorkDir(tempDir).Exec().Out.Contents() // validate - out := ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .ref}}{{end}}").Exec().Out + out := ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .reference}}{{end}}").Exec().Out Expect(out).To(gbytes.Say(string(ref))) }) @@ -235,11 +235,11 @@ var _ = Describe("1.0 registry users:", func() { subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag) prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef) // test - ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.ref}}"). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.reference}}"). WithWorkDir(tempDir).Exec().Out.Contents() // validate - out := ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .ref}}{{end}}").Exec().Out + out := ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .reference}}{{end}}").Exec().Out Expect(out).To(gbytes.Say(string(ref))) }) @@ -249,11 +249,11 @@ var _ = Describe("1.0 registry users:", func() { subjectRef := RegistryRef(FallbackHost, testRepo, foobar.Tag) prepare(RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag), subjectRef) // test - ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--distribution-spec", "v1.1-referrers-tag", "--format", "{{.ref}}"). + ref := ORAS("attach", "--artifact-type", "test/attach", subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--distribution-spec", "v1.1-referrers-tag", "--format", "{{.reference}}"). WithWorkDir(tempDir).Exec().Out.Contents() // validate - out := ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .ref}}{{end}}").Exec().Out + out := ORAS("discover", subjectRef, "--format", "{{range .manifests}}{{println .reference}}{{end}}").Exec().Out Expect(out).To(gbytes.Say(string(ref))) }) }) @@ -275,7 +275,7 @@ var _ = Describe("OCI image layout users:", func() { root := PrepareTempOCI(ImageRepo) subjectRef := LayoutRef(root, foobar.Tag) // test - ref := ORAS("attach", "--artifact-type", "test/attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName, "--format", "{{.ref}}"). + ref := ORAS("attach", "--artifact-type", "test/attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--export-manifest", exportName, "--format", "{{.reference}}"). WithWorkDir(root).Exec().Out.Contents() // validate fetched := ORAS("manifest", "fetch", Flags.Layout, string(ref)).Exec().Out.Contents() @@ -297,10 +297,10 @@ var _ = Describe("OCI image layout users:", func() { root := PrepareTempOCI(ImageRepo) subjectRef := LayoutRef(root, foobar.Tag) // test - ref := ORAS("attach", "--artifact-type", "test/attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.ref}}"). + ref := ORAS("attach", "--artifact-type", "test/attach", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--format", "{{.reference}}"). WithWorkDir(root).Exec().Out.Contents() // validate - out := ORAS("discover", Flags.Layout, subjectRef, "--format", "{{range .manifests}}{{println .ref}}{{end}}").Exec().Out + out := ORAS("discover", Flags.Layout, subjectRef, "--format", "{{range .manifests}}{{println .reference}}{{end}}").Exec().Out Expect(out).To(gbytes.Say(string(ref))) }) }) diff --git a/test/e2e/suite/command/discover.go b/test/e2e/suite/command/discover.go index 8201f9953..082ee4eb3 100644 --- a/test/e2e/suite/command/discover.go +++ b/test/e2e/suite/command/discover.go @@ -204,7 +204,7 @@ var _ = Describe("1.1 registry users:", func() { }) When("running discover command with go-template output", func() { It("should show referrers digest of a subject", func() { - ORAS("discover", subjectRef, "--format", "{{(first .manifests).ref}}"). + ORAS("discover", subjectRef, "--format", "{{(first .manifests).reference}}"). MatchContent(RegistryRef(ZOTHost, ArtifactRepo, foobar.SBOMImageReferrer.Digest.String())). Exec() }) diff --git a/test/e2e/suite/command/push.go b/test/e2e/suite/command/push.go index e08c855a6..39beace43 100644 --- a/test/e2e/suite/command/push.go +++ b/test/e2e/suite/command/push.go @@ -180,8 +180,8 @@ var _ = Describe("Remote registry users:", func() { tempDir := PrepareTempFiles() extraTag := "2e2" - ORAS("push", fmt.Sprintf("%s,%s", RegistryRef(ZOTHost, repo, tag), extraTag), foobar.FileBarName, "-v"). - MatchStatus(statusKeys, true, len(statusKeys)). + ORAS("push", fmt.Sprintf("%s,%s", RegistryRef(ZOTHost, repo, tag), extraTag), foobar.FileBarName, "-v", "--format", "{{range .referenceAsTags}}{{println .}}{{end}}"). + MatchContent(fmt.Sprintf("%s\n%s\n", RegistryRef(ZOTHost, repo, extraTag), RegistryRef(ZOTHost, repo, tag))). WithWorkDir(tempDir).Exec() // validate @@ -200,10 +200,10 @@ var _ = Describe("Remote registry users:", func() { tempDir := PrepareTempFiles() extraTag := "2e2" - ORAS("push", fmt.Sprintf("%s,%s", RegistryRef(ZOTHost, repo, tag), extraTag), foobar.FileBarName, "-v", "--format", "{{.mediaType}}"). + out := ORAS("push", fmt.Sprintf("%s,%s", RegistryRef(ZOTHost, repo, tag), extraTag), foobar.FileBarName, "-v", "--format", "json"). WithWorkDir(tempDir). - MatchContent("application/vnd.oci.image.manifest.v1+json"). - Exec() + Exec().Out.Contents() + Expect(json.Unmarshal(out, &struct{}{})).ShouldNot(HaveOccurred()) }) It("should push files with customized media types", func() { @@ -367,7 +367,7 @@ var _ = Describe("Remote registry users:", func() { annotationValue := "value" // test - out := ORAS("push", RegistryRef(ZOTHost, repo, tag), "-a", fmt.Sprintf("%s=%s", annotationKey, annotationValue), "--format", "{{.ref}}"). + out := ORAS("push", RegistryRef(ZOTHost, repo, tag), "-a", fmt.Sprintf("%s=%s", annotationKey, annotationValue), "--format", "{{.reference}}"). WithWorkDir(tempDir).Exec().Out // validate diff --git a/test/e2e/suite/scenario/oci_artifact.go b/test/e2e/suite/scenario/oci_artifact.go index 704c41fb6..41703764e 100644 --- a/test/e2e/suite/scenario/oci_artifact.go +++ b/test/e2e/suite/scenario/oci_artifact.go @@ -64,7 +64,7 @@ var _ = Describe("OCI artifact users:", Ordered, func() { WithWorkDir(tempDir). WithDescription("attach with manifest exported").Exec() - ref := string(ORAS("discover", subject, "--format", "{{(first .manifests).ref}}").Exec().Out.Contents()) + ref := string(ORAS("discover", subject, "--format", "{{(first .manifests).reference}}").Exec().Out.Contents()) fetched := ORAS("manifest", "fetch", ref).MatchKeyWords(foobar.AttachFileMedia).Exec() MatchFile(filepath.Join(tempDir, pulledManifest), string(fetched.Out.Contents()), DefaultTimeout) @@ -81,7 +81,7 @@ var _ = Describe("OCI artifact users:", Ordered, func() { WithWorkDir(tempDir). WithDescription("attach again with manifest exported").Exec() - ref = string(ORAS("discover", subject, "--format", "{{(first .manifests).ref}}", "--artifact-type", "test/artifact2").Exec().Out.Contents()) + ref = string(ORAS("discover", subject, "--format", "{{(first .manifests).reference}}", "--artifact-type", "test/artifact2").Exec().Out.Contents()) fetched = ORAS("manifest", "fetch", ref).MatchKeyWords(foobar.AttachFileMedia).Exec() MatchFile(filepath.Join(tempDir, pulledManifest), string(fetched.Out.Contents()), DefaultTimeout)