Add libimage/manifests.PushOptions.SourceFilter

Add a SourceFilter hook that allows a caller to intercept and filter
attempts to read source blobs when pushing a manifest list.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai 2022-02-03 17:47:56 -05:00
parent d9489c8ea4
commit 630d2df7f2
2 changed files with 17 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/containers/common/libimage/manifests"
"github.com/containers/common/pkg/config" "github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/retry" "github.com/containers/common/pkg/retry"
"github.com/containers/image/v5/copy" "github.com/containers/image/v5/copy"
@ -26,8 +27,10 @@ const (
) )
// LookupReferenceFunc return an image reference based on the specified one. // LookupReferenceFunc return an image reference based on the specified one.
// This can be used to pass custom blob caches to the copy operation. // The returned reference can return custom ImageSource or ImageDestination
type LookupReferenceFunc func(ref types.ImageReference) (types.ImageReference, error) // objects which intercept or filter blobs, manifests, and signatures as
// they are read and written.
type LookupReferenceFunc = manifests.LookupReferenceFunc
// CopyOptions allow for customizing image-copy operations. // CopyOptions allow for customizing image-copy operations.
type CopyOptions struct { type CopyOptions struct {

View File

@ -27,6 +27,12 @@ import (
const instancesData = "instances.json" const instancesData = "instances.json"
// LookupReferenceFunc return an image reference based on the specified one.
// The returned reference can return custom ImageSource or ImageDestination
// objects which intercept or filter blobs, manifests, and signatures as
// they are read and written.
type LookupReferenceFunc func(ref types.ImageReference) (types.ImageReference, error)
// ErrListImageUnknown is returned when we attempt to create an image reference // ErrListImageUnknown is returned when we attempt to create an image reference
// for a List that has not yet been saved to an image. // for a List that has not yet been saved to an image.
var ErrListImageUnknown = stderrors.New("unable to determine which image holds the manifest list") var ErrListImageUnknown = stderrors.New("unable to determine which image holds the manifest list")
@ -57,6 +63,7 @@ type PushOptions struct {
SignBy string // fingerprint of GPG key to use to sign images SignBy string // fingerprint of GPG key to use to sign images
RemoveSignatures bool // true to discard signatures in images RemoveSignatures bool // true to discard signatures in images
ManifestType string // the format to use when saving the list - possible options are oci, v2s1, and v2s2 ManifestType string // the format to use when saving the list - possible options are oci, v2s1, and v2s2
SourceFilter LookupReferenceFunc // filter the list source
} }
// Create creates a new list containing information about the specified image, // Create creates a new list containing information about the specified image,
@ -221,6 +228,11 @@ func (l *list) Push(ctx context.Context, dest types.ImageReference, options Push
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
if options.SourceFilter != nil {
if src, err = options.SourceFilter(src); err != nil {
return nil, "", err
}
}
copyOptions := &cp.Options{ copyOptions := &cp.Options{
ImageListSelection: options.ImageListSelection, ImageListSelection: options.ImageListSelection,
Instances: options.Instances, Instances: options.Instances,