diff --git a/app/cli/cmd/workflow_integration.go b/app/cli/cmd/attached_integration.go similarity index 74% rename from app/cli/cmd/workflow_integration.go rename to app/cli/cmd/attached_integration.go index d9d02272e..26b75fef5 100644 --- a/app/cli/cmd/workflow_integration.go +++ b/app/cli/cmd/attached_integration.go @@ -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 } diff --git a/app/cli/cmd/workflow_integration_attach.go b/app/cli/cmd/attached_integration_add.go similarity index 81% rename from app/cli/cmd/workflow_integration_attach.go rename to app/cli/cmd/attached_integration_add.go index 8abbee705..35916412e 100644 --- a/app/cli/cmd/workflow_integration_attach.go +++ b/app/cli/cmd/attached_integration_add.go @@ -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) @@ -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) }, } @@ -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 } diff --git a/app/cli/cmd/workflow_integration_detach.go b/app/cli/cmd/attached_integration_delete.go similarity index 81% rename from app/cli/cmd/workflow_integration_detach.go rename to app/cli/cmd/attached_integration_delete.go index 669191efc..8bfc250f4 100644 --- a/app/cli/cmd/workflow_integration_detach.go +++ b/app/cli/cmd/attached_integration_delete.go @@ -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 } diff --git a/app/cli/cmd/workflow_integration_list.go b/app/cli/cmd/attached_integration_list.go similarity index 83% rename from app/cli/cmd/workflow_integration_list.go rename to app/cli/cmd/attached_integration_list.go index 6c857c6ef..feddc2f38 100644 --- a/app/cli/cmd/workflow_integration_list.go +++ b/app/cli/cmd/attached_integration_list.go @@ -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 { diff --git a/app/cli/cmd/available_integration_list.go b/app/cli/cmd/available_integration_list.go index 8096729df..1053d9356 100644 --- a/app/cli/cmd/available_integration_list.go +++ b/app/cli/cmd/available_integration_list.go @@ -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 { diff --git a/app/cli/cmd/integration.go b/app/cli/cmd/integration.go index 4d65f24f5..6d5c5ab46 100644 --- a/app/cli/cmd/integration.go +++ b/app/cli/cmd/integration.go @@ -25,6 +25,6 @@ func newIntegrationCmd() *cobra.Command { Short: "Third party integrations", } - cmd.AddCommand(newRegisteredIntegrationCmd(), newAvailableIntegrationCmd()) + cmd.AddCommand(newRegisteredIntegrationCmd(), newAvailableIntegrationCmd(), newAttachedIntegrationCmd()) return cmd } diff --git a/app/cli/cmd/output.go b/app/cli/cmd/output.go index 558d906b1..24fca31e7 100644 --- a/app/cli/cmd/output.go +++ b/app/cli/cmd/output.go @@ -41,7 +41,7 @@ type tabulatedData interface { *action.ConfigContextItem | []*action.RegisteredIntegrationItem | []*action.AvailableIntegrationItem | - []*action.IntegrationAttachmentItem | + []*action.AttachedIntegrationItem | []*action.MembershipItem } diff --git a/app/cli/cmd/registered_integration_add.go b/app/cli/cmd/registered_integration_add.go index 1044d4ccc..b3300d52d 100644 --- a/app/cli/cmd/registered_integration_add.go +++ b/app/cli/cmd/registered_integration_add.go @@ -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 } diff --git a/app/cli/cmd/registered_integration_add_deptrack.go b/app/cli/cmd/registered_integration_add_deptrack.go deleted file mode 100644 index af9ad7af3..000000000 --- a/app/cli/cmd/registered_integration_add_deptrack.go +++ /dev/null @@ -1,65 +0,0 @@ -// -// 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 ( - "fmt" - "syscall" - - "github.com/chainloop-dev/chainloop/app/cli/internal/action" - "github.com/spf13/cobra" - "golang.org/x/term" -) - -func newRegisteredIntegrationAddDepTrackCmd() *cobra.Command { - var instance, integrationDescription string - var allowAutoCreate bool - - cmd := &cobra.Command{ - Use: "dependency-track", - Aliases: []string{"deptrack"}, - Short: "Add Dependency-Track integration ", - Deprecated: "use `chainloop integration registered add` instead", - RunE: func(cmd *cobra.Command, args []string) error { - fmt.Print("Enter API Token: \n") - apiKey, err := term.ReadPassword(syscall.Stdin) - if err != nil { - return fmt.Errorf("retrieving token from stdin: %w", err) - } - - opts := map[string]any{ - "instanceURI": instance, - "apiKey": string(apiKey), - "allowAutoCreate": allowAutoCreate, - } - - res, err := action.NewRegisteredIntegrationAdd(actionOpts).Run("dependencytrack", integrationDescription, opts) - if err != nil { - return err - } - - return encodeOutput([]*action.RegisteredIntegrationItem{res}, registeredIntegrationListTableOutput) - }, - } - - cmd.Flags().StringVar(&integrationDescription, "description", "", "integration registration description") - cmd.Flags().StringVar(&instance, "instance", "", "dependency track instance URL") - cobra.CheckErr(cmd.MarkFlagRequired("instance")) - - cmd.Flags().BoolVar(&allowAutoCreate, "allow-project-auto-create", false, "Allow auto-creation of projects or require to always specify an existing one") - - return cmd -} diff --git a/app/cli/cmd/registered_integration_list.go b/app/cli/cmd/registered_integration_list.go index 4dc620b4a..0cc59646c 100644 --- a/app/cli/cmd/registered_integration_list.go +++ b/app/cli/cmd/registered_integration_list.go @@ -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 { diff --git a/app/cli/cmd/workflow.go b/app/cli/cmd/workflow.go index 3d75c0aa4..1ef8b590a 100644 --- a/app/cli/cmd/workflow.go +++ b/app/cli/cmd/workflow.go @@ -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 } diff --git a/app/cli/cmd/workflow_integration_attach_deptrack.go b/app/cli/cmd/workflow_integration_attach_deptrack.go deleted file mode 100644 index 70b49b296..000000000 --- a/app/cli/cmd/workflow_integration_attach_deptrack.go +++ /dev/null @@ -1,66 +0,0 @@ -// -// 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 ( - "errors" - - "github.com/chainloop-dev/chainloop/app/cli/internal/action" - "github.com/spf13/cobra" -) - -func newWorkflowIntegrationAttachDependencyTrackCmd() *cobra.Command { - var integrationID, workflowID, projectID, projectName string - - cmd := &cobra.Command{ - Use: "dependency-track", - Short: "Attach a Dependency-Track integration to this workflow", - Deprecated: "use `chainloop workflow integration attach --integration --workflow --options ...` instead", - PreRunE: func(cmd *cobra.Command, args []string) error { - if projectID == "" && projectName == "" { - return errors.New("either a Dependency-Track --project-id or the --project-name flag must be set") - } - return nil - }, - RunE: func(cmd *cobra.Command, args []string) error { - opts := make(map[string]any) - if projectID != "" { - opts["projectID"] = projectID - } else if projectName != "" { - opts["projectName"] = projectName - } - - res, err := action.NewWorkflowIntegrationAttach(actionOpts).Run(integrationID, workflowID, opts) - if err != nil { - return err - } - - return encodeOutput([]*action.IntegrationAttachmentItem{res}, integrationAttachmentListTableOutput) - }, - } - - cmd.Flags().StringVar(&integrationID, "integration", "", "ID of the integration already registered in this organization") - cobra.CheckErr(cmd.MarkFlagRequired("integration")) - - cmd.Flags().StringVar(&workflowID, "workflow", "", "ID of the workflow to attach this integration") - cobra.CheckErr(cmd.MarkFlagRequired("workflow")) - - cmd.Flags().StringVar(&projectID, "project-id", "", "Identifier of the Dependency-Track you want this integration to talk to") - cmd.Flags().StringVar(&projectName, "project-name", "", "Create a project with the provided name instead of using an existing one") - cmd.MarkFlagsMutuallyExclusive("project-id", "project-name") - - return cmd -} diff --git a/app/cli/internal/action/workflow_integration_attach.go b/app/cli/internal/action/attached_integration_add.go similarity index 80% rename from app/cli/internal/action/workflow_integration_attach.go rename to app/cli/internal/action/attached_integration_add.go index 8be6eda88..ec050c27e 100644 --- a/app/cli/internal/action/workflow_integration_attach.go +++ b/app/cli/internal/action/attached_integration_add.go @@ -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) diff --git a/app/cli/internal/action/workflow_integration_detach.go b/app/cli/internal/action/attached_integration_delete.go similarity index 79% rename from app/cli/internal/action/workflow_integration_detach.go rename to app/cli/internal/action/attached_integration_delete.go index 1e687539d..a8958556c 100644 --- a/app/cli/internal/action/workflow_integration_detach.go +++ b/app/cli/internal/action/attached_integration_delete.go @@ -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}) diff --git a/app/cli/internal/action/workflow_integration_list.go b/app/cli/internal/action/attached_integration_list.go similarity index 82% rename from app/cli/internal/action/workflow_integration_list.go rename to app/cli/internal/action/attached_integration_list.go index c0093d800..7bea24ab9 100644 --- a/app/cli/internal/action/workflow_integration_list.go +++ b/app/cli/internal/action/attached_integration_list.go @@ -23,13 +23,13 @@ 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{}) @@ -37,7 +37,7 @@ func (action *WorkflowIntegrationList) Run() ([]*IntegrationAttachmentItem, erro 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 { @@ -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, @@ -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"`