Skip to content

Commit 5488f49

Browse files
authored
fix(controlplane): allow changing contract by name (#1065)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 67a0ed3 commit 5488f49

File tree

7 files changed

+149
-119
lines changed

7 files changed

+149
-119
lines changed

app/cli/cmd/workflow_update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func newWorkflowUpdateCmd() *cobra.Command {
26-
var name, description, project, team, contractID string
26+
var name, description, project, team, contractName string
2727
var public bool
2828

2929
cmd := &cobra.Command{
@@ -46,7 +46,7 @@ func newWorkflowUpdateCmd() *cobra.Command {
4646
}
4747

4848
if cmd.Flags().Changed("contract") {
49-
opts.ContractID = &contractID
49+
opts.ContractName = &contractName
5050
}
5151

5252
res, err := action.NewWorkflowUpdate(actionOpts).Run(context.Background(), name, opts)
@@ -66,7 +66,7 @@ func newWorkflowUpdateCmd() *cobra.Command {
6666
cmd.Flags().StringVar(&team, "team", "", "team name")
6767
cmd.Flags().StringVar(&project, "project", "", "project name")
6868
cmd.Flags().BoolVar(&public, "public", false, "is the workflow public")
69-
cmd.Flags().StringVar(&contractID, "contract", "", "the ID of an existing contract")
69+
cmd.Flags().StringVar(&contractName, "contract", "", "the name of an existing contract")
7070

7171
return cmd
7272
}

app/cli/internal/action/workflow_update.go

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

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

3737
func (action *WorkflowUpdate) Run(ctx context.Context, name string, opts *WorkflowUpdateOpts) (*WorkflowItem, error) {
3838
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
3939
resp, err := client.Update(ctx, &pb.WorkflowServiceUpdateRequest{
40-
Name: name,
41-
Description: opts.Description,
42-
Project: opts.Project,
43-
Team: opts.Team,
44-
Public: opts.Public,
45-
SchemaId: opts.ContractID,
40+
Name: name,
41+
Description: opts.Description,
42+
Project: opts.Project,
43+
Team: opts.Team,
44+
Public: opts.Public,
45+
ContractName: opts.ContractName,
4646
})
4747

4848
if err != nil {

app/controlplane/api/controlplane/v1/workflow.pb.go

Lines changed: 102 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/workflow.proto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ message WorkflowServiceUpdateRequest {
6969
optional string team = 4;
7070
optional bool public = 5;
7171
optional string description = 6;
72-
optional string schema_id = 7;
72+
optional string contract_name = 7 [(buf.validate.field) = {
73+
cel: {
74+
message: "must contain only lowercase letters, numbers, and hyphens.",
75+
expression: "this.matches('^[a-z0-9]([-a-z0-9]*[a-z0-9])?$')",
76+
id: "name.dns-1123",
77+
},
78+
}];
7379
}
7480

7581
message WorkflowServiceUpdateResponse {

app/controlplane/api/gen/frontend/controlplane/v1/workflow.ts

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/cmd/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/service/workflow.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ type WorkflowService struct {
2828
pb.UnimplementedWorkflowServiceServer
2929
*service
3030

31-
useCase *biz.WorkflowUseCase
31+
useCase *biz.WorkflowUseCase
32+
contractUC *biz.WorkflowContractUseCase
3233
}
3334

34-
func NewWorkflowService(uc *biz.WorkflowUseCase, opts ...NewOpt) *WorkflowService {
35+
func NewWorkflowService(uc *biz.WorkflowUseCase, wfuc *biz.WorkflowContractUseCase, opts ...NewOpt) *WorkflowService {
3536
return &WorkflowService{
36-
service: newService(opts...),
37-
useCase: uc,
37+
service: newService(opts...),
38+
useCase: uc,
39+
contractUC: wfuc,
3840
}
3941
}
4042

@@ -73,12 +75,25 @@ func (s *WorkflowService) Update(ctx context.Context, req *pb.WorkflowServiceUpd
7375
return nil, handleUseCaseErr(err, s.log)
7476
}
7577

78+
var contractID *string
79+
if req.ContractName != nil {
80+
c, err := s.contractUC.FindByNameInOrg(ctx, currentOrg.ID, *req.ContractName)
81+
if err != nil {
82+
return nil, handleUseCaseErr(err, s.log)
83+
} else if c == nil {
84+
return nil, biz.NewErrNotFound("contract")
85+
}
86+
87+
cid := c.ID.String()
88+
contractID = &cid
89+
}
90+
7691
updateOpts := &biz.WorkflowUpdateOpts{
7792
Project: req.Project,
7893
Team: req.Team,
7994
Public: req.Public,
8095
Description: req.Description,
81-
ContractID: req.SchemaId,
96+
ContractID: contractID,
8297
}
8398

8499
p, err := s.useCase.Update(ctx, currentOrg.ID, wf.ID.String(), updateOpts)

0 commit comments

Comments
 (0)