From c56fdecdcaf4c48703274fe2d374cfec6f45fd6d Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Wed, 9 Oct 2024 16:02:28 +0800 Subject: [PATCH] manifest ref fetch handler Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/status/discard.go | 14 ++------------ cmd/oras/internal/display/status/interface.go | 12 ++++++++---- cmd/oras/internal/display/status/text.go | 4 ++-- cmd/oras/root/manifest/index/create.go | 4 ++-- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/cmd/oras/internal/display/status/discard.go b/cmd/oras/internal/display/status/discard.go index 83694398c..917572885 100644 --- a/cmd/oras/internal/display/status/discard.go +++ b/cmd/oras/internal/display/status/discard.go @@ -90,22 +90,12 @@ func (DiscardHandler) OnNodeSkipped(desc ocispec.Descriptor) error { return nil } -// OnSourceManifestFetching implements ManifestIndexCreateHandler. -func (DiscardHandler) OnSourceManifestFetching(string) error { - return nil -} - -// OnSourceManifestFetched implements ManifestIndexCreateHandler. -func (DiscardHandler) OnSourceManifestFetched(string) error { - return nil -} - -// OnManifestFetching implements ManifestIndexUpdateHandler. +// OnSourceManifestFetching implements ManifestReferenceFetchHandler. func (DiscardHandler) OnManifestFetching(string) error { return nil } -// OnManifestFetched implements ManifestIndexUpdateHandler. +// OnSourceManifestFetched implements ManifestReferenceFetchHandler. func (DiscardHandler) OnManifestFetched(string, digest.Digest) error { return nil } diff --git a/cmd/oras/internal/display/status/interface.go b/cmd/oras/internal/display/status/interface.go index 70df6e385..8bafeb7c5 100644 --- a/cmd/oras/internal/display/status/interface.go +++ b/cmd/oras/internal/display/status/interface.go @@ -64,16 +64,20 @@ type CopyHandler interface { OnMounted(ctx context.Context, desc ocispec.Descriptor) error } +// ManifestReferenceFetchHandler handles status output for manifest reference fetch events. +type ManifestReferenceFetchHandler interface { + OnManifestFetching(manifestRef string) error + OnManifestFetched(manifestRef string, digest digest.Digest) error +} + // ManifestIndexCreateHandler handles status output for manifest index create command. type ManifestIndexCreateHandler interface { - OnSourceManifestFetching(source string) error - OnSourceManifestFetched(source string) error + ManifestReferenceFetchHandler } // ManifestIndexUpdateHandler handles status output for manifest index update command. type ManifestIndexUpdateHandler interface { + ManifestReferenceFetchHandler OnIndexFetching(indexRef string) error OnIndexFetched(indexRef string, digest digest.Digest) error - OnManifestFetching(manifestRef string) error - OnManifestFetched(manifestRef string, digest digest.Digest) error } diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index 150caee6f..2c5323fe9 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -188,12 +188,12 @@ type TextManifestIndexCreateHandler struct { } // OnSourceManifestFetching implements ManifestIndexCreateHandler. -func (mich TextManifestIndexCreateHandler) OnSourceManifestFetching(source string) error { +func (mich TextManifestIndexCreateHandler) OnManifestFetching(source string) error { return mich.printer.Println(IndexPromptFetching, source) } // OnSourceManifestFetched implements ManifestIndexCreateHandler. -func (mich TextManifestIndexCreateHandler) OnSourceManifestFetched(source string) error { +func (mich TextManifestIndexCreateHandler) OnManifestFetched(source string, _ digest.Digest) error { return mich.printer.Println(IndexPromptFetched, source) } diff --git a/cmd/oras/root/manifest/index/create.go b/cmd/oras/root/manifest/index/create.go index 435b0c391..1e1aba9f4 100644 --- a/cmd/oras/root/manifest/index/create.go +++ b/cmd/oras/root/manifest/index/create.go @@ -149,7 +149,7 @@ func createIndex(cmd *cobra.Command, opts createOptions) error { func fetchSourceManifests(ctx context.Context, displayStatus status.ManifestIndexCreateHandler, target oras.ReadOnlyTarget, sources []string) ([]ocispec.Descriptor, error) { resolved := []ocispec.Descriptor{} for _, source := range sources { - if err := displayStatus.OnSourceManifestFetching(source); err != nil { + if err := displayStatus.OnManifestFetching(source); err != nil { return nil, err } desc, content, err := oras.FetchBytes(ctx, target, source, oras.DefaultFetchBytesOptions) @@ -159,7 +159,7 @@ func fetchSourceManifests(ctx context.Context, displayStatus status.ManifestInde if !descriptor.IsManifest(desc) { return nil, fmt.Errorf("%s is not a manifest", source) } - if err := displayStatus.OnSourceManifestFetched(source); err != nil { + if err := displayStatus.OnManifestFetched(source, desc.Digest); err != nil { return nil, err } desc = descriptor.Plain(desc)