Skip to content

Commit 0311143

Browse files
authored
feat(cli): reorganize attached integrations (#166)
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
1 parent 5f69f4f commit 0311143

15 files changed

Lines changed: 42 additions & 172 deletions
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import (
1919
"github.com/spf13/cobra"
2020
)
2121

22-
func newWorkflowIntegrationCmd() *cobra.Command {
22+
func newAttachedIntegrationCmd() *cobra.Command {
2323
cmd := &cobra.Command{
24-
Use: "integration",
25-
Short: "Third party integrations",
24+
Use: "attached",
25+
Short: "Integrations attached to workflows",
2626
}
2727

28-
cmd.AddCommand(newWorkflowIntegrationAttachCmd(), newWorkflowIntegrationDetachCmd(), newWorkflowIntegrationListCmd())
28+
cmd.AddCommand(newAttachedIntegrationAttachCmd(), newAttachedIntegrationDeleteCmd(), newAttachedIntegrationListCmd())
2929
return cmd
3030
}

app/cli/cmd/workflow_integration_attach.go renamed to app/cli/cmd/attached_integration_add.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
func newWorkflowIntegrationAttachCmd() *cobra.Command {
23+
func newAttachedIntegrationAttachCmd() *cobra.Command {
2424
var options []string
2525
var integrationID, workflowID string
2626

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

54-
res, err := action.NewWorkflowIntegrationAttach(actionOpts).Run(integrationID, workflowID, opts)
55+
res, err := action.NewAttachedIntegrationAdd(actionOpts).Run(integrationID, workflowID, opts)
5556
if err != nil {
5657
return err
5758
}
5859

59-
return encodeOutput([]*action.IntegrationAttachmentItem{res}, integrationAttachmentListTableOutput)
60+
return encodeOutput([]*action.AttachedIntegrationItem{res}, attachedIntegrationListTableOutput)
6061
},
6162
}
6263

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

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

7272
return cmd
7373
}

app/cli/cmd/workflow_integration_detach.go renamed to app/cli/cmd/attached_integration_delete.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
func newWorkflowIntegrationDetachCmd() *cobra.Command {
23+
func newAttachedIntegrationDeleteCmd() *cobra.Command {
2424
var attachmentID string
2525

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,31 @@ import (
2626
"golang.org/x/exp/maps"
2727
)
2828

29-
func newWorkflowIntegrationListCmd() *cobra.Command {
29+
func newAttachedIntegrationListCmd() *cobra.Command {
3030
cmd := &cobra.Command{
3131
Use: "list",
3232
Aliases: []string{"ls"},
3333
Short: "List integrations attached to workflows",
3434
RunE: func(cmd *cobra.Command, args []string) error {
35-
res, err := action.NewWorkflowIntegrationList(actionOpts).Run()
35+
res, err := action.NewAttachedIntegrationList(actionOpts).Run()
3636
if err != nil {
3737
return err
3838
}
3939

40-
return encodeOutput(res, integrationAttachmentListTableOutput)
40+
return encodeOutput(res, attachedIntegrationListTableOutput)
4141
},
4242
}
4343

4444
return cmd
4545
}
4646

47-
func integrationAttachmentListTableOutput(attachments []*action.IntegrationAttachmentItem) error {
47+
func attachedIntegrationListTableOutput(attachments []*action.AttachedIntegrationItem) error {
4848
if len(attachments) == 0 {
4949
fmt.Println("there are no integration attached")
5050
return nil
5151
}
5252

53+
fmt.Println("Integrations attached to workflows")
5354
t := newTableWriter()
5455
t.AppendHeader(table.Row{"ID", "Kind", "Config", "Attached At", "Workflow"})
5556
for _, i := range attachments {

app/cli/cmd/available_integration_list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func availableIntegrationListTableOutput(items []*action.AvailableIntegrationIte
4747
return nil
4848
}
4949

50+
fmt.Println("Available integrations ready to be used during registration")
51+
5052
t := newTableWriter()
5153
t.AppendHeader(table.Row{"ID", "Version", "Description"})
5254
for _, i := range items {

app/cli/cmd/integration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ func newIntegrationCmd() *cobra.Command {
2525
Short: "Third party integrations",
2626
}
2727

28-
cmd.AddCommand(newRegisteredIntegrationCmd(), newAvailableIntegrationCmd())
28+
cmd.AddCommand(newRegisteredIntegrationCmd(), newAvailableIntegrationCmd(), newAttachedIntegrationCmd())
2929
return cmd
3030
}

app/cli/cmd/output.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type tabulatedData interface {
4141
*action.ConfigContextItem |
4242
[]*action.RegisteredIntegrationItem |
4343
[]*action.AvailableIntegrationItem |
44-
[]*action.IntegrationAttachmentItem |
44+
[]*action.AttachedIntegrationItem |
4545
[]*action.MembershipItem
4646
}
4747

app/cli/cmd/registered_integration_add.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ func newRegisteredIntegrationAddCmd() *cobra.Command {
6868
cmd.Flags().StringVar(&integrationDescription, "description", "", "integration registration description")
6969
cmd.Flags().StringSliceVar(&options, "options", nil, "integration arguments")
7070

71-
// We maintain the dependencytrack integration as a separate command for now
72-
// for compatibility reasons
73-
cmd.AddCommand(newRegisteredIntegrationAddDepTrackCmd())
74-
7571
return cmd
7672
}
7773

app/cli/cmd/registered_integration_add_deptrack.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

app/cli/cmd/registered_integration_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func registeredIntegrationListTableOutput(items []*action.RegisteredIntegrationI
4949
return nil
5050
}
5151

52+
fmt.Println("Integrations registered and configured in your organization")
5253
t := newTableWriter()
5354
t.AppendHeader(table.Row{"ID", "Description", "Kind", "Config", "Created At"})
5455
for _, i := range items {

0 commit comments

Comments
 (0)