From a8a8595a62ef26976a4963c779bdb2caae984ece Mon Sep 17 00:00:00 2001 From: David Gannon <19214156+dgannon991@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:19:08 +0000 Subject: [PATCH] Pass in context to cnab-go Run() Signed-off-by: David Gannon <19214156+dgannon991@users.noreply.github.com> --- go.mod | 2 +- pkg/cnab/provider/action.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 5620c7cd3..60711dbe6 100644 --- a/go.mod +++ b/go.mod @@ -252,4 +252,4 @@ require ( sigs.k8s.io/yaml v1.3.0 // indirect ) -//replace get.porter.sh/magefiles v0.3.3 => ../magefiles +replace github.com/cnabio/cnab-go v0.25.1 => ../cnabio-cnab-go diff --git a/pkg/cnab/provider/action.go b/pkg/cnab/provider/action.go index 5124ab065..3aeb43923 100644 --- a/pkg/cnab/provider/action.go +++ b/pkg/cnab/provider/action.go @@ -61,6 +61,14 @@ func (r *Runtime) ApplyConfig(ctx context.Context, args ActionArguments) cnabact r.AddFiles(ctx, args), r.AddEnvironment(args), r.AddRelocation(args), + r.SetContext(ctx), + } +} + +func (r *Runtime) SetContext(ctx context.Context) cnabaction.OperationConfigFunc { + return func(op *driver.Operation) error { + op.CTX = ctx + return nil } } @@ -202,6 +210,11 @@ func (r *Runtime) Execute(ctx context.Context, args ActionArguments) error { tracing.ObjectAttribute("cnab-credentials", cnabCreds)) opResult, result, err := a.Run(cnabClaim, cnabCreds, r.ApplyConfig(ctx, args)...) + // if the error was due to context, just stop and return the context error + if ctx.Err() != nil { + return ctx.Err() + } + if currentRun.ShouldRecord() { if err != nil { err = r.appendFailedResult(ctx, err, currentRun)