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
7 changes: 6 additions & 1 deletion app/cli/cmd/workflow_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

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

cmd := &cobra.Command{
Expand All @@ -48,6 +48,10 @@ func newWorkflowUpdateCmd() *cobra.Command {
opts.Description = &description
}

if cmd.Flags().Changed("contract") {
opts.ContractID = &contractID
}

res, err := action.NewWorkflowUpdate(actionOpts).Run(context.Background(), workflowID, opts)
if err != nil {
return err
Expand All @@ -67,6 +71,7 @@ func newWorkflowUpdateCmd() *cobra.Command {
cmd.Flags().StringVar(&team, "team", "", "team name")
cmd.Flags().StringVar(&project, "project", "", "project name")
cmd.Flags().BoolVar(&public, "public", false, "is the workflow public")
cmd.Flags().StringVar(&contractID, "contract", "", "the ID of an existing contract")

return cmd
}
7 changes: 4 additions & 3 deletions app/cli/internal/action/workflow_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func NewWorkflowUpdate(cfg *ActionsOpts) *WorkflowUpdate {
}

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

func (action *WorkflowUpdate) Run(ctx context.Context, id string, opts *NewWorkflowUpdateOpts) (*WorkflowItem, error) {
Expand All @@ -40,7 +40,8 @@ func (action *WorkflowUpdate) Run(ctx context.Context, id string, opts *NewWorkf
Id: id,
Name: opts.Name, Description: opts.Description,
Project: opts.Project, Team: opts.Team,
Public: opts.Public,
Public: opts.Public,
SchemaId: opts.ContractID,
})

if err != nil {
Expand Down
23 changes: 17 additions & 6 deletions app/controlplane/api/controlplane/v1/workflow.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/controlplane/api/controlplane/v1/workflow.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/controlplane/api/controlplane/v1/workflow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ message WorkflowServiceUpdateRequest {
optional string team = 4;
optional bool public = 5;
optional string description = 6;
optional string schema_id = 7;
}

message WorkflowServiceUpdateResponse {
Expand Down
24 changes: 23 additions & 1 deletion app/controlplane/api/gen/frontend/controlplane/v1/workflow.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions app/controlplane/internal/biz/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ type WorkflowCreateOpts struct {
}

type WorkflowUpdateOpts struct {
Name, Project, Team, Description *string
Public *bool
Name, Project, Team, Description, ContractID *string
Public *bool
}

type WorkflowUseCase struct {
Expand Down Expand Up @@ -144,6 +144,15 @@ func (uc *WorkflowUseCase) Update(ctx context.Context, orgID, workflowID string,
return nil, NewErrNotFound("workflow in organization")
}

// Double check that the contract exists
if opts.ContractID != nil {
if c, err := uc.contractUC.FindByIDInOrg(ctx, orgID, *opts.ContractID); err != nil {
return nil, err
} else if c == nil {
return nil, NewErrNotFound("contract")
}
}

wf, err := uc.wfRepo.Update(ctx, workflowUUID, opts)
if err != nil {
if errors.Is(err, ErrAlreadyExists) {
Expand Down
16 changes: 16 additions & 0 deletions app/controlplane/internal/biz/workflow_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ func (s *workflowIntegrationTestSuite) TestUpdate() {
workflow, err := s.Workflow.Create(ctx, &biz.WorkflowCreateOpts{Name: name, OrgID: s.org.ID})
require.NoError(s.T(), err)

// Create two contracts in two different orgs
contract1, err := s.WorkflowContract.Create(ctx, &biz.WorkflowContractCreateOpts{Name: "contract-1", OrgID: s.org.ID})
require.NoError(s.T(), err)
contract2, err := s.WorkflowContract.Create(ctx, &biz.WorkflowContractCreateOpts{Name: "contract-2", OrgID: org2.ID})
require.NoError(s.T(), err)

s.Run("by default the workflow is private", func() {
s.False(workflow.Public)
})
Expand Down Expand Up @@ -238,6 +244,16 @@ func (s *workflowIntegrationTestSuite) TestUpdate() {
updates: &biz.WorkflowUpdateOpts{Name: toPtrS("")},
wantErr: true,
},
{
name: "can update contract",
updates: &biz.WorkflowUpdateOpts{ContractID: toPtrS(contract1.ID.String())},
want: &biz.Workflow{Description: description, Team: team, Project: project, ContractID: contract2.ID},
},
{
name: "can not update contract in another org",
updates: &biz.WorkflowUpdateOpts{ContractID: toPtrS(contract2.ID.String())},
wantErr: true,
},
{
name: "but other opts can",
updates: &biz.WorkflowUpdateOpts{Team: toPtrS(""), Project: toPtrS(""), Description: toPtrS("")},
Expand Down
9 changes: 9 additions & 0 deletions app/controlplane/internal/data/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ func (r *WorkflowRepo) Update(ctx context.Context, id uuid.UUID, opts *biz.Workf
req = req.SetName(*opts.Name)
}

// Update the contract if provided
if opts.ContractID != nil {
contractUUID, err := uuid.Parse(*opts.ContractID)
if err != nil {
return nil, err
}
req = req.SetContractID(contractUUID)
}

wf, err := req.Save(ctx)

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion app/controlplane/internal/service/workflow.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2024 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.
Expand Down Expand Up @@ -79,6 +79,7 @@ func (s *WorkflowService) Update(ctx context.Context, req *pb.WorkflowServiceUpd
Team: req.Team,
Public: req.Public,
Description: req.Description,
ContractID: req.SchemaId,
}

p, err := s.useCase.Update(ctx, currentOrg.ID, req.Id, updateOpts)
Expand Down