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 <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2025-02-20 18:42:14 +01:00
parent 07c1f0b996
commit 618e37794e
3 changed files with 17 additions and 8 deletions

View File

@ -215,8 +215,10 @@ func (ir *ImageEngine) ArtifactExtract(ctx context.Context, name string, target
return err
}
extractOpt := &types.ExtractOptions{
FilterBlobOptions: types.FilterBlobOptions{
Digest: opts.Digest,
Title: opts.Title,
},
}
return artStore.Extract(ctx, name, target, extractOpt)

View File

@ -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() {

View File

@ -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
}