Skip to content

Commit

Permalink
make changes to signing.go to support v1beta1 storage backwards compa…
Browse files Browse the repository at this point in the history
…tibility
  • Loading branch information
aaron-prindle committed Jan 10, 2024
1 parent aee1656 commit 3ed1545
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions pkg/chains/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/tektoncd/chains/pkg/chains/signing/x509"
"github.com/tektoncd/chains/pkg/chains/storage"
"github.com/tektoncd/chains/pkg/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
versioned "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
"k8s.io/apimachinery/pkg/util/sets"
"knative.dev/pkg/logging"
Expand Down Expand Up @@ -134,10 +135,10 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject)

// Extract all the "things" to be signed.
// We might have a few of each type (several binaries, or images)
objects := signableType.ExtractObjects(ctx, tektonObj)
objs := signableType.ExtractObjects(ctx, tektonObj)

// Go through each object one at a time.
for _, obj := range objects {
for _, obj := range objs {

payload, err := payloader.CreatePayload(ctx, obj)
if err != nil {
Expand Down Expand Up @@ -178,6 +179,33 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject)

// Now store those!
for _, backend := range sets.List[string](signableType.StorageBackend(cfg)) {
// TODO(https://github.com/tektoncd/chains/issues/1026) add support for passing v1 object (vs converted v1beta1) for v2alpha3+

// convert types to v1beta1 as needed for backwards compatibility
var storageObj objects.TektonObject
switch v := obj.(type) {
case *objects.TaskRunObjectV1:
trV1Beta1 := &v1beta1.TaskRun{} //nolint:staticcheck
if err := trV1Beta1.ConvertFrom(ctx, v); err != nil {
return fmt.Errorf("error converting Tekton TaskRun from version v1 to v1beta1: %s", err)
}
storageObj = objects.NewTaskRunObjectV1Beta1(trV1Beta1)
case *objects.PipelineRunObjectV1:
prV1Beta1 := &v1beta1.PipelineRun{} //nolint:staticcheck
if err := prV1Beta1.ConvertFrom(ctx, v); err != nil {
return fmt.Errorf("error converting Tekton PipelineRun from version v1 to v1beta1: %s", err)
}
proV1Beta1 := objects.NewPipelineRunObjectV1Beta1(prV1Beta1)
trs := pro.GetTaskRuns()
for _, tr := range trs {
trV1Beta1 := &v1beta1.TaskRun{} //nolint:staticcheck
if err := trV1Beta1.ConvertFrom(ctx, tr); err != nil {
return fmt.Errorf("error converting Tekton TaskRun from version v1 to v1beta1: %s", err)
}
proV1Beta1.AppendTaskRun(trV1Beta1)
}
storageObj = proV1Beta1

b := o.Backends[backend]
storageOpts := config.StorageOpts{
ShortKey: signableType.ShortKey(obj),
Expand All @@ -186,7 +214,7 @@ func (o *ObjectSigner) Sign(ctx context.Context, tektonObj objects.TektonObject)
Chain: signer.Chain(),
PayloadFormat: payloadFormat,
}
if err := b.StorePayload(ctx, tektonObj, rawPayload, string(signature), storageOpts); err != nil {
if err := b.StorePayload(ctx, storageObj, rawPayload, string(signature), storageOpts); err != nil {
logger.Error(err)
merr = multierror.Append(merr, err)
}
Expand Down

0 comments on commit 3ed1545

Please sign in to comment.