Skip to content

Commit 617a903

Browse files
authored
feat(cli): retrieve worklowRun by attestation digest (#425)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent c4a6e12 commit 617a903

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

app/cli/cmd/workflow_workflow_run_describe.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package cmd
1717

1818
import (
19+
"context"
1920
"errors"
2021
"fmt"
2122
"os"
@@ -32,7 +33,7 @@ const formatStatement = "statement"
3233
const formatAttestation = "attestation"
3334

3435
func newWorkflowWorkflowRunDescribeCmd() *cobra.Command {
35-
var runID, publicKey string
36+
var runID, attestationDigest, publicKey string
3637
var verifyAttestation bool
3738
// TODO: Replace by retrieving key from rekor
3839
const signingKeyEnvVarName = "CHAINLOOP_SIGNING_PUBLIC_KEY"
@@ -44,10 +45,15 @@ func newWorkflowWorkflowRunDescribeCmd() *cobra.Command {
4445
if verifyAttestation && publicKey == "" {
4546
return errors.New("a public key needs to be provided for verification")
4647
}
48+
49+
if runID == "" && attestationDigest == "" {
50+
return errors.New("either a run ID or the attestation digest needs to be provided")
51+
}
52+
4753
return nil
4854
},
4955
RunE: func(cmd *cobra.Command, args []string) error {
50-
res, err := action.NewWorkflowRunDescribe(actionOpts).Run(runID, verifyAttestation, publicKey)
56+
res, err := action.NewWorkflowRunDescribe(actionOpts).Run(context.Background(), runID, attestationDigest, verifyAttestation, publicKey)
5157
if err != nil {
5258
return err
5359
}
@@ -57,8 +63,7 @@ func newWorkflowWorkflowRunDescribeCmd() *cobra.Command {
5763
}
5864

5965
cmd.Flags().StringVar(&runID, "id", "", "workflow Run ID")
60-
err := cmd.MarkFlagRequired("id")
61-
cobra.CheckErr(err)
66+
cmd.Flags().StringVar(&attestationDigest, "digest", "", "content digest of the attestation")
6267

6368
cmd.Flags().BoolVar(&verifyAttestation, "verify", false, "verify the attestation")
6469
cmd.Flags().StringVar(&publicKey, "key", "", fmt.Sprintf("public key used to verify the attestation. Note: You can also use env variable %s", signingKeyEnvVarName))

app/cli/internal/action/workflow_run_describe.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ func NewWorkflowRunDescribe(cfg *ActionsOpts) *WorkflowRunDescribe {
8080
return &WorkflowRunDescribe{cfg}
8181
}
8282

83-
func (action *WorkflowRunDescribe) Run(runID string, verify bool, publicKey string) (*WorkflowRunItemFull, error) {
83+
func (action *WorkflowRunDescribe) Run(ctx context.Context, runID string, digest string, verify bool, publicKey string) (*WorkflowRunItemFull, error) {
8484
client := pb.NewWorkflowRunServiceClient(action.cfg.CPConnection)
85-
resp, err := client.View(context.Background(), &pb.WorkflowRunServiceViewRequest{
86-
Ref: &pb.WorkflowRunServiceViewRequest_Id{Id: runID},
87-
})
85+
86+
req := &pb.WorkflowRunServiceViewRequest{}
87+
if digest != "" {
88+
req.Ref = &pb.WorkflowRunServiceViewRequest_Digest{Digest: digest}
89+
} else if runID != "" {
90+
req.Ref = &pb.WorkflowRunServiceViewRequest_Id{Id: runID}
91+
}
92+
93+
resp, err := client.View(ctx, req)
8894
if err != nil {
8995
return nil, err
9096
}
@@ -113,7 +119,7 @@ func (action *WorkflowRunDescribe) Run(runID string, verify bool, publicKey stri
113119
}
114120

115121
if verify {
116-
if err := verifyEnvelope(context.Background(), envelope, publicKey); err != nil {
122+
if err := verifyEnvelope(ctx, envelope, publicKey); err != nil {
117123
action.cfg.Logger.Debug().Err(err).Msg("verifying the envelope")
118124
return nil, errors.New("invalid signature, did you provide the right key?")
119125
}

0 commit comments

Comments
 (0)