Skip to content

Commit 5fbff91

Browse files
authored
refactor(cli): Use attestation state to pass workflow-name (#766)
Signed-off-by: Javier Rodriguez <[email protected]>
1 parent e0d3c80 commit 5fbff91

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

app/cli/cmd/attestation_init.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ package cmd
1818
import (
1919
"errors"
2020
"fmt"
21-
22-
"github.com/spf13/cobra"
21+
"os"
2322

2423
"github.com/chainloop-dev/chainloop/app/cli/internal/action"
24+
"github.com/spf13/cobra"
2525
)
2626

27+
const workflowNameEnvVarName = "CHAINLOOP_WORKFLOW_NAME"
28+
2729
func newAttestationInitCmd() *cobra.Command {
2830
var (
2931
force bool
3032
contractRevision int
3133
attestationDryRun bool
34+
workflowName string
3235
)
3336

3437
cmd := &cobra.Command{
@@ -50,7 +53,7 @@ func newAttestationInitCmd() *cobra.Command {
5053
}
5154

5255
// Initialize it
53-
attestationID, err := a.Run(cmd.Context(), contractRevision)
56+
attestationID, err := a.Run(cmd.Context(), contractRevision, workflowName)
5457
if err != nil {
5558
if errors.Is(err, action.ErrAttestationAlreadyExist) {
5659
return err
@@ -82,6 +85,10 @@ func newAttestationInitCmd() *cobra.Command {
8285
cmd.Flags().BoolVarP(&force, "replace", "f", false, "replace any existing in-progress attestation")
8386
cmd.Flags().BoolVar(&attestationDryRun, "dry-run", false, "do not record attestation in the control plane, useful for development")
8487
cmd.Flags().IntVar(&contractRevision, "contract-revision", 0, "revision of the contract to retrieve, \"latest\" by default")
88+
cmd.Flags().StringVar(&workflowName, "workflow-name", "", "name of the workflow to run the attestation. This is ignored when authentication is based on Robot Account")
89+
if workflowName == "" {
90+
workflowName = os.Getenv(workflowNameEnvVarName)
91+
}
8592

8693
return cmd
8794
}

app/cli/internal/action/attestation_init.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func NewAttestationInit(cfg *AttestationInitOpts) (*AttestationInit, error) {
6767
}
6868

6969
// returns the attestation ID
70-
func (action *AttestationInit) Run(ctx context.Context, contractRevision int) (string, error) {
70+
func (action *AttestationInit) Run(ctx context.Context, contractRevision int, workflowName string) (string, error) {
7171
if action.dryRun && action.UseAttestationRemoteState {
7272
return "", errors.New("remote state is not compatible with dry-run mode")
7373
}
@@ -83,7 +83,10 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int) (s
8383
action.Logger.Debug().Msg("Retrieving attestation definition")
8484
client := pb.NewAttestationServiceClient(action.ActionsOpts.CPConnection)
8585
// get information of the workflow
86-
contractResp, err := client.GetContract(ctx, &pb.AttestationServiceGetContractRequest{ContractRevision: int32(contractRevision)})
86+
contractResp, err := client.GetContract(ctx, &pb.AttestationServiceGetContractRequest{
87+
ContractRevision: int32(contractRevision),
88+
WorkflowName: workflowName,
89+
})
8790
if err != nil {
8891
return "", err
8992
}

0 commit comments

Comments
 (0)