From b854a213e06dee2c5b36cd0e842cc47028723fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Barroso?= Date: Fri, 17 Jan 2025 11:14:26 +0100 Subject: [PATCH 1/2] feat(cli): add processor plugins ls --- cmd/conduit/root/processorplugins/list.go | 98 +++++++++++++++++++ .../root/processorplugins/list_test.go | 56 +++++++++++ .../processorplugins/processor_plugins.go | 43 ++++++++ cmd/conduit/root/processors/processors.go | 2 +- cmd/conduit/root/root.go | 8 +- 5 files changed, 203 insertions(+), 4 deletions(-) create mode 100644 cmd/conduit/root/processorplugins/list.go create mode 100644 cmd/conduit/root/processorplugins/list_test.go create mode 100644 cmd/conduit/root/processorplugins/processor_plugins.go diff --git a/cmd/conduit/root/processorplugins/list.go b/cmd/conduit/root/processorplugins/list.go new file mode 100644 index 000000000..10f335ffe --- /dev/null +++ b/cmd/conduit/root/processorplugins/list.go @@ -0,0 +1,98 @@ +// Copyright © 2025 Meroxa, Inc. +// +// 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 processorplugins + +import ( + "context" + "fmt" + + "github.com/alexeyco/simpletable" + "github.com/conduitio/conduit/cmd/conduit/api" + "github.com/conduitio/conduit/cmd/conduit/cecdysis" + apiv1 "github.com/conduitio/conduit/proto/api/v1" + "github.com/conduitio/ecdysis" +) + +var ( + _ ecdysis.CommandWithAliases = (*ListCommand)(nil) + _ ecdysis.CommandWithDocs = (*ListCommand)(nil) + _ ecdysis.CommandWithFlags = (*ListCommand)(nil) + _ cecdysis.CommandWithExecuteWithClient = (*ListCommand)(nil) +) + +type ListFlags struct { + Name string `long:"name" usage:"name to filter processor plugins by"` +} + +type ListCommand struct { + flags ListFlags +} + +func (c *ListCommand) Flags() []ecdysis.Flag { + return ecdysis.BuildFlags(&c.flags) +} + +func (c *ListCommand) Docs() ecdysis.Docs { + return ecdysis.Docs{ + Short: "List existing Conduit Processor Plugins", + Long: `This command requires Conduit to be already running since it will list all processor plugins that +could be added to your pipelines.`, + Example: "conduit processor-plugins list\nconduit processor-plugins ls", + } +} + +func (c *ListCommand) Aliases() []string { return []string{"ls"} } + +func (c *ListCommand) Usage() string { return "list" } + +func (c *ListCommand) ExecuteWithClient(ctx context.Context, client *api.Client) error { + regex := fmt.Sprintf(".*%s.*", c.flags.Name) + resp, err := client.ProcessorServiceClient.ListProcessorPlugins(ctx, &apiv1.ListProcessorPluginsRequest{ + Name: regex, + }) + if err != nil { + return fmt.Errorf("failed to list processor plugins: %w", err) + } + + displayProcessorPlugins(resp.Plugins) + + return nil +} + +func displayProcessorPlugins(processorPlugins []*apiv1.ProcessorPluginSpecifications) { + if len(processorPlugins) == 0 { + return + } + + table := simpletable.New() + + table.Header = &simpletable.Header{ + Cells: []*simpletable.Cell{ + {Align: simpletable.AlignCenter, Text: "NAME"}, + {Align: simpletable.AlignCenter, Text: "DESCRIPTION"}, + }, + } + + for _, p := range processorPlugins { + r := []*simpletable.Cell{ + {Align: simpletable.AlignLeft, Text: p.Name}, + {Align: simpletable.AlignLeft, Text: p.Description}, + } + + table.Body.Cells = append(table.Body.Cells, r) + } + table.SetStyle(simpletable.StyleCompact) + fmt.Println(table.String()) +} diff --git a/cmd/conduit/root/processorplugins/list_test.go b/cmd/conduit/root/processorplugins/list_test.go new file mode 100644 index 000000000..8e95156f2 --- /dev/null +++ b/cmd/conduit/root/processorplugins/list_test.go @@ -0,0 +1,56 @@ +// Copyright © 2024 Meroxa, Inc. +// +// 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 processorplugins + +import ( + "testing" + + "github.com/conduitio/ecdysis" + "github.com/matryer/is" + "github.com/spf13/pflag" +) + +func TestListCommandFlags(t *testing.T) { + is := is.New(t) + + expectedFlags := []struct { + longName string + shortName string + usage string + persistent bool + }{ + {longName: "name", usage: "name to filter processor plugins by"}, + } + + e := ecdysis.New() + c := e.MustBuildCobraCommand(&ListCommand{}) + + persistentFlags := c.PersistentFlags() + cmdFlags := c.Flags() + + for _, f := range expectedFlags { + var cf *pflag.Flag + + if f.persistent { + cf = persistentFlags.Lookup(f.longName) + } else { + cf = cmdFlags.Lookup(f.longName) + } + is.True(cf != nil) + is.Equal(f.longName, cf.Name) + is.Equal(f.shortName, cf.Shorthand) + is.Equal(cf.Usage, f.usage) + } +} diff --git a/cmd/conduit/root/processorplugins/processor_plugins.go b/cmd/conduit/root/processorplugins/processor_plugins.go new file mode 100644 index 000000000..09b38fefc --- /dev/null +++ b/cmd/conduit/root/processorplugins/processor_plugins.go @@ -0,0 +1,43 @@ +// Copyright © 2025 Meroxa, Inc. +// +// 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 processorplugins + +import ( + "github.com/conduitio/ecdysis" +) + +var ( + _ ecdysis.CommandWithDocs = (*ProcessorPluginsCommand)(nil) + _ ecdysis.CommandWithSubCommands = (*ProcessorPluginsCommand)(nil) + _ ecdysis.CommandWithAliases = (*ProcessorPluginsCommand)(nil) +) + +type ProcessorPluginsCommand struct{} + +func (c *ProcessorPluginsCommand) Aliases() []string { return []string{"processor-plugin"} } + +func (c *ProcessorPluginsCommand) SubCommands() []ecdysis.Command { + return []ecdysis.Command{ + &ListCommand{}, + } +} + +func (c *ProcessorPluginsCommand) Usage() string { return "processor-plugins" } + +func (c *ProcessorPluginsCommand) Docs() ecdysis.Docs { + return ecdysis.Docs{ + Short: "Manage Processor Plugins", + } +} diff --git a/cmd/conduit/root/processors/processors.go b/cmd/conduit/root/processors/processors.go index 59187247c..caacdaa6e 100644 --- a/cmd/conduit/root/processors/processors.go +++ b/cmd/conduit/root/processors/processors.go @@ -38,6 +38,6 @@ func (c *ProcessorsCommand) Usage() string { return "processors" } func (c *ProcessorsCommand) Docs() ecdysis.Docs { return ecdysis.Docs{ - Short: "Manage processors", + Short: "Manage Processors", } } diff --git a/cmd/conduit/root/root.go b/cmd/conduit/root/root.go index cf40bc000..b1869b891 100644 --- a/cmd/conduit/root/root.go +++ b/cmd/conduit/root/root.go @@ -24,6 +24,7 @@ import ( "github.com/conduitio/conduit/cmd/conduit/root/connectors" "github.com/conduitio/conduit/cmd/conduit/root/initialize" "github.com/conduitio/conduit/cmd/conduit/root/pipelines" + "github.com/conduitio/conduit/cmd/conduit/root/processorplugins" "github.com/conduitio/conduit/cmd/conduit/root/processors" "github.com/conduitio/conduit/cmd/conduit/root/run" "github.com/conduitio/conduit/cmd/conduit/root/version" @@ -81,12 +82,13 @@ func (c *RootCommand) SubCommands() []ecdysis.Command { return []ecdysis.Command{ &config.ConfigCommand{RunCmd: runCmd}, + &connectors.ConnectorsCommand{}, + &connectorplugins.ConnectorPluginsCommand{}, &initialize.InitCommand{Cfg: &runCmd.Cfg}, - &version.VersionCommand{}, &pipelines.PipelinesCommand{}, &processors.ProcessorsCommand{}, - &connectors.ConnectorsCommand{}, - &connectorplugins.ConnectorPluginsCommand{}, + &processorplugins.ProcessorPluginsCommand{}, + &version.VersionCommand{}, runCmd, } } From 28f99cdba1da2328b9a372d2c54bcf67b8ecaf53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Barroso?= Date: Fri, 17 Jan 2025 13:39:41 +0100 Subject: [PATCH 2/2] use summary on ls --- cmd/conduit/root/connectorplugins/list.go | 4 ++-- cmd/conduit/root/processorplugins/list.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/conduit/root/connectorplugins/list.go b/cmd/conduit/root/connectorplugins/list.go index 01f980d1e..cbb4afdc7 100644 --- a/cmd/conduit/root/connectorplugins/list.go +++ b/cmd/conduit/root/connectorplugins/list.go @@ -81,14 +81,14 @@ func displayConnectorPlugins(connectorPlugins []*apiv1.ConnectorPluginSpecificat table.Header = &simpletable.Header{ Cells: []*simpletable.Cell{ {Align: simpletable.AlignCenter, Text: "NAME"}, - {Align: simpletable.AlignCenter, Text: "DESCRIPTION"}, + {Align: simpletable.AlignCenter, Text: "SUMMARY"}, }, } for _, p := range connectorPlugins { r := []*simpletable.Cell{ {Align: simpletable.AlignLeft, Text: p.Name}, - {Align: simpletable.AlignLeft, Text: p.Description}, + {Align: simpletable.AlignLeft, Text: p.Summary}, } table.Body.Cells = append(table.Body.Cells, r) diff --git a/cmd/conduit/root/processorplugins/list.go b/cmd/conduit/root/processorplugins/list.go index 10f335ffe..8aee70f51 100644 --- a/cmd/conduit/root/processorplugins/list.go +++ b/cmd/conduit/root/processorplugins/list.go @@ -81,14 +81,14 @@ func displayProcessorPlugins(processorPlugins []*apiv1.ProcessorPluginSpecificat table.Header = &simpletable.Header{ Cells: []*simpletable.Cell{ {Align: simpletable.AlignCenter, Text: "NAME"}, - {Align: simpletable.AlignCenter, Text: "DESCRIPTION"}, + {Align: simpletable.AlignCenter, Text: "SUMMARY"}, }, } for _, p := range processorPlugins { r := []*simpletable.Cell{ {Align: simpletable.AlignLeft, Text: p.Name}, - {Align: simpletable.AlignLeft, Text: p.Description}, + {Align: simpletable.AlignLeft, Text: p.Summary}, } table.Body.Cells = append(table.Body.Cells, r)