Skip to content

Commit

Permalink
feat(CLI): add connector plugins ls
Browse files Browse the repository at this point in the history
  • Loading branch information
raulb committed Jan 16, 2025
1 parent 2515cf5 commit 18357d5
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/conduit/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
type Client struct {
conn *grpc.ClientConn
apiv1.PipelineServiceClient
apiv1.ConnectorServiceClient
healthgrpc.HealthClient
}

Expand All @@ -40,9 +41,10 @@ func NewClient(ctx context.Context, address string) (*Client, error) {
}

client := &Client{
conn: conn,
PipelineServiceClient: apiv1.NewPipelineServiceClient(conn),
HealthClient: healthgrpc.NewHealthClient(conn),
conn: conn,
PipelineServiceClient: apiv1.NewPipelineServiceClient(conn),
ConnectorServiceClient: apiv1.NewConnectorServiceClient(conn),
HealthClient: healthgrpc.NewHealthClient(conn),
}

if err := client.CheckHealth(ctx, address); err != nil {
Expand Down
43 changes: 43 additions & 0 deletions cmd/conduit/root/connector_plugins/connector-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 connector_plugins

Check failure on line 15 in cmd/conduit/root/connector_plugins/connector-plugins.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1003: should not use underscores in package names (stylecheck)

import (
"github.com/conduitio/ecdysis"
)

var (
_ ecdysis.CommandWithDocs = (*ConnectorPluginsCommand)(nil)
_ ecdysis.CommandWithSubCommands = (*ConnectorPluginsCommand)(nil)
_ ecdysis.CommandWithAliases = (*ConnectorPluginsCommand)(nil)
)

type ConnectorPluginsCommand struct{}

func (c *ConnectorPluginsCommand) Aliases() []string { return []string{"connector-plugin"} }

func (c *ConnectorPluginsCommand) SubCommands() []ecdysis.Command {
return []ecdysis.Command{
&ListCommand{},
}
}

func (c *ConnectorPluginsCommand) Usage() string { return "connector-plugins" }

func (c *ConnectorPluginsCommand) Docs() ecdysis.Docs {
return ecdysis.Docs{
Short: "Manage Connector Plugins",
}
}
102 changes: 102 additions & 0 deletions cmd/conduit/root/connector_plugins/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 connector_plugins

Check failure on line 15 in cmd/conduit/root/connector_plugins/list.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1003: should not use underscores in package names (stylecheck)

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 (
_ cecdysis.CommandWithExecuteWithClient = (*ListCommand)(nil)
_ ecdysis.CommandWithAliases = (*ListCommand)(nil)
_ ecdysis.CommandWithDocs = (*ListCommand)(nil)
_ ecdysis.CommandWithFlags = (*ListCommand)(nil)
)

type ListFlags struct {
Name string `long:"name" usage:"name to filter connector 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 pipelines",
Long: `This command requires Conduit to be already running since it will list all pipelines registered
by Conduit. This will depend on the configured pipelines directory, which by default is /pipelines; however, it could
be configured via --pipelines.path at the time of running Conduit.`,
Example: "conduit pipelines 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.ConnectorServiceClient.ListConnectorPlugins(ctx, &apiv1.ListConnectorPluginsRequest{
Name: regex,
})

Check failure on line 66 in cmd/conduit/root/connector_plugins/list.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)
if err != nil {
return fmt.Errorf("failed to list pipelines: %w", err)
}

displayConnectorPlugins(resp.Plugins)

return nil
}

func displayConnectorPlugins(connectorPlugins []*apiv1.ConnectorPluginSpecifications) {
if len(connectorPlugins) == 0 {
return
}

table := simpletable.New()

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

for _, p := range connectorPlugins {
r := []*simpletable.Cell{
{Align: simpletable.AlignRight, Text: p.Name},
{Align: simpletable.AlignLeft, Text: p.Description},
{Align: simpletable.AlignLeft, Text: p.Version},
}

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/connector_plugins/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 connector_plugins

Check failure on line 15 in cmd/conduit/root/connector_plugins/list_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1003: should not use underscores in package names (stylecheck)

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 connector 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)
}
}
2 changes: 2 additions & 0 deletions cmd/conduit/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"

"github.com/conduitio/conduit/cmd/conduit/root/config"
"github.com/conduitio/conduit/cmd/conduit/root/connector_plugins"
"github.com/conduitio/conduit/cmd/conduit/root/initialize"
"github.com/conduitio/conduit/cmd/conduit/root/pipelines"
"github.com/conduitio/conduit/cmd/conduit/root/run"
Expand Down Expand Up @@ -81,6 +82,7 @@ func (c *RootCommand) SubCommands() []ecdysis.Command {
&initialize.InitCommand{Cfg: &runCmd.Cfg},
&version.VersionCommand{},
&pipelines.PipelinesCommand{},
&connector_plugins.ConnectorPluginsCommand{},
runCmd,
}
}

0 comments on commit 18357d5

Please sign in to comment.