Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/cli/cmd/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ func newWorkflowCmd() *cobra.Command {
Short: "Workflow, contracts, robot-accounts and runs management in the control plane",
}

cmd.AddCommand(newWorkflowListCmd(), newWorkflowCreateCmd(), newWorkflowDeleteCmd(), newWorkflowRobotAccountCmd(), newWorkflowWorkflowRunCmd(), newWorkflowContractCmd(), newAttachedIntegrationCmd())
cmd.AddCommand(newWorkflowListCmd(), newWorkflowCreateCmd(), newWorkflowUpdateCmd(), newWorkflowDeleteCmd(), newWorkflowRobotAccountCmd(), newWorkflowWorkflowRunCmd(), newWorkflowContractCmd(), newAttachedIntegrationCmd())
return cmd
}
67 changes: 67 additions & 0 deletions app/cli/cmd/workflow_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// Copyright 2023 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"context"

"github.com/chainloop-dev/chainloop/app/cli/internal/action"
"github.com/spf13/cobra"
)

func newWorkflowUpdateCmd() *cobra.Command {
var workflowID, name, project, team string
var public bool

cmd := &cobra.Command{
Use: "update",
Short: "Update an existing workflow",
RunE: func(cmd *cobra.Command, args []string) error {
opts := &action.NewWorkflowUpdateOpts{}
if cmd.Flags().Changed("name") {
opts.Name = &name
}
if cmd.Flags().Changed("team") {
opts.Team = &team
}
if cmd.Flags().Changed("project") {
opts.Project = &project
}
if cmd.Flags().Changed("public") {
opts.Public = &public
}

res, err := action.NewWorkflowUpdate(actionOpts).Run(context.Background(), workflowID, opts)
if err != nil {
return err
}

logger.Info().Msg("Workflow updated!")
return encodeOutput([]*action.WorkflowItem{res}, WorkflowListTableOutput)
},
}

cmd.Flags().StringVar(&workflowID, "id", "", "workflow ID")
err := cmd.MarkFlagRequired("id")
cobra.CheckErr(err)

cmd.Flags().StringVar(&name, "name", "", "workflow name")
cmd.Flags().StringVar(&team, "team", "", "team name")
cmd.Flags().StringVar(&project, "project", "", "project name")
cmd.Flags().BoolVar(&public, "public", false, "is the workflow public")

return cmd
}
50 changes: 50 additions & 0 deletions app/cli/internal/action/workflow_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Copyright 2023 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package action

import (
"context"

pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
)

type WorkflowUpdate struct {
cfg *ActionsOpts
}

func NewWorkflowUpdate(cfg *ActionsOpts) *WorkflowUpdate {
return &WorkflowUpdate{cfg}
}

type NewWorkflowUpdateOpts struct {
Name, Project, Team *string
Public *bool
}

func (action *WorkflowUpdate) Run(ctx context.Context, id string, opts *NewWorkflowUpdateOpts) (*WorkflowItem, error) {
client := pb.NewWorkflowServiceClient(action.cfg.CPConnection)
resp, err := client.Update(ctx, &pb.WorkflowServiceUpdateRequest{
Id: id,
Name: opts.Name, Project: opts.Project, Team: opts.Team,
Public: opts.Public,
})

if err != nil {
return nil, err
}

return pbWorkflowItemToAction(resp.Result), nil
}
Loading