-
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) #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
Open
Channing Dong (channingdong)
wants to merge
5
commits into
main
Choose a base branch
from
APIE-989
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d154b2f
Initial generated code for Symphony control plane APIs
channingdong d5db7eb
Address the comments after improving the CLI generator, add the check…
channingdong 921f14b
Merge branch 'main' into APIE-989
channingdong 5d0c769
Cosmetic improvements
channingdong cf6cc71
Update test cases, handlers and SDK path in go.mod
channingdong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 9fbeaf01266df55f34074a848c64c5bdbae9fdbb89295add419c4655c55264f3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| 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, | ||
| } | ||
| 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() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| 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 a RTCE topic.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.create, | ||
| } | ||
|
channingdong marked this conversation as resolved.
|
||
| pcmd.AddCloudAwsFlag(cmd) | ||
| cmd.Flags().String("description", "", "A model-readable description of the RTCE topic.") | ||
| pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand) | ||
| pcmd.AddClusterFlag(cmd, c.AuthenticatedCLICommand) | ||
| 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.") | ||
|
|
||
| pcmd.AddContextFlag(cmd, c.CLICommand) | ||
| pcmd.AddOutputFlag(cmd) | ||
| cobra.CheckErr(cmd.MarkFlagRequired("cloud")) | ||
| cobra.CheckErr(cmd.MarkFlagRequired("description")) | ||
| cobra.CheckErr(cmd.MarkFlagRequired("region")) | ||
| cobra.CheckErr(cmd.MarkFlagRequired("topic-name")) | ||
|
|
||
| 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) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.