Skip to content

Commit

Permalink
manifest ref fetch handler
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
  • Loading branch information
Xiaoxuan Wang committed Oct 9, 2024
1 parent 16cf5ab commit c56fdec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
14 changes: 2 additions & 12 deletions cmd/oras/internal/display/status/discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 8 additions & 4 deletions cmd/oras/internal/display/status/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/status/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/oras/root/manifest/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c56fdec

Please sign in to comment.