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
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"github.com/spf13/cobra"
)

func newWorkflowIntegrationCmd() *cobra.Command {
func newAttachedIntegrationCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "integration",
Short: "Third party integrations",
Use: "attached",
Short: "Integrations attached to workflows",
}

cmd.AddCommand(newWorkflowIntegrationAttachCmd(), newWorkflowIntegrationDetachCmd(), newWorkflowIntegrationListCmd())
cmd.AddCommand(newAttachedIntegrationAttachCmd(), newAttachedIntegrationDeleteCmd(), newAttachedIntegrationListCmd())
return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
"github.com/spf13/cobra"
)

func newWorkflowIntegrationAttachCmd() *cobra.Command {
func newAttachedIntegrationAttachCmd() *cobra.Command {
var options []string
var integrationID, workflowID string

cmd := &cobra.Command{
Use: "attach",
Use: "add",
Aliases: []string{"attach"},
Short: "Attach an existing registered integration to a workflow",
Example: ` chainloop workflow integration attach --workflow deadbeef --integration beefdoingwell --options projectName=MyProject`,
Example: ` chainloop integration attached add --workflow deadbeef --integration beefdoingwell --options projectName=MyProject`,
RunE: func(cmd *cobra.Command, args []string) error {
// Find the integration to extract the kind of integration we care about
integration, err := action.NewRegisteredIntegrationDescribe(actionOpts).Run(integrationID)
Expand All @@ -51,12 +52,12 @@ func newWorkflowIntegrationAttachCmd() *cobra.Command {
return err
}

res, err := action.NewWorkflowIntegrationAttach(actionOpts).Run(integrationID, workflowID, opts)
res, err := action.NewAttachedIntegrationAdd(actionOpts).Run(integrationID, workflowID, opts)
if err != nil {
return err
}

return encodeOutput([]*action.IntegrationAttachmentItem{res}, integrationAttachmentListTableOutput)
return encodeOutput([]*action.AttachedIntegrationItem{res}, attachedIntegrationListTableOutput)
},
}

Expand All @@ -67,7 +68,6 @@ func newWorkflowIntegrationAttachCmd() *cobra.Command {
cobra.CheckErr(cmd.MarkFlagRequired("workflow"))

cmd.Flags().StringSliceVar(&options, "options", nil, "integration attachment arguments")
cmd.AddCommand(newWorkflowIntegrationAttachDependencyTrackCmd())

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
"github.com/spf13/cobra"
)

func newWorkflowIntegrationDetachCmd() *cobra.Command {
func newAttachedIntegrationDeleteCmd() *cobra.Command {
var attachmentID string

cmd := &cobra.Command{
Use: "detach",
Short: "Remove a third-party integration attached to a workflow",
Use: "delete",
Aliases: []string{"detach"},
Short: "Detach an integration that's attached to a workflow",
RunE: func(cmd *cobra.Command, args []string) error {
if err := action.NewWorkflowIntegrationDetach(actionOpts).Run(attachmentID); err != nil {
if err := action.NewAttachedIntegrationDelete(actionOpts).Run(attachmentID); err != nil {
return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,31 @@ import (
"golang.org/x/exp/maps"
)

func newWorkflowIntegrationListCmd() *cobra.Command {
func newAttachedIntegrationListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List integrations attached to workflows",
RunE: func(cmd *cobra.Command, args []string) error {
res, err := action.NewWorkflowIntegrationList(actionOpts).Run()
res, err := action.NewAttachedIntegrationList(actionOpts).Run()
if err != nil {
return err
}

return encodeOutput(res, integrationAttachmentListTableOutput)
return encodeOutput(res, attachedIntegrationListTableOutput)
},
}

return cmd
}

func integrationAttachmentListTableOutput(attachments []*action.IntegrationAttachmentItem) error {
func attachedIntegrationListTableOutput(attachments []*action.AttachedIntegrationItem) error {
if len(attachments) == 0 {
fmt.Println("there are no integration attached")
return nil
}

fmt.Println("Integrations attached to workflows")
t := newTableWriter()
t.AppendHeader(table.Row{"ID", "Kind", "Config", "Attached At", "Workflow"})
for _, i := range attachments {
Expand Down
2 changes: 2 additions & 0 deletions app/cli/cmd/available_integration_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func availableIntegrationListTableOutput(items []*action.AvailableIntegrationIte
return nil
}

fmt.Println("Available integrations ready to be used during registration")

t := newTableWriter()
t.AppendHeader(table.Row{"ID", "Version", "Description"})
for _, i := range items {
Expand Down
2 changes: 1 addition & 1 deletion app/cli/cmd/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ func newIntegrationCmd() *cobra.Command {
Short: "Third party integrations",
}

cmd.AddCommand(newRegisteredIntegrationCmd(), newAvailableIntegrationCmd())
cmd.AddCommand(newRegisteredIntegrationCmd(), newAvailableIntegrationCmd(), newAttachedIntegrationCmd())
return cmd
}
2 changes: 1 addition & 1 deletion app/cli/cmd/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type tabulatedData interface {
*action.ConfigContextItem |
[]*action.RegisteredIntegrationItem |
[]*action.AvailableIntegrationItem |
[]*action.IntegrationAttachmentItem |
[]*action.AttachedIntegrationItem |
[]*action.MembershipItem
}

Expand Down
4 changes: 0 additions & 4 deletions app/cli/cmd/registered_integration_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func newRegisteredIntegrationAddCmd() *cobra.Command {
cmd.Flags().StringVar(&integrationDescription, "description", "", "integration registration description")
cmd.Flags().StringSliceVar(&options, "options", nil, "integration arguments")

// We maintain the dependencytrack integration as a separate command for now
// for compatibility reasons
cmd.AddCommand(newRegisteredIntegrationAddDepTrackCmd())

return cmd
}

Expand Down
65 changes: 0 additions & 65 deletions app/cli/cmd/registered_integration_add_deptrack.go

This file was deleted.

1 change: 1 addition & 0 deletions app/cli/cmd/registered_integration_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func registeredIntegrationListTableOutput(items []*action.RegisteredIntegrationI
return nil
}

fmt.Println("Integrations registered and configured in your organization")
t := newTableWriter()
t.AppendHeader(table.Row{"ID", "Description", "Kind", "Config", "Created At"})
for _, i := range items {
Expand Down
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(), newWorkflowIntegrationCmd())
cmd.AddCommand(newWorkflowListCmd(), newWorkflowCreateCmd(), newWorkflowDeleteCmd(), newWorkflowRobotAccountCmd(), newWorkflowWorkflowRunCmd(), newWorkflowContractCmd(), newAttachedIntegrationCmd())
return cmd
}
66 changes: 0 additions & 66 deletions app/cli/cmd/workflow_integration_attach_deptrack.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
)

// Attach a third party integration to a workflow
type WorkflowIntegrationAttach struct{ cfg *ActionsOpts }
type AttachedIntegrationAdd struct{ cfg *ActionsOpts }

func NewWorkflowIntegrationAttach(cfg *ActionsOpts) *WorkflowIntegrationAttach {
return &WorkflowIntegrationAttach{cfg}
func NewAttachedIntegrationAdd(cfg *ActionsOpts) *AttachedIntegrationAdd {
return &AttachedIntegrationAdd{cfg}
}

func (action *WorkflowIntegrationAttach) Run(integrationID, workflowID string, options map[string]any) (*IntegrationAttachmentItem, error) {
func (action *AttachedIntegrationAdd) Run(integrationID, workflowID string, options map[string]any) (*AttachedIntegrationItem, error) {
client := pb.NewIntegrationsServiceClient(action.cfg.CPConnection)

requestConfig, err := structpb.NewStruct(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
)

type WorkflowIntegrationDetach struct{ cfg *ActionsOpts }
type AttachedIntegrationDelete struct{ cfg *ActionsOpts }

func NewWorkflowIntegrationDetach(cfg *ActionsOpts) *WorkflowIntegrationDetach {
return &WorkflowIntegrationDetach{cfg}
func NewAttachedIntegrationDelete(cfg *ActionsOpts) *AttachedIntegrationDelete {
return &AttachedIntegrationDelete{cfg}
}

func (action *WorkflowIntegrationDetach) Run(attachmentID string) error {
func (action *AttachedIntegrationDelete) Run(attachmentID string) error {
client := pb.NewIntegrationsServiceClient(action.cfg.CPConnection)

_, err := client.Detach(context.Background(), &pb.IntegrationsServiceDetachRequest{Id: attachmentID})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ import (
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
)

type WorkflowIntegrationList struct{ cfg *ActionsOpts }
type AttachedIntegrationList struct{ cfg *ActionsOpts }

func NewWorkflowIntegrationList(cfg *ActionsOpts) *WorkflowIntegrationList {
return &WorkflowIntegrationList{cfg}
func NewAttachedIntegrationList(cfg *ActionsOpts) *AttachedIntegrationList {
return &AttachedIntegrationList{cfg}
}

func (action *WorkflowIntegrationList) Run() ([]*IntegrationAttachmentItem, error) {
func (action *AttachedIntegrationList) Run() ([]*AttachedIntegrationItem, error) {
client := pb.NewIntegrationsServiceClient(action.cfg.CPConnection)

resp, err := client.ListAttachments(context.Background(), &pb.ListAttachmentsRequest{})
if err != nil {
return nil, err
}

result := make([]*IntegrationAttachmentItem, 0, len(resp.Result))
result := make([]*AttachedIntegrationItem, 0, len(resp.Result))
for _, i := range resp.Result {
attachment, err := pbIntegrationAttachmentItemToAction(i)
if err != nil {
Expand All @@ -50,13 +50,13 @@ func (action *WorkflowIntegrationList) Run() ([]*IntegrationAttachmentItem, erro
return result, nil
}

func pbIntegrationAttachmentItemToAction(in *pb.IntegrationAttachmentItem) (*IntegrationAttachmentItem, error) {
func pbIntegrationAttachmentItemToAction(in *pb.IntegrationAttachmentItem) (*AttachedIntegrationItem, error) {
integration, err := pbRegisteredIntegrationItemToAction(in.GetIntegration())
if err != nil {
return nil, err
}

i := &IntegrationAttachmentItem{
i := &AttachedIntegrationItem{
ID: in.GetId(),
CreatedAt: toTimePtr(in.GetCreatedAt().AsTime()),
Integration: integration,
Expand All @@ -76,7 +76,7 @@ func pbIntegrationAttachmentItemToAction(in *pb.IntegrationAttachmentItem) (*Int
return i, nil
}

type IntegrationAttachmentItem struct {
type AttachedIntegrationItem struct {
ID string `json:"id"`
CreatedAt *time.Time `json:"createdAt"`
Config map[string]interface{} `json:"config"`
Expand Down