Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cli-generation-checksum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9fbeaf01266df55f34074a848c64c5bdbae9fdbb89295add419c4655c55264f3
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ require (
github.com/confluentinc/ccloud-sdk-go-v2/networking-privatelink v0.3.0
github.com/confluentinc/ccloud-sdk-go-v2/org v0.9.0
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.2.0
github.com/confluentinc/ccloud-sdk-go-v2/rtce v0.1.0
github.com/confluentinc/ccloud-sdk-go-v2/service-quota v0.2.0
github.com/confluentinc/ccloud-sdk-go-v2/srcm v0.7.3
github.com/confluentinc/ccloud-sdk-go-v2/sso v0.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ github.com/confluentinc/ccloud-sdk-go-v2/org v0.9.0 h1:FtaqHX0kBTK7fCQK+9SJcOso+
github.com/confluentinc/ccloud-sdk-go-v2/org v0.9.0/go.mod h1:X0uaTYPp+mr19W1R/Z1LuB1ePZJZrH7kxnQckDx6zoc=
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.2.0 h1:UN2a+aqYhk95ro+wVLkeB/8W7n+UV2KsE3jNFbbDCSw=
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.2.0/go.mod h1:TzompS9F0G6awN5xMC+nguNG8ULElN5UqX2XOBOIPuM=
github.com/confluentinc/ccloud-sdk-go-v2/rtce v0.1.0 h1:OBa2vm09bOG1oojOP1vNj8V7+M2AfUkYP1sRQ+xlRm4=
github.com/confluentinc/ccloud-sdk-go-v2/rtce v0.1.0/go.mod h1:DNLAZ1R59mLfTM66zypmTIz0R2GouLJfPHeyR/id1gw=
github.com/confluentinc/ccloud-sdk-go-v2/service-quota v0.2.0 h1:xVSmwdycExze1E2Jta99CaFuMOlL6k6KExOOSY1hSFg=
github.com/confluentinc/ccloud-sdk-go-v2/service-quota v0.2.0/go.mod h1:zZWZoGWJuO0Qm4lO6H2KlXMx4OoB/yhD8y6J1ZB/97Q=
github.com/confluentinc/ccloud-sdk-go-v2/srcm v0.7.3 h1:ozdDSJHruQIgtxS5hwz8Rp8pUSX0i4h9besp2H9NYzU=
Expand Down
2 changes: 2 additions & 0 deletions internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/confluentinc/cli/v4/internal/plugin"
"github.com/confluentinc/cli/v4/internal/prompt"
providerintegration "github.com/confluentinc/cli/v4/internal/provider-integration"
"github.com/confluentinc/cli/v4/internal/rtce"
schemaregistry "github.com/confluentinc/cli/v4/internal/schema-registry"
"github.com/confluentinc/cli/v4/internal/secret"
servicequota "github.com/confluentinc/cli/v4/internal/service-quota"
Expand Down Expand Up @@ -131,6 +132,7 @@ func NewConfluentCommand(cfg *config.Config) *cobra.Command {
cmd.AddCommand(plugin.New(cfg, prerunner))
cmd.AddCommand(prompt.New(cfg))
cmd.AddCommand(providerintegration.New(prerunner))
cmd.AddCommand(rtce.New(cfg, prerunner))
cmd.AddCommand(schemaregistry.New(cfg, prerunner))
cmd.AddCommand(secret.New(prerunner, secrets.NewPasswordProtectionPlugin()))
cmd.AddCommand(servicequota.New(prerunner))
Expand Down
23 changes: 23 additions & 0 deletions internal/rtce/command.go
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
}
37 changes: 37 additions & 0 deletions internal/rtce/command_region.go
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 {
Copy link
Copy Markdown
Contributor Author

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.

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 := &regionCommand{
AuthenticatedCLICommand: pcmd.NewAuthenticatedCLICommand(cmd, prerunner),
}

cmd.AddCommand(
c.newListCommand(),
)

return cmd
}
56 changes: 56 additions & 0 deletions internal/rtce/command_region_list.go
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 := &regionOut{
ID: region.GetId(),
Cloud: region.GetCloud(),
Region: region.GetRegion(),
DisplayName: region.GetDisplayName(),
}
list.Add(out)
}
return list.Print()
}
103 changes: 103 additions & 0 deletions internal/rtce/command_rtce_topic.go
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
}
Comment thread
channingdong marked this conversation as resolved.

suggestions := make([]string, len(rtceTopics))
for i, rtceTopic := range rtceTopics {
suggestions[i] = rtceTopic.Spec.GetTopicName()
}
return suggestions
}
88 changes: 88 additions & 0 deletions internal/rtce/command_rtce_topic_create.go
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,
}
Comment thread
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)
}
Loading