Skip to content

Commit d8169e0

Browse files
authored
processor plugin desc (#2088)
* describe connector plugins command * move displayConfig to utils, needed by processor-plugin * describe processor plugin * address reviews
1 parent 643a331 commit d8169e0

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

Diff for: cmd/conduit/root/processorplugins/describe.go

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright © 2025 Meroxa, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package processorplugins
16+
17+
import (
18+
"context"
19+
"fmt"
20+
21+
"github.com/conduitio/conduit/cmd/conduit/api"
22+
"github.com/conduitio/conduit/cmd/conduit/cecdysis"
23+
"github.com/conduitio/conduit/cmd/conduit/internal"
24+
"github.com/conduitio/conduit/pkg/foundation/cerrors"
25+
apiv1 "github.com/conduitio/conduit/proto/api/v1"
26+
"github.com/conduitio/ecdysis"
27+
)
28+
29+
var (
30+
_ cecdysis.CommandWithExecuteWithClient = (*DescribeCommand)(nil)
31+
_ ecdysis.CommandWithAliases = (*DescribeCommand)(nil)
32+
_ ecdysis.CommandWithDocs = (*DescribeCommand)(nil)
33+
_ ecdysis.CommandWithArgs = (*DescribeCommand)(nil)
34+
)
35+
36+
type DescribeArgs struct {
37+
processorPlugin string
38+
}
39+
40+
type DescribeCommand struct {
41+
args DescribeArgs
42+
}
43+
44+
func (c *DescribeCommand) Usage() string { return "describe" }
45+
46+
func (c *DescribeCommand) Docs() ecdysis.Docs {
47+
return ecdysis.Docs{
48+
Short: "Describe an existing processor plugin.",
49+
Long: `This command requires Conduit to be already running since it will show a processor plugins that
50+
could be added to your pipelines.`,
51+
Example: "conduit processor-plugin describe builtin:[email protected]\n" +
52+
"conduit processor-plugin desc standalone:[email protected]",
53+
}
54+
}
55+
56+
func (c *DescribeCommand) Aliases() []string { return []string{"desc"} }
57+
58+
func (c *DescribeCommand) Args(args []string) error {
59+
if len(args) == 0 {
60+
return cerrors.Errorf("requires a processor plugin name")
61+
}
62+
63+
if len(args) > 1 {
64+
return cerrors.Errorf("too many arguments")
65+
}
66+
67+
c.args.processorPlugin = args[0]
68+
return nil
69+
}
70+
71+
func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Client) error {
72+
resp, err := client.ProcessorServiceClient.ListProcessorPlugins(ctx, &apiv1.ListProcessorPluginsRequest{
73+
Name: c.args.processorPlugin,
74+
})
75+
if err != nil {
76+
return fmt.Errorf("failed to get processor plugin: %w", err)
77+
}
78+
79+
if len(resp.Plugins) == 0 {
80+
return nil
81+
}
82+
83+
displayConnectorPluginsDescription(resp.Plugins[0])
84+
85+
return nil
86+
}
87+
88+
func displayConnectorPluginsDescription(p *apiv1.ProcessorPluginSpecifications) {
89+
if !internal.IsEmpty(p.Name) {
90+
fmt.Printf("Name: %s\n", p.Name)
91+
}
92+
if !internal.IsEmpty(p.Summary) {
93+
fmt.Printf("Summary: %s\n", p.Summary)
94+
}
95+
if !internal.IsEmpty(p.Description) {
96+
fmt.Printf("Description: %s\n", p.Description)
97+
}
98+
if !internal.IsEmpty(p.Author) {
99+
fmt.Printf("Author: %s\n", p.Author)
100+
}
101+
if !internal.IsEmpty(p.Version) {
102+
fmt.Printf("Version: %s\n", p.Version)
103+
}
104+
105+
if len(p.Parameters) > 0 {
106+
fmt.Println("\nParameters:")
107+
internal.DisplayConfigParams(p.Parameters)
108+
}
109+
}

Diff for: cmd/conduit/root/processorplugins/describe_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright © 2025 Meroxa, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package processorplugins
16+
17+
import (
18+
"testing"
19+
20+
"github.com/matryer/is"
21+
)
22+
23+
func TestDescribeExecutionNoArgs(t *testing.T) {
24+
is := is.New(t)
25+
26+
c := DescribeCommand{}
27+
err := c.Args([]string{})
28+
29+
expected := "requires a processor plugin name"
30+
31+
is.True(err != nil)
32+
is.Equal(err.Error(), expected)
33+
}
34+
35+
func TestDescribeExecutionMultipleArgs(t *testing.T) {
36+
is := is.New(t)
37+
38+
c := DescribeCommand{}
39+
err := c.Args([]string{"foo", "bar"})
40+
41+
expected := "too many arguments"
42+
43+
is.True(err != nil)
44+
is.Equal(err.Error(), expected)
45+
}
46+
47+
func TestDescribeExecutionCorrectArgs(t *testing.T) {
48+
is := is.New(t)
49+
processorPluginID := "processor-plugin-id"
50+
51+
c := DescribeCommand{}
52+
err := c.Args([]string{processorPluginID})
53+
54+
is.NoErr(err)
55+
is.Equal(c.args.processorPlugin, processorPluginID)
56+
}

Diff for: cmd/conduit/root/processorplugins/processor_plugins.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (c *ProcessorPluginsCommand) Aliases() []string { return []string{"processo
3131
func (c *ProcessorPluginsCommand) SubCommands() []ecdysis.Command {
3232
return []ecdysis.Command{
3333
&ListCommand{},
34+
&DescribeCommand{},
3435
}
3536
}
3637

0 commit comments

Comments
 (0)