|
| 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 | +} |
0 commit comments