Skip to content

Commit 4978e66

Browse files
authored
feat: require project name on workflow management (#1378)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 382fee2 commit 4978e66

File tree

47 files changed

+1029
-704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1029
-704
lines changed

app/cli/cmd/attestation_init.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func newAttestationInitCmd() *cobra.Command {
2929
contractRevision int
3030
attestationDryRun bool
3131
workflowName string
32+
projectName string
3233
)
3334

3435
cmd := &cobra.Command{
@@ -37,14 +38,14 @@ func newAttestationInitCmd() *cobra.Command {
3738
Annotations: map[string]string{
3839
useAPIToken: "true",
3940
},
40-
PreRunE: func(cmd *cobra.Command, args []string) error {
41+
PreRunE: func(_ *cobra.Command, _ []string) error {
4142
if workflowName == "" {
42-
return errors.New("workflow name is required, set it via --name flag")
43+
return errors.New("workflow name is required, set it via --workflow flag")
4344
}
4445

4546
return nil
4647
},
47-
RunE: func(cmd *cobra.Command, args []string) error {
48+
RunE: func(cmd *cobra.Command, _ []string) error {
4849
a, err := action.NewAttestationInit(
4950
&action.AttestationInitOpts{
5051
ActionsOpts: actionOpts,
@@ -58,7 +59,7 @@ func newAttestationInitCmd() *cobra.Command {
5859
}
5960

6061
// Initialize it
61-
attestationID, err := a.Run(cmd.Context(), contractRevision, workflowName)
62+
attestationID, err := a.Run(cmd.Context(), contractRevision, projectName, workflowName)
6263
if err != nil {
6364
if errors.Is(err, action.ErrAttestationAlreadyExist) {
6465
return err
@@ -86,7 +87,11 @@ func newAttestationInitCmd() *cobra.Command {
8687
logger.Info().Msg("The attestation is being crafted in dry-run mode. It will not get stored once rendered")
8788
}
8889

89-
return encodeOutput(res, simpleStatusTable)
90+
if projectName == "" {
91+
logger.Warn().Msg("DEPRECATION WARNING: --project not set, this will be required in the near future")
92+
}
93+
94+
return encodeOutput(res, fullStatusTable)
9095
},
9196
}
9297

@@ -96,10 +101,10 @@ func newAttestationInitCmd() *cobra.Command {
96101
cmd.Flags().IntVar(&contractRevision, "contract-revision", 0, "revision of the contract to retrieve, \"latest\" by default")
97102
cmd.Flags().BoolVar(&useAttestationRemoteState, "remote-state", false, "Store the attestation state remotely")
98103

99-
// workflow-name has been replaced by --name flag
100-
cmd.Flags().StringVar(&workflowName, "workflow-name", "", "name of the workflow to run the attestation")
101-
cobra.CheckErr(cmd.Flags().MarkHidden("workflow-name"))
104+
// name has been replaced by --workflow flag
105+
cmd.Flags().StringVar(&workflowName, "workflow", "", "name of the workflow to run the attestation")
102106
cmd.Flags().StringVar(&workflowName, "name", "", "name of the workflow to run the attestation")
103-
107+
cobra.CheckErr(cmd.Flags().MarkDeprecated("name", "please use --workflow instead"))
108+
cmd.Flags().StringVar(&projectName, "project", "", "name of the project of this workflow")
104109
return cmd
105110
}

app/cli/cmd/attestation_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult, full b
8181
gt.AppendSeparator()
8282
meta := status.WorkflowMeta
8383
gt.AppendRow(table.Row{"Attestation ID", status.AttestationID})
84+
gt.AppendRow(table.Row{"Organization", meta.Organization})
8485
gt.AppendRow(table.Row{"Name", meta.Name})
85-
gt.AppendRow(table.Row{"Team", meta.Team})
8686
gt.AppendRow(table.Row{"Project", meta.Project})
8787
gt.AppendRow(table.Row{"Contract Revision", meta.ContractRevision})
8888
if status.RunnerContext.JobURL != "" {

app/cli/cmd/workflow_delete.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import (
2121
)
2222

2323
func newWorkflowDeleteCmd() *cobra.Command {
24-
var name string
24+
var name, projectName string
2525

2626
cmd := &cobra.Command{
2727
Use: "delete",
2828
Short: "Delete an existing workflow",
2929
RunE: func(cmd *cobra.Command, args []string) error {
30-
err := action.NewWorkflowDelete(actionOpts).Run(name)
30+
err := action.NewWorkflowDelete(actionOpts).Run(name, projectName)
3131
if err == nil {
32-
logger.Info().Msg("Workload deleted!")
32+
logger.Info().Msg("Workflow deleted!")
3333
}
3434
return err
3535
},
@@ -38,5 +38,8 @@ func newWorkflowDeleteCmd() *cobra.Command {
3838
cmd.Flags().StringVar(&name, "name", "", "workflow name")
3939
cobra.CheckErr(cmd.MarkFlagRequired("name"))
4040

41+
cmd.Flags().StringVar(&projectName, "project", "", "project name")
42+
cobra.CheckErr(cmd.MarkFlagRequired("project"))
43+
4144
return cmd
4245
}

app/cli/cmd/workflow_describe.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import (
2121
)
2222

2323
func newWorkflowDescribeCmd() *cobra.Command {
24-
var workflowName string
24+
var workflowName, projectName string
2525

2626
cmd := &cobra.Command{
2727
Use: "describe",
2828
Short: "Describe an existing workflow",
2929
RunE: func(cmd *cobra.Command, args []string) error {
30-
wf, err := action.NewWorkflowDescribe(actionOpts).Run(cmd.Context(), workflowName)
30+
wf, err := action.NewWorkflowDescribe(actionOpts).Run(cmd.Context(), workflowName, projectName)
3131
if err != nil {
3232
return err
3333
}
@@ -39,5 +39,7 @@ func newWorkflowDescribeCmd() *cobra.Command {
3939
cmd.Flags().StringVar(&workflowName, "name", "", "workflow name")
4040
cobra.CheckErr(cmd.MarkFlagRequired("name"))
4141

42+
cmd.Flags().StringVar(&projectName, "project", "", "project name")
43+
cobra.CheckErr(cmd.MarkFlagRequired("project"))
4244
return cmd
4345
}

app/cli/cmd/workflow_update.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -34,9 +34,6 @@ func newWorkflowUpdateCmd() *cobra.Command {
3434
if cmd.Flags().Changed("team") {
3535
opts.Team = &team
3636
}
37-
if cmd.Flags().Changed("project") {
38-
opts.Project = &project
39-
}
4037
if cmd.Flags().Changed("public") {
4138
opts.Public = &public
4239
}
@@ -49,7 +46,7 @@ func newWorkflowUpdateCmd() *cobra.Command {
4946
opts.ContractName = &contractName
5047
}
5148

52-
res, err := action.NewWorkflowUpdate(actionOpts).Run(context.Background(), name, opts)
49+
res, err := action.NewWorkflowUpdate(actionOpts).Run(context.Background(), name, project, opts)
5350
if err != nil {
5451
return err
5552
}
@@ -61,10 +58,11 @@ func newWorkflowUpdateCmd() *cobra.Command {
6158

6259
cmd.Flags().StringVar(&name, "name", "", "workflow name")
6360
cobra.CheckErr(cmd.MarkFlagRequired("name"))
61+
cmd.Flags().StringVar(&project, "project", "", "project name")
62+
cobra.CheckErr(cmd.MarkFlagRequired("project"))
6463

6564
cmd.Flags().StringVar(&description, "description", "", "workflow description")
6665
cmd.Flags().StringVar(&team, "team", "", "team name")
67-
cmd.Flags().StringVar(&project, "project", "", "project name")
6866
cmd.Flags().BoolVar(&public, "public", false, "is the workflow public")
6967
cmd.Flags().StringVar(&contractName, "contract", "", "the name of an existing contract")
7068

app/cli/cmd/workflow_workflow_run_list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
3131
DefaultLimit: 20,
3232
}
3333

34-
var workflowName, status string
34+
var workflowName, projectName, status string
3535

3636
cmd := &cobra.Command{
3737
Use: "list",
@@ -48,6 +48,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
4848
res, err := action.NewWorkflowRunList(actionOpts).Run(
4949
&action.WorkflowRunListOpts{
5050
WorkflowName: workflowName,
51+
ProjectName: projectName,
5152
Pagination: &action.PaginationOpts{
5253
Limit: paginationOpts.Limit,
5354
NextCursor: paginationOpts.NextCursor,
@@ -79,6 +80,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
7980
}
8081

8182
cmd.Flags().StringVar(&workflowName, "workflow", "", "workflow name")
83+
cmd.Flags().StringVar(&projectName, "project", "", "project name")
8284
cmd.Flags().BoolVar(&full, "full", false, "full report")
8385
cmd.Flags().StringVar(&status, "status", "", fmt.Sprintf("filter by workflow run status: %v", listAvailableWorkflowStatusFlag()))
8486
// Add pagination flags

app/cli/internal/action/attestation_init.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func NewAttestationInit(cfg *AttestationInitOpts) (*AttestationInit, error) {
7070
}
7171

7272
// returns the attestation ID
73-
func (action *AttestationInit) Run(ctx context.Context, contractRevision int, workflowName string) (string, error) {
73+
func (action *AttestationInit) Run(ctx context.Context, contractRevision int, projectName, workflowName string) (string, error) {
7474
if action.dryRun && action.useRemoteState {
7575
return "", errors.New("remote state is not compatible with dry-run mode")
7676
}
@@ -89,6 +89,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, wo
8989
contractResp, err := client.GetContract(ctx, &pb.AttestationServiceGetContractRequest{
9090
ContractRevision: int32(contractRevision),
9191
WorkflowName: workflowName,
92+
ProjectName: projectName,
9293
})
9394
if err != nil {
9495
return "", err
@@ -127,6 +128,7 @@ func (action *AttestationInit) Run(ctx context.Context, contractRevision int, wo
127128
ContractRevision: int32(contractRevision),
128129
// send the workflow name explicitly provided by the user to detect that functional case
129130
WorkflowName: workflowName,
131+
ProjectName: projectName,
130132
},
131133
)
132134
if err != nil {

app/cli/internal/action/attestation_status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type AttestationResultRunnerContext struct {
5252
}
5353

5454
type AttestationStatusWorkflowMeta struct {
55-
WorkflowID, Name, Team, Project, ContractRevision string
55+
WorkflowID, Name, Team, Project, ContractRevision, Organization string
5656
}
5757

5858
type AttestationStatusResultMaterial struct {
@@ -94,6 +94,7 @@ func (action *AttestationStatus) Run(ctx context.Context, attestationID string)
9494
WorkflowMeta: &AttestationStatusWorkflowMeta{
9595
WorkflowID: workflowMeta.GetWorkflowId(),
9696
Name: workflowMeta.GetName(),
97+
Organization: workflowMeta.GetOrganization(),
9798
Project: workflowMeta.GetProject(),
9899
Team: workflowMeta.GetTeam(),
99100
ContractRevision: workflowMeta.GetSchemaRevision(),

app/cli/internal/action/workflow_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type NewWorkflowCreateOpts struct {
3737
func (action *WorkflowCreate) Run(opts *NewWorkflowCreateOpts) (*WorkflowItem, error) {
3838
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
3939
resp, err := client.Create(context.Background(), &pb.WorkflowServiceCreateRequest{
40-
Name: opts.Name, Project: opts.Project, Team: opts.Team, ContractName: opts.ContractName,
40+
Name: opts.Name, ProjectName: opts.Project, Team: opts.Team, ContractName: opts.ContractName,
4141
Description: opts.Description,
4242
Public: opts.Public,
4343
})

app/cli/internal/action/workflow_delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func NewWorkflowDelete(cfg *ActionsOpts) *WorkflowDelete {
2929
return &WorkflowDelete{cfg}
3030
}
3131

32-
func (action *WorkflowDelete) Run(name string) error {
32+
func (action *WorkflowDelete) Run(name, projectName string) error {
3333
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
34-
if _, err := client.Delete(context.Background(), &pb.WorkflowServiceDeleteRequest{Name: name}); err != nil {
34+
if _, err := client.Delete(context.Background(), &pb.WorkflowServiceDeleteRequest{Name: name, ProjectName: projectName}); err != nil {
3535
return err
3636
}
3737

app/cli/internal/action/workflow_describe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ func NewWorkflowDescribe(cfg *ActionsOpts) *WorkflowDescribe {
2929
return &WorkflowDescribe{cfg}
3030
}
3131

32-
func (action *WorkflowDescribe) Run(ctx context.Context, name string) (*WorkflowItem, error) {
32+
func (action *WorkflowDescribe) Run(ctx context.Context, name, projectName string) (*WorkflowItem, error) {
3333
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
3434

35-
req := &pb.WorkflowServiceViewRequest{Name: name}
35+
req := &pb.WorkflowServiceViewRequest{Name: name, ProjectName: projectName}
3636
resp, err := client.View(ctx, req)
3737
if err != nil {
3838
return nil, err

app/cli/internal/action/workflow_run_list.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func NewWorkflowRunList(cfg *ActionsOpts) *WorkflowRunList {
6363
}
6464

6565
type WorkflowRunListOpts struct {
66-
WorkflowName string
67-
Pagination *PaginationOpts
68-
Status string
66+
WorkflowName, ProjectName string
67+
Pagination *PaginationOpts
68+
Status string
6969
}
7070
type PaginationOpts struct {
7171
Limit int
@@ -76,6 +76,7 @@ func (action *WorkflowRunList) Run(opts *WorkflowRunListOpts) (*PaginatedWorkflo
7676
client := pb.NewWorkflowRunServiceClient(action.cfg.CPConnection)
7777
req := &pb.WorkflowRunServiceListRequest{
7878
WorkflowName: opts.WorkflowName,
79+
ProjectName: opts.ProjectName,
7980
Pagination: &pb.CursorPaginationRequest{
8081
Limit: int32(opts.Pagination.Limit),
8182
Cursor: opts.Pagination.NextCursor,

app/cli/internal/action/workflow_update.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ func NewWorkflowUpdate(cfg *ActionsOpts) *WorkflowUpdate {
3030
}
3131

3232
type WorkflowUpdateOpts struct {
33-
Description, Project, Team, ContractName *string
34-
Public *bool
33+
Description, Team, ContractName *string
34+
Public *bool
3535
}
3636

37-
func (action *WorkflowUpdate) Run(ctx context.Context, name string, opts *WorkflowUpdateOpts) (*WorkflowItem, error) {
37+
func (action *WorkflowUpdate) Run(ctx context.Context, name, project string, opts *WorkflowUpdateOpts) (*WorkflowItem, error) {
3838
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
3939
resp, err := client.Update(ctx, &pb.WorkflowServiceUpdateRequest{
4040
Name: name,
41+
ProjectName: project,
4142
Description: opts.Description,
42-
Project: opts.Project,
4343
Team: opts.Team,
4444
Public: opts.Public,
4545
ContractName: opts.ContractName,

0 commit comments

Comments
 (0)