Skip to content

Commit a0e511a

Browse files
authored
feat: workflow update (#436)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent d8662de commit a0e511a

File tree

17 files changed

+1047
-776
lines changed

17 files changed

+1047
-776
lines changed

app/cli/cmd/workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ func newWorkflowCmd() *cobra.Command {
2626
Short: "Workflow, contracts, robot-accounts and runs management in the control plane",
2727
}
2828

29-
cmd.AddCommand(newWorkflowListCmd(), newWorkflowCreateCmd(), newWorkflowDeleteCmd(), newWorkflowRobotAccountCmd(), newWorkflowWorkflowRunCmd(), newWorkflowContractCmd(), newAttachedIntegrationCmd())
29+
cmd.AddCommand(newWorkflowListCmd(), newWorkflowCreateCmd(), newWorkflowUpdateCmd(), newWorkflowDeleteCmd(), newWorkflowRobotAccountCmd(), newWorkflowWorkflowRunCmd(), newWorkflowContractCmd(), newAttachedIntegrationCmd())
3030
return cmd
3131
}

app/cli/cmd/workflow_update.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// Copyright 2023 The Chainloop Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package cmd
17+
18+
import (
19+
"context"
20+
21+
"github.com/chainloop-dev/chainloop/app/cli/internal/action"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
func newWorkflowUpdateCmd() *cobra.Command {
26+
var workflowID, name, project, team string
27+
var public bool
28+
29+
cmd := &cobra.Command{
30+
Use: "update",
31+
Short: "Update an existing workflow",
32+
RunE: func(cmd *cobra.Command, args []string) error {
33+
opts := &action.NewWorkflowUpdateOpts{}
34+
if cmd.Flags().Changed("name") {
35+
opts.Name = &name
36+
}
37+
if cmd.Flags().Changed("team") {
38+
opts.Team = &team
39+
}
40+
if cmd.Flags().Changed("project") {
41+
opts.Project = &project
42+
}
43+
if cmd.Flags().Changed("public") {
44+
opts.Public = &public
45+
}
46+
47+
res, err := action.NewWorkflowUpdate(actionOpts).Run(context.Background(), workflowID, opts)
48+
if err != nil {
49+
return err
50+
}
51+
52+
logger.Info().Msg("Workflow updated!")
53+
return encodeOutput([]*action.WorkflowItem{res}, WorkflowListTableOutput)
54+
},
55+
}
56+
57+
cmd.Flags().StringVar(&workflowID, "id", "", "workflow ID")
58+
err := cmd.MarkFlagRequired("id")
59+
cobra.CheckErr(err)
60+
61+
cmd.Flags().StringVar(&name, "name", "", "workflow name")
62+
cmd.Flags().StringVar(&team, "team", "", "team name")
63+
cmd.Flags().StringVar(&project, "project", "", "project name")
64+
cmd.Flags().BoolVar(&public, "public", false, "is the workflow public")
65+
66+
return cmd
67+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Copyright 2023 The Chainloop Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package action
17+
18+
import (
19+
"context"
20+
21+
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
22+
)
23+
24+
type WorkflowUpdate struct {
25+
cfg *ActionsOpts
26+
}
27+
28+
func NewWorkflowUpdate(cfg *ActionsOpts) *WorkflowUpdate {
29+
return &WorkflowUpdate{cfg}
30+
}
31+
32+
type NewWorkflowUpdateOpts struct {
33+
Name, Project, Team *string
34+
Public *bool
35+
}
36+
37+
func (action *WorkflowUpdate) Run(ctx context.Context, id string, opts *NewWorkflowUpdateOpts) (*WorkflowItem, error) {
38+
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
39+
resp, err := client.Update(ctx, &pb.WorkflowServiceUpdateRequest{
40+
Id: id,
41+
Name: opts.Name, Project: opts.Project, Team: opts.Team,
42+
Public: opts.Public,
43+
})
44+
45+
if err != nil {
46+
return nil, err
47+
}
48+
49+
return pbWorkflowItemToAction(resp.Result), nil
50+
}

0 commit comments

Comments
 (0)