-
Notifications
You must be signed in to change notification settings - Fork 26
[APIE-989] Initial generated code for Symphony control plane APIs (Don't Merge Yet) #3331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bb7852b
26dcef0
7f1413c
216fbe4
efe6a1e
0a0738a
b4faf26
7fa1323
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| a0515ddfd100747d6fe4bcdc5d335c28680ef6728b1465c4fa98f0224da2b270 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package rtce | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/config" | ||
| ) | ||
|
|
||
| func New(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "rtce", | ||
| Short: "Manage Real Time Context Engine.", | ||
| } | ||
|
|
||
| cmd.AddCommand( | ||
| newRegionCommand(cfg, prerunner), | ||
| newRtceTopicCommand(cfg, prerunner), | ||
| // cli-tfgen:cli-subcommands | ||
| ) | ||
|
|
||
| return cmd | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package rtce | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/config" | ||
| ) | ||
|
|
||
| type regionCommand struct { | ||
| *pcmd.AuthenticatedCLICommand | ||
| } | ||
|
|
||
| type regionOut struct { | ||
| ID string `human:"ID" serialized:"id"` | ||
| Cloud string `human:"Cloud" serialized:"cloud"` | ||
| Region string `human:"Region" serialized:"region"` | ||
| DisplayName string `human:"Display Name" serialized:"display_name"` | ||
| } | ||
|
|
||
| func newRegionCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command { //nolint:unparam | ||
| cmd := &cobra.Command{ | ||
| Use: "region", | ||
| Short: "Manage RTCE regions.", | ||
| Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin}, | ||
| } | ||
|
|
||
| c := ®ionCommand{ | ||
| AuthenticatedCLICommand: pcmd.NewAuthenticatedCLICommand(cmd, prerunner), | ||
| } | ||
|
|
||
| cmd.AddCommand( | ||
| c.newListCommand(), | ||
| ) | ||
|
|
||
| return cmd | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package rtce | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *regionCommand) newListCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List RTCE regions.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.list, | ||
| } | ||
|
|
||
| // Required flags | ||
|
|
||
| // Optional flags | ||
| pcmd.AddCloudAwsFlag(cmd) | ||
| cmd.Flags().String("region", "", "Filter the results by exact match for region.") | ||
|
|
||
| pcmd.AddContextFlag(cmd, c.CLICommand) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *regionCommand) list(cmd *cobra.Command, _ []string) error { | ||
| cloud, err := cmd.Flags().GetString("cloud") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| cloud = strings.ToUpper(cloud) | ||
|
|
||
| region, err := cmd.Flags().GetString("region") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| regions, err := c.V2Client.ListRtceRegions(cloud, region) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| list := output.NewList(cmd) | ||
| for _, region := range regions { | ||
| out := ®ionOut{ | ||
| ID: region.GetId(), | ||
| Cloud: region.GetCloud(), | ||
| Region: region.GetRegion(), | ||
| DisplayName: region.GetDisplayName(), | ||
| } | ||
| list.Add(out) | ||
| } | ||
| return list.Print() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package rtce | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| rtcev1 "github.com/confluentinc/ccloud-sdk-go-v2/rtce/v1" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/config" | ||
| "github.com/confluentinc/cli/v4/pkg/kafka" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| type rtceTopicCommand struct { | ||
| *pcmd.AuthenticatedCLICommand | ||
| } | ||
|
|
||
| type rtceTopicOut struct { | ||
| TopicName string `human:"Topic Name" serialized:"topic_name"` | ||
| Cloud string `human:"Cloud" serialized:"cloud"` | ||
| Description string `human:"Description" serialized:"description"` | ||
| Environment string `human:"Environment" serialized:"environment"` | ||
| KafkaCluster string `human:"Kafka Cluster" serialized:"kafka_cluster"` | ||
| Region string `human:"Region" serialized:"region"` | ||
| ErrorMessage string `human:"Error Message" serialized:"error_message"` | ||
| Phase string `human:"Phase" serialized:"phase"` | ||
| } | ||
|
|
||
| func newRtceTopicCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command { //nolint:unparam | ||
| cmd := &cobra.Command{ | ||
| Use: "rtce-topic", | ||
| Short: "Manage RTCE topics.", | ||
| Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin}, | ||
| } | ||
|
|
||
| c := &rtceTopicCommand{ | ||
| AuthenticatedCLICommand: pcmd.NewAuthenticatedCLICommand(cmd, prerunner), | ||
| } | ||
|
|
||
| cmd.AddCommand( | ||
| c.newCreateCommand(), | ||
| c.newDeleteCommand(), | ||
| c.newDescribeCommand(), | ||
| c.newListCommand(), | ||
| c.newUpdateCommand(), | ||
| ) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func printRtceTopic(cmd *cobra.Command, rtceTopic rtcev1.RtceV1RtceTopic) error { | ||
| table := output.NewTable(cmd) | ||
| out := &rtceTopicOut{ | ||
| TopicName: rtceTopic.Spec.GetTopicName(), | ||
| Cloud: rtceTopic.Spec.GetCloud(), | ||
| Description: rtceTopic.Spec.GetDescription(), | ||
| Environment: rtceTopic.Spec.Environment.GetId(), | ||
| KafkaCluster: rtceTopic.Spec.KafkaCluster.GetId(), | ||
| Region: rtceTopic.Spec.GetRegion(), | ||
| ErrorMessage: rtceTopic.Status.GetErrorMessage(), | ||
| Phase: rtceTopic.Status.GetPhase(), | ||
| } | ||
| table.Add(out) | ||
| return table.Print() | ||
| } | ||
|
|
||
| func (c *rtceTopicCommand) validArgs(cmd *cobra.Command, args []string) []string { | ||
| if len(args) > 0 { | ||
| return nil | ||
| } | ||
|
|
||
| return c.validArgsMultiple(cmd, args) | ||
| } | ||
|
|
||
| func (c *rtceTopicCommand) validArgsMultiple(cmd *cobra.Command, args []string) []string { | ||
| if err := c.PersistentPreRunE(cmd, args); err != nil { | ||
|
Check warning on line 76 in internal/rtce/command_rtce_topic.go
|
||
| return nil | ||
| } | ||
|
|
||
| return c.autocompleteRtceTopics() | ||
| } | ||
|
|
||
| func (c *rtceTopicCommand) autocompleteRtceTopics() []string { | ||
| environmentId, err := c.Context.EnvironmentId() | ||
| if err != nil { | ||
| return nil | ||
| } | ||
| kafkaClusterConfig, err := kafka.GetClusterForCommand(c.V2Client, c.Context) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
| kafkaClusterId := kafkaClusterConfig.GetId() | ||
| rtceTopics, err := c.V2Client.ListRtceTopics("", "", environmentId, kafkaClusterId) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
|
channingdong marked this conversation as resolved.
|
||
|
|
||
| suggestions := make([]string, len(rtceTopics)) | ||
| for i, rtceTopic := range rtceTopics { | ||
| suggestions[i] = rtceTopic.Spec.GetTopicName() | ||
| } | ||
| return suggestions | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package rtce | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| rtcev1 "github.com/confluentinc/ccloud-sdk-go-v2/rtce/v1" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/errors" | ||
| "github.com/confluentinc/cli/v4/pkg/kafka" | ||
| ) | ||
|
|
||
| func (c *rtceTopicCommand) newCreateCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "create", | ||
| Short: "Create an RTCE topic.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.create, | ||
| } | ||
|
channingdong marked this conversation as resolved.
|
||
|
|
||
| // Required flags | ||
| pcmd.AddCloudAwsFlag(cmd) | ||
| cmd.Flags().String("description", "", "A model-readable description of the RTCE topic.") | ||
| cmd.Flags().String("region", "", "The cloud region where the RTCE topic is deployed.") | ||
| cmd.Flags().String("topic-name", "", "The Kafka topic name containing the data for the RTCE topic.") | ||
|
Check failure on line 27 in internal/rtce/command_rtce_topic_create.go
|
||
| cobra.CheckErr(cmd.MarkFlagRequired("cloud")) | ||
| cobra.CheckErr(cmd.MarkFlagRequired("description")) | ||
| cobra.CheckErr(cmd.MarkFlagRequired("region")) | ||
| cobra.CheckErr(cmd.MarkFlagRequired("topic-name")) | ||
|
|
||
| // Optional flags | ||
| pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand) | ||
| pcmd.AddClusterFlag(cmd, c.AuthenticatedCLICommand) | ||
|
|
||
| pcmd.AddContextFlag(cmd, c.CLICommand) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *rtceTopicCommand) create(cmd *cobra.Command, args []string) error { | ||
| spec := rtcev1.RtceV1RtceTopicSpec{} | ||
| createReq := rtcev1.RtceV1RtceTopic{} | ||
|
|
||
| cloud, err := cmd.Flags().GetString("cloud") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| cloud = strings.ToUpper(cloud) | ||
| spec.Cloud = rtcev1.PtrString(cloud) | ||
|
|
||
| description, err := cmd.Flags().GetString("description") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| spec.Description = rtcev1.PtrString(description) | ||
|
|
||
| environmentId, err := c.Context.EnvironmentId() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| spec.Environment = &rtcev1.EnvScopedObjectReference{Id: environmentId} | ||
|
|
||
| kafkaClusterConfig, err := kafka.GetClusterForCommand(c.V2Client, c.Context) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| kafkaClusterId := kafkaClusterConfig.GetId() | ||
| spec.KafkaCluster = &rtcev1.EnvScopedObjectReference{Id: kafkaClusterId} | ||
|
|
||
| region, err := cmd.Flags().GetString("region") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| spec.Region = rtcev1.PtrString(region) | ||
|
|
||
| topicName, err := cmd.Flags().GetString("topic-name") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| spec.TopicName = rtcev1.PtrString(topicName) | ||
|
|
||
| createReq.Spec = &spec | ||
| rtceTopic, httpResp, err := c.V2Client.CreateRtceTopic(createReq) | ||
| if err != nil { | ||
| return errors.CatchCCloudV2Error(err, httpResp) | ||
| } | ||
|
|
||
| return printRtceTopic(cmd, rtceTopic) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the RTCE region output table looks good? We can always add more stuff in the future if we want, but adding more fields now and reducing later will be hard, so we recommend starting with these.