From 618e37794e504f70950e7a67412f3553f258a5e2 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 20 Feb 2025 18:42:14 +0100 Subject: [PATCH] libartifact: create FilterBlobOptions The main point of this is so that I can share the same lookup logic between Extract() and then the new blob path API I add next. Signed-off-by: Paul Holzinger --- pkg/domain/infra/abi/artifact.go | 6 ++++-- pkg/libartifact/store/store.go | 6 +++--- pkg/libartifact/types/config.go | 13 ++++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/domain/infra/abi/artifact.go b/pkg/domain/infra/abi/artifact.go index d66ec44561..fa70c28aac 100644 --- a/pkg/domain/infra/abi/artifact.go +++ b/pkg/domain/infra/abi/artifact.go @@ -215,8 +215,10 @@ func (ir *ImageEngine) ArtifactExtract(ctx context.Context, name string, target return err } extractOpt := &types.ExtractOptions{ - Digest: opts.Digest, - Title: opts.Title, + FilterBlobOptions: types.FilterBlobOptions{ + Digest: opts.Digest, + Title: opts.Title, + }, } return artStore.Extract(ctx, name, target, extractOpt) diff --git a/pkg/libartifact/store/store.go b/pkg/libartifact/store/store.go index 2224ce4066..eafeb87a67 100644 --- a/pkg/libartifact/store/store.go +++ b/pkg/libartifact/store/store.go @@ -364,7 +364,7 @@ func (as ArtifactStore) Extract(ctx context.Context, nameOrDigest string, target if len(options.Digest) == 0 && len(options.Title) == 0 { return fmt.Errorf("the artifact consists of several blobs and the target %q is not a directory and neither digest or title was specified to only copy a single blob", target) } - digest, err = findDigest(arty, options) + digest, err = findDigest(arty, &options.FilterBlobOptions) if err != nil { return err } @@ -376,7 +376,7 @@ func (as ArtifactStore) Extract(ctx context.Context, nameOrDigest string, target } if len(options.Digest) > 0 || len(options.Title) > 0 { - digest, err := findDigest(arty, options) + digest, err := findDigest(arty, &options.FilterBlobOptions) if err != nil { return err } @@ -427,7 +427,7 @@ func generateArtifactBlobName(title string, digest digest.Digest) (string, error return filename, nil } -func findDigest(arty *libartifact.Artifact, options *libartTypes.ExtractOptions) (digest.Digest, error) { +func findDigest(arty *libartifact.Artifact, options *libartTypes.FilterBlobOptions) (digest.Digest, error) { var digest digest.Digest for _, l := range arty.Manifest.Layers { if options.Digest == l.Digest.String() { diff --git a/pkg/libartifact/types/config.go b/pkg/libartifact/types/config.go index ab0a8eb3d6..2fb4fa79ab 100644 --- a/pkg/libartifact/types/config.go +++ b/pkg/libartifact/types/config.go @@ -12,9 +12,16 @@ type AddOptions struct { Append bool `json:",omitempty"` } -type ExtractOptions struct { - // Title annotation value to extract only a single blob matching that name. Optional. +// FilterBlobOptions options used to filter for a single blob in an artifact +type FilterBlobOptions struct { + // Title annotation value to extract only a single blob matching that name. + // Optional. Conflicts with Digest. Title string - // Digest of the blob to extract. Optional. + // Digest of the blob to extract. + // Optional. Conflicts with Title. Digest string } + +type ExtractOptions struct { + FilterBlobOptions +}