Skip to content

Commit

Permalink
Merge branch 'main' into haris/cli-pipelines-describe
Browse files Browse the repository at this point in the history
  • Loading branch information
hariso committed Jan 17, 2025
2 parents 4cf9456 + c210fe4 commit 4d752d3
Show file tree
Hide file tree
Showing 13 changed files with 544 additions and 4 deletions.
2 changes: 2 additions & 0 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.ProcessorServiceClient
apiv1.ConnectorServiceClient
healthgrpc.HealthClient
}
Expand All @@ -43,6 +44,7 @@ func NewClient(ctx context.Context, address string) (*Client, error) {
client := &Client{
conn: conn,
PipelineServiceClient: apiv1.NewPipelineServiceClient(conn),
ProcessorServiceClient: apiv1.NewProcessorServiceClient(conn),
ConnectorServiceClient: apiv1.NewConnectorServiceClient(conn),
HealthClient: healthgrpc.NewHealthClient(conn),
}
Expand Down
43 changes: 43 additions & 0 deletions cmd/conduit/root/connectorplugins/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 connectorplugins

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",
}
}
98 changes: 98 additions & 0 deletions cmd/conduit/root/connectorplugins/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 connectorplugins

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 Connector Plugins",
Long: `This command requires Conduit to be already running since it will list all connector plugins that
could be added to your pipelines.`,
Example: "conduit connector-plugins list\nconduit connector-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.ConnectorServiceClient.ListConnectorPlugins(ctx, &apiv1.ListConnectorPluginsRequest{
Name: regex,
})
if err != nil {
return fmt.Errorf("failed to list connector plugins: %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"},
},
}

for _, p := range connectorPlugins {
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())
}
56 changes: 56 additions & 0 deletions cmd/conduit/root/connectorplugins/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 connectorplugins

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)
}
}
43 changes: 43 additions & 0 deletions cmd/conduit/root/connectors/connectors.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 connectors

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

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

type ConnectorsCommand struct{}

func (c *ConnectorsCommand) Aliases() []string { return []string{"connector"} }

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

func (c *ConnectorsCommand) Usage() string { return "connectors" }

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

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 {
PipelineID string `long:"pipeline-id" usage:"filter connectors by pipeline ID"`
}

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 connectors",
Long: `This command requires Conduit to be already running since it will list all connectors registered
by Conduit.`,
Example: "conduit connectors list\nconduit connectors 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 {
resp, err := client.ConnectorServiceClient.ListConnectors(ctx, &apiv1.ListConnectorsRequest{
PipelineId: c.flags.PipelineID,
})
if err != nil {
return fmt.Errorf("failed to list connectors: %w", err)
}

displayConnectors(resp.Connectors)

return nil
}

func displayConnectors(connectors []*apiv1.Connector) {
if len(connectors) == 0 {
return
}

table := simpletable.New()

table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "ID"},
{Align: simpletable.AlignCenter, Text: "PLUGIN"},
{Align: simpletable.AlignCenter, Text: "PIPELINE_ID"},
{Align: simpletable.AlignCenter, Text: "CREATED"},
{Align: simpletable.AlignCenter, Text: "LAST_UPDATED"},
},
}

for _, p := range connectors {
r := []*simpletable.Cell{
{Align: simpletable.AlignLeft, Text: p.Id},
{Align: simpletable.AlignLeft, Text: p.Plugin},
{Align: simpletable.AlignLeft, Text: p.PipelineId},
{Align: simpletable.AlignLeft, Text: p.CreatedAt.AsTime().String()},
{Align: simpletable.AlignLeft, Text: p.UpdatedAt.AsTime().String()},
}

table.Body.Cells = append(table.Body.Cells, r)
}
table.SetStyle(simpletable.StyleCompact)
fmt.Println(table.String())
}
Loading

0 comments on commit 4d752d3

Please sign in to comment.