From 26430ecbdae182928b5efbafcf29677a746d1215 Mon Sep 17 00:00:00 2001 From: "Lixia (Sylvia) Lei" Date: Fri, 17 Jan 2025 19:50:08 +0800 Subject: [PATCH 1/4] fix: scope action only has pull when get service token in executing cmd org push (#1608) Signed-off-by: hopegi <690383065@qq.com> Co-authored-by: hopegi <690383065@qq.com> --- cmd/oras/root/push.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/root/push.go b/cmd/oras/root/push.go index 1b7396aa2..c6b8b5d90 100644 --- a/cmd/oras/root/push.go +++ b/cmd/oras/root/push.go @@ -255,7 +255,7 @@ func runPush(cmd *cobra.Command, opts *pushOptions) error { copyWithScopeHint := func(root ocispec.Descriptor) error { // add both pull and push scope hints for dst repository // to save potential push-scope token requests during copy - ctx = registryutil.WithScopeHint(ctx, dst, auth.ActionPull, auth.ActionPush) + ctx = registryutil.WithScopeHint(ctx, originalDst, auth.ActionPull, auth.ActionPush) if tag := opts.Reference; tag == "" { err = oras.CopyGraph(ctx, union, dst, root, copyOptions.CopyGraphOptions) From ad8c845d830ea7b5c37a24d45784c3faf112586e Mon Sep 17 00:00:00 2001 From: Praful Khanduri <99384392+Horiodino@users.noreply.github.com> Date: Tue, 21 Jan 2025 17:20:04 +0530 Subject: [PATCH 2/4] fix: mark `--oci-layout-path` as experimental (#1607) Signed-off-by: Horiodino Co-authored-by: Terry Howe --- cmd/oras/internal/option/target.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index 839f376db..4c832bb25 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -85,7 +85,7 @@ func (opts *Target) AnnotatedReference() string { func (opts *Target) applyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description string) { flagPrefix, notePrefix := applyPrefix(prefix, description) fs.BoolVarP(&opts.IsOCILayout, flagPrefix+"oci-layout", "", false, "set "+notePrefix+"target as an OCI image layout") - fs.StringVar(&opts.Path, flagPrefix+"oci-layout-path", "", "set the path for the "+notePrefix+"OCI image layout target") + fs.StringVar(&opts.Path, flagPrefix+"oci-layout-path", "", "[Experimental] Set the path for the "+notePrefix+"OCI image layout target") } // ApplyFlagsWithPrefix applies flags to a command flag set with a prefix string. From 13dce59433e31be5fc0113684566ae9d45948f14 Mon Sep 17 00:00:00 2001 From: "Lixia (Sylvia) Lei" Date: Wed, 22 Jan 2025 20:00:28 +0800 Subject: [PATCH 3/4] docs: update the help doc for `--oci-layout-path` (#1609) Signed-off-by: Lixia (Sylvia) Lei --- cmd/oras/internal/option/format.go | 4 ++-- cmd/oras/internal/option/target.go | 2 +- test/e2e/suite/command/cp.go | 4 +++- test/e2e/suite/command/pull.go | 1 + test/e2e/suite/command/push.go | 1 + 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/oras/internal/option/format.go b/cmd/oras/internal/option/format.go index 76acdc105..75a496342 100644 --- a/cmd/oras/internal/option/format.go +++ b/cmd/oras/internal/option/format.go @@ -86,7 +86,7 @@ func (f *Format) SetTypes(defaultType *FormatType, otherTypes ...*FormatType) { // ApplyFlags implements FlagProvider.ApplyFlag. func (opts *Format) ApplyFlags(fs *pflag.FlagSet) { - buf := bytes.NewBufferString("[Experimental] Format output using a custom template:") + buf := bytes.NewBufferString("[Experimental] format output using a custom template:") w := tabwriter.NewWriter(buf, 0, 0, 2, ' ', 0) for _, t := range opts.allowedTypes { _, _ = fmt.Fprintf(w, "\n'%s':\t%s", t.Name, t.Usage) @@ -94,7 +94,7 @@ func (opts *Format) ApplyFlags(fs *pflag.FlagSet) { _ = w.Flush() // apply flags fs.StringVar(&opts.FormatFlag, "format", opts.FormatFlag, buf.String()) - fs.StringVar(&opts.Template, "template", "", "[Experimental] Template string used to format output") + fs.StringVar(&opts.Template, "template", "", "[Experimental] template string used to format output") } // Parse parses the input format flag. diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index 4c832bb25..7fd795ead 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -85,7 +85,7 @@ func (opts *Target) AnnotatedReference() string { func (opts *Target) applyFlagsWithPrefix(fs *pflag.FlagSet, prefix, description string) { flagPrefix, notePrefix := applyPrefix(prefix, description) fs.BoolVarP(&opts.IsOCILayout, flagPrefix+"oci-layout", "", false, "set "+notePrefix+"target as an OCI image layout") - fs.StringVar(&opts.Path, flagPrefix+"oci-layout-path", "", "[Experimental] Set the path for the "+notePrefix+"OCI image layout target") + fs.StringVar(&opts.Path, flagPrefix+"oci-layout-path", "", "[Experimental] set the path for the "+notePrefix+"OCI image layout target") } // ApplyFlagsWithPrefix applies flags to a command flag set with a prefix string. diff --git a/test/e2e/suite/command/cp.go b/test/e2e/suite/command/cp.go index 169629c2a..90dd8f40b 100644 --- a/test/e2e/suite/command/cp.go +++ b/test/e2e/suite/command/cp.go @@ -44,10 +44,12 @@ func cpTestRepo(text string) string { var _ = Describe("ORAS beginners:", func() { When("running cp command", func() { It("should show help doc with feature flags", func() { - out := ORAS("cp", "--help").MatchKeyWords("Copy", ExampleDesc).Exec() + out := ORAS("cp", "--help").MatchKeyWords("Copy", ExampleDesc).Exec().Out Expect(out).Should(gbytes.Say("--from-distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) + Expect(out).Should(gbytes.Say("--from-oci-layout-path string\\s+%s", regexp.QuoteMeta(feature.Experimental.Mark))) Expect(out).Should(gbytes.Say("-r, --recursive\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) Expect(out).Should(gbytes.Say("--to-distribution-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) + Expect(out).Should(gbytes.Say("--to-oci-layout-path string\\s+%s", regexp.QuoteMeta(feature.Experimental.Mark))) }) It("should not show --verbose in help doc", func() { diff --git a/test/e2e/suite/command/pull.go b/test/e2e/suite/command/pull.go index f31436e7a..8a22177ea 100644 --- a/test/e2e/suite/command/pull.go +++ b/test/e2e/suite/command/pull.go @@ -41,6 +41,7 @@ var _ = Describe("ORAS beginners:", func() { It("should show help description with feature flags", func() { out := ORAS("pull", "--help").MatchKeyWords(ExampleDesc).Exec().Out gomega.Expect(out).Should(gbytes.Say("--include-subject\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) + gomega.Expect(out).Should(gbytes.Say("--oci-layout-path string\\s+%s", regexp.QuoteMeta(feature.Experimental.Mark))) }) It("should not show --verbose in help doc", func() { diff --git a/test/e2e/suite/command/push.go b/test/e2e/suite/command/push.go index e489283f9..b322a2055 100644 --- a/test/e2e/suite/command/push.go +++ b/test/e2e/suite/command/push.go @@ -39,6 +39,7 @@ var _ = Describe("ORAS beginners:", func() { It("should show help description with feature flags", func() { out := ORAS("push", "--help").MatchKeyWords(ExampleDesc).Exec().Out gomega.Expect(out).Should(gbytes.Say("--image-spec string\\s+%s", regexp.QuoteMeta(feature.Preview.Mark))) + gomega.Expect(out).Should(gbytes.Say("--oci-layout-path string\\s+%s", regexp.QuoteMeta(feature.Experimental.Mark))) }) It("should not show --verbose in help doc", func() { From 05e97edb35811938d392e32153ce5b13618c3f24 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang <103478229+wangxiaoxuan273@users.noreply.github.com> Date: Wed, 22 Jan 2025 20:36:09 +0800 Subject: [PATCH 4/4] refactor: apply metadata render interface to oras discover command (#1605) Signed-off-by: Xiaoxuan Wang Co-authored-by: Xiaoxuan Wang Co-authored-by: Terry Howe --- cmd/oras/internal/display/metadata/interface.go | 4 ++-- cmd/oras/internal/display/metadata/json/discover.go | 4 ++-- cmd/oras/internal/display/metadata/table/discover.go | 4 ++-- cmd/oras/internal/display/metadata/template/discover.go | 4 ++-- cmd/oras/internal/display/metadata/tree/discover.go | 4 ++-- cmd/oras/root/discover.go | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/oras/internal/display/metadata/interface.go b/cmd/oras/internal/display/metadata/interface.go index cc8d504c0..8815a0500 100644 --- a/cmd/oras/internal/display/metadata/interface.go +++ b/cmd/oras/internal/display/metadata/interface.go @@ -42,13 +42,13 @@ type AttachHandler interface { // DiscoverHandler handles metadata output for discover events. type DiscoverHandler interface { + Renderer + // MultiLevelSupported returns true if the handler supports multi-level // discovery. MultiLevelSupported() bool // OnDiscovered is called after a referrer is discovered. OnDiscovered(referrer, subject ocispec.Descriptor) error - // OnCompleted is called when referrer discovery is completed. - OnCompleted() error } // ManifestFetchHandler handles metadata output for manifest fetch events. diff --git a/cmd/oras/internal/display/metadata/json/discover.go b/cmd/oras/internal/display/metadata/json/discover.go index 8d9eea230..fa1c24e0e 100644 --- a/cmd/oras/internal/display/metadata/json/discover.go +++ b/cmd/oras/internal/display/metadata/json/discover.go @@ -57,7 +57,7 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err return nil } -// OnCompleted implements metadata.DiscoverHandler. -func (h *discoverHandler) OnCompleted() error { +// Render implements metadata.DiscoverHandler. +func (h *discoverHandler) Render() error { return output.PrintPrettyJSON(h.out, model.NewDiscover(h.path, h.referrers)) } diff --git a/cmd/oras/internal/display/metadata/table/discover.go b/cmd/oras/internal/display/metadata/table/discover.go index 6acd0e6e8..d76967fd0 100644 --- a/cmd/oras/internal/display/metadata/table/discover.go +++ b/cmd/oras/internal/display/metadata/table/discover.go @@ -59,8 +59,8 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err return nil } -// OnCompleted implements metadata.DiscoverHandler. -func (h *discoverHandler) OnCompleted() error { +// Render implements metadata.DiscoverHandler. +func (h *discoverHandler) Render() error { if n := len(h.referrers); n > 1 { fmt.Fprintln(h.out, "Discovered", n, "artifacts referencing", h.rawReference) } else { diff --git a/cmd/oras/internal/display/metadata/template/discover.go b/cmd/oras/internal/display/metadata/template/discover.go index 1495a4b03..8ce7581ae 100644 --- a/cmd/oras/internal/display/metadata/template/discover.go +++ b/cmd/oras/internal/display/metadata/template/discover.go @@ -59,7 +59,7 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err return nil } -// OnCompleted implements metadata.DiscoverHandler. -func (h *discoverHandler) OnCompleted() error { +// Render implements metadata.DiscoverHandler. +func (h *discoverHandler) Render() error { return output.ParseAndWrite(h.out, model.NewDiscover(h.path, h.referrers), h.template) } diff --git a/cmd/oras/internal/display/metadata/tree/discover.go b/cmd/oras/internal/display/metadata/tree/discover.go index 496de1279..0738a6597 100644 --- a/cmd/oras/internal/display/metadata/tree/discover.go +++ b/cmd/oras/internal/display/metadata/tree/discover.go @@ -78,7 +78,7 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err return nil } -// OnCompleted implements metadata.DiscoverHandler. -func (h *discoverHandler) OnCompleted() error { +// Render implements metadata.DiscoverHandler. +func (h *discoverHandler) Render() error { return tree.NewPrinter(h.out).Print(h.root) } diff --git a/cmd/oras/root/discover.go b/cmd/oras/root/discover.go index e65817b57..0ede79232 100644 --- a/cmd/oras/root/discover.go +++ b/cmd/oras/root/discover.go @@ -151,7 +151,7 @@ func runDiscover(cmd *cobra.Command, opts *discoverOptions) error { } } } - return handler.OnCompleted() + return handler.Render() } func fetchAllReferrers(ctx context.Context, repo oras.ReadOnlyGraphTarget, desc ocispec.Descriptor, artifactType string, handler metadata.DiscoverHandler) error {