Skip to content

Commit 134a1d9

Browse files
authored
feat(controlplane): workflow contract description support (#608)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 033193b commit 134a1d9

36 files changed

+759
-332
lines changed

app/cli/cmd/workflow_contract_create.go

Lines changed: 8 additions & 3 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.
@@ -21,13 +21,17 @@ import (
2121
)
2222

2323
func newWorkflowContractCreateCmd() *cobra.Command {
24-
var name, contractPath string
24+
var name, description, contractPath string
2525

2626
cmd := &cobra.Command{
2727
Use: "create",
2828
Short: "Create a new contract",
2929
RunE: func(cmd *cobra.Command, args []string) error {
30-
res, err := action.NewWorkflowContractCreate(actionOpts).Run(name, contractPath)
30+
var desc *string
31+
if cmd.Flags().Changed("description") {
32+
desc = &description
33+
}
34+
res, err := action.NewWorkflowContractCreate(actionOpts).Run(name, desc, contractPath)
3135
if err != nil {
3236
return err
3337
}
@@ -42,6 +46,7 @@ func newWorkflowContractCreateCmd() *cobra.Command {
4246
cobra.CheckErr(err)
4347

4448
cmd.Flags().StringVarP(&contractPath, "contract", "f", "", "path or URL to the contract schema")
49+
cmd.Flags().StringVar(&description, "description", "", "description of the contract")
4550

4651
return cmd
4752
}

app/cli/cmd/workflow_contract_describe.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ func contractDescribeTableOutput(contractWithVersion *action.WorkflowContractWit
9797
t.SetTitle("Contract")
9898
t.AppendRow(table.Row{"Name", c.Name})
9999
t.AppendSeparator()
100+
t.AppendRow(table.Row{"Description", c.Description})
101+
t.AppendSeparator()
100102
t.AppendRow(table.Row{"ID", c.ID})
101103
t.AppendSeparator()
102104
t.AppendRow(table.Row{"Associated Workflows", strings.Join(c.WorkflowIDs, ", ")})

app/cli/cmd/workflow_contract_list.go

Lines changed: 1 addition & 1 deletion
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.

app/cli/cmd/workflow_contract_update.go

Lines changed: 9 additions & 3 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.
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func newWorkflowContractUpdateCmd() *cobra.Command {
26-
var contractID, name, contractPath string
26+
var contractID, name, description, contractPath string
2727

2828
cmd := &cobra.Command{
2929
Use: "update",
@@ -35,7 +35,12 @@ func newWorkflowContractUpdateCmd() *cobra.Command {
3535
return nil
3636
},
3737
RunE: func(cmd *cobra.Command, args []string) error {
38-
res, err := action.NewWorkflowContractUpdate(actionOpts).Run(contractID, name, contractPath)
38+
var desc *string
39+
if cmd.Flags().Changed("description") {
40+
desc = &description
41+
}
42+
43+
res, err := action.NewWorkflowContractUpdate(actionOpts).Run(contractID, name, desc, contractPath)
3944
if err != nil {
4045
return err
4146
}
@@ -51,6 +56,7 @@ func newWorkflowContractUpdateCmd() *cobra.Command {
5156

5257
cmd.Flags().StringVarP(&contractPath, "contract", "f", "", "path or URL to the contract schema")
5358
cmd.Flags().StringVar(&name, "name", "", "name of the contract")
59+
cmd.Flags().StringVar(&description, "description", "", "description of the contract")
5460

5561
return cmd
5662
}

app/cli/cmd/workflow_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ func newWorkflowCreateCmd() *cobra.Command {
4848
// If it's provided by the UUID we skip this
4949
if contract != "" {
5050
if !isValidUUID(contract) {
51-
ccreateResp, err := action.NewWorkflowContractCreate(actionOpts).Run(fmt.Sprintf("%s/%s", project, workflowName), contract)
51+
createResp, err := action.NewWorkflowContractCreate(actionOpts).Run(fmt.Sprintf("%s/%s", project, workflowName), nil, contract)
5252
if err != nil {
5353
return err
5454
}
55-
contract = ccreateResp.ID
55+
contract = createResp.ID
5656
}
5757
}
5858

app/cli/internal/action/workflow_contract_create.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ func NewWorkflowContractCreate(cfg *ActionsOpts) *WorkflowContractCreate {
3030
return &WorkflowContractCreate{cfg}
3131
}
3232

33-
func (action *WorkflowContractCreate) Run(name, contractPath string) (*WorkflowContractItem, error) {
33+
func (action *WorkflowContractCreate) Run(name string, description *string, contractPath string) (*WorkflowContractItem, error) {
3434
client := pb.NewWorkflowContractServiceClient(action.cfg.CPConnection)
3535

36-
request := &pb.WorkflowContractServiceCreateRequest{Name: name}
36+
request := &pb.WorkflowContractServiceCreateRequest{
37+
Name: name, Description: description,
38+
}
39+
3740
if contractPath != "" {
3841
contract, err := crafter.LoadSchema(contractPath)
3942
if err != nil {

app/cli/internal/action/workflow_contract_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type WorkflowContractList struct {
2929

3030
type WorkflowContractItem struct {
3131
Name string `json:"name"`
32+
Description string `json:"description,omitempty"`
3233
ID string `json:"id"`
3334
LatestRevision int `json:"latestRevision,omitempty"`
3435
CreatedAt *time.Time `json:"createdAt"`
@@ -64,7 +65,7 @@ func (action *WorkflowContractList) Run() ([]*WorkflowContractItem, error) {
6465
func pbWorkflowContractItemToAction(in *pb.WorkflowContractItem) *WorkflowContractItem {
6566
return &WorkflowContractItem{
6667
Name: in.GetName(), ID: in.GetId(), LatestRevision: int(in.GetLatestRevision()),
67-
CreatedAt: toTimePtr(in.GetCreatedAt().AsTime()), WorkflowIDs: in.WorkflowIds,
68+
CreatedAt: toTimePtr(in.GetCreatedAt().AsTime()), WorkflowIDs: in.WorkflowIds, Description: in.GetDescription(),
6869
}
6970
}
7071

app/cli/internal/action/workflow_contract_update.go

Lines changed: 3 additions & 3 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.
@@ -30,10 +30,10 @@ func NewWorkflowContractUpdate(cfg *ActionsOpts) *WorkflowContractUpdate {
3030
return &WorkflowContractUpdate{cfg}
3131
}
3232

33-
func (action *WorkflowContractUpdate) Run(contractID, name, contractPath string) (*WorkflowContractWithVersionItem, error) {
33+
func (action *WorkflowContractUpdate) Run(contractID, name string, description *string, contractPath string) (*WorkflowContractWithVersionItem, error) {
3434
client := pb.NewWorkflowContractServiceClient(action.cfg.CPConnection)
3535

36-
request := &pb.WorkflowContractServiceUpdateRequest{Id: contractID, Name: name}
36+
request := &pb.WorkflowContractServiceUpdateRequest{Id: contractID, Name: name, Description: description}
3737
if contractPath != "" {
3838
contract, err := crafter.LoadSchema(contractPath)
3939
if err != nil {

0 commit comments

Comments
 (0)