|
| 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 processors |
| 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 | + ProcessorID 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", |
| 49 | + Long: `This command requires Conduit to be already running since it will describe a processor registered |
| 50 | +by Conduit. You can list existing processors with the 'conduit processors list' command.`, |
| 51 | + Example: "conduit processors describe pipeline-processor\n" + |
| 52 | + "conduit processor desc connector-processor", |
| 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 ID") |
| 61 | + } |
| 62 | + |
| 63 | + if len(args) > 1 { |
| 64 | + return cerrors.Errorf("too many arguments") |
| 65 | + } |
| 66 | + |
| 67 | + c.args.ProcessorID = args[0] |
| 68 | + return nil |
| 69 | +} |
| 70 | + |
| 71 | +func (c *DescribeCommand) ExecuteWithClient(ctx context.Context, client *api.Client) error { |
| 72 | + resp, err := client.ProcessorServiceClient.GetProcessor(ctx, &apiv1.GetProcessorRequest{ |
| 73 | + Id: c.args.ProcessorID, |
| 74 | + }) |
| 75 | + if err != nil { |
| 76 | + return fmt.Errorf("failed to get processor: %w", err) |
| 77 | + } |
| 78 | + |
| 79 | + displayProcessor(resp.Processor) |
| 80 | + return nil |
| 81 | +} |
| 82 | + |
| 83 | +func displayProcessor(p *apiv1.Processor) { |
| 84 | + fmt.Printf("ID: %s\n", p.Id) |
| 85 | + fmt.Printf("Plugin: %s\n", p.Plugin) |
| 86 | + |
| 87 | + processorType := "Processor " |
| 88 | + switch p.Parent.Type.String() { |
| 89 | + case "TYPE_PIPELINE": |
| 90 | + processorType += "for Pipeline" |
| 91 | + case "TYPE_CONNECTOR": |
| 92 | + processorType += "for Connector" |
| 93 | + default: |
| 94 | + processorType += "associated to" |
| 95 | + } |
| 96 | + |
| 97 | + fmt.Printf("%s: %s\n", processorType, p.Parent.Id) |
| 98 | + |
| 99 | + if !internal.IsEmpty(p.Condition) { |
| 100 | + fmt.Printf("Condition: %s\n", p.Condition) |
| 101 | + } |
| 102 | + |
| 103 | + if len(p.Config.Settings) > 0 { |
| 104 | + fmt.Println("Config:") |
| 105 | + for name, value := range p.Config.Settings { |
| 106 | + fmt.Printf("%s%s: %s\n", internal.Indentation(1), name, value) |
| 107 | + } |
| 108 | + } |
| 109 | + fmt.Printf("Workers: %d\n", p.Config.Workers) |
| 110 | + |
| 111 | + fmt.Printf("Created At: %s\n", internal.PrintTime(p.CreatedAt)) |
| 112 | + fmt.Printf("Updated At: %s\n", internal.PrintTime(p.UpdatedAt)) |
| 113 | +} |
0 commit comments