Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add processor plugins ls #2081

Merged
merged 2 commits into from
Jan 17, 2025
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
4 changes: 2 additions & 2 deletions cmd/conduit/root/connectorplugins/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
98 changes: 98 additions & 0 deletions cmd/conduit/root/processorplugins/list.go
Original file line number Diff line number Diff line change
@@ -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
}
raulb marked this conversation as resolved.
Show resolved Hide resolved

table := simpletable.New()

table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "NAME"},
{Align: simpletable.AlignCenter, Text: "SUMMARY"},
},
}

for _, p := range processorPlugins {
r := []*simpletable.Cell{
{Align: simpletable.AlignLeft, Text: p.Name},
{Align: simpletable.AlignLeft, Text: p.Summary},
}

table.Body.Cells = append(table.Body.Cells, r)
}
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}
56 changes: 56 additions & 0 deletions cmd/conduit/root/processorplugins/list_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
43 changes: 43 additions & 0 deletions cmd/conduit/root/processorplugins/processor_plugins.go
Original file line number Diff line number Diff line change
@@ -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",
}
}
2 changes: 1 addition & 1 deletion cmd/conduit/root/processors/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
8 changes: 5 additions & 3 deletions cmd/conduit/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
}
Loading