From baf34034395162a05544f1bc847f1e9d8b1babcc Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 22 Mar 2019 15:43:56 -0400 Subject: [PATCH] Extend Applier's Apply() method with an optional options parameter Extend the Applier interface's Apply method with an optional options parameter. For the container image encryption we intend to use the options parameter to pass image decryption parameters ('dcparameters'), which are primarily (privatte) keys, in form of a JSON document under the map key '_dcparameters', and pass them to the Applier's Apply() method. This helps us to access decryption keys and start the pipeline with the layer decryption before the layer data are unzipped and untarred. Signed-off-by: Stefan Berger Signed-off-by: Harshal Patil --- diff.go | 10 ++++++++-- diff/apply/apply.go | 2 +- diff/diff.go | 9 ++++++++- diff/lcow/lcow.go | 2 +- diff/windows/windows.go | 2 +- services/diff/local.go | 4 +++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/diff.go b/diff.go index 4d890ce2b..182362941 100644 --- a/diff.go +++ b/diff.go @@ -45,9 +45,15 @@ type diffRemote struct { client diffapi.DiffClient } -func (r *diffRemote) Apply(ctx context.Context, diff ocispec.Descriptor, mounts []mount.Mount) (ocispec.Descriptor, error) { +func (r *diffRemote) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (ocispec.Descriptor, error) { + var config diff.ApplyConfig + for _, opt := range opts { + if err := opt(&config); err != nil { + return ocispec.Descriptor{}, err + } + } req := &diffapi.ApplyRequest{ - Diff: fromDescriptor(diff), + Diff: fromDescriptor(desc), Mounts: fromMounts(mounts), } resp, err := r.client.Apply(ctx, req) diff --git a/diff/apply/apply.go b/diff/apply/apply.go index d5b4ff45d..e4251026c 100644 --- a/diff/apply/apply.go +++ b/diff/apply/apply.go @@ -53,7 +53,7 @@ var emptyDesc = ocispec.Descriptor{} // Apply applies the content associated with the provided digests onto the // provided mounts. Archive content will be extracted and decompressed if // necessary. -func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) { +func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) { t1 := time.Now() defer func() { if err == nil { diff --git a/diff/diff.go b/diff/diff.go index 2b6f01c74..a62a4671a 100644 --- a/diff/diff.go +++ b/diff/diff.go @@ -51,6 +51,13 @@ type Comparer interface { Compare(ctx context.Context, lower, upper []mount.Mount, opts ...Opt) (ocispec.Descriptor, error) } +// ApplyConfig is used to hold parameters needed for a apply operation +type ApplyConfig struct { +} + +// ApplyOpt is used to configure an Apply operation +type ApplyOpt func(*ApplyConfig) error + // Applier allows applying diffs between mounts type Applier interface { // Apply applies the content referred to by the given descriptor to @@ -58,7 +65,7 @@ type Applier interface { // implementation and content descriptor. For example, in the common // case the descriptor is a file system difference in tar format, // that tar would be applied on top of the mounts. - Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount) (ocispec.Descriptor, error) + Apply(ctx context.Context, desc ocispec.Descriptor, mount []mount.Mount, opts ...ApplyOpt) (ocispec.Descriptor, error) } // WithMediaType sets the media type to use for creating the diff, without diff --git a/diff/lcow/lcow.go b/diff/lcow/lcow.go index 6ac42ed6b..328058edf 100644 --- a/diff/lcow/lcow.go +++ b/diff/lcow/lcow.go @@ -95,7 +95,7 @@ func NewWindowsLcowDiff(store content.Store) (CompareApplier, error) { // Apply applies the content associated with the provided digests onto the // provided mounts. Archive content will be extracted and decompressed if // necessary. -func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) { +func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) { t1 := time.Now() defer func() { if err == nil { diff --git a/diff/windows/windows.go b/diff/windows/windows.go index d205ae19a..bf2887ad0 100644 --- a/diff/windows/windows.go +++ b/diff/windows/windows.go @@ -87,7 +87,7 @@ func NewWindowsDiff(store content.Store) (CompareApplier, error) { // Apply applies the content associated with the provided digests onto the // provided mounts. Archive content will be extracted and decompressed if // necessary. -func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount) (d ocispec.Descriptor, err error) { +func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (d ocispec.Descriptor, err error) { t1 := time.Now() defer func() { if err == nil { diff --git a/services/diff/local.go b/services/diff/local.go index 7cf6c768e..f60e1c658 100644 --- a/services/diff/local.go +++ b/services/diff/local.go @@ -99,8 +99,10 @@ func (l *local) Apply(ctx context.Context, er *diffapi.ApplyRequest, _ ...grpc.C mounts = toMounts(er.Mounts) ) + var opts []diff.ApplyOpt + for _, differ := range l.differs { - ocidesc, err = differ.Apply(ctx, desc, mounts) + ocidesc, err = differ.Apply(ctx, desc, mounts, opts...) if !errdefs.IsNotImplemented(err) { break }