diff --git a/.cli-generation-checksum b/.cli-generation-checksum index 333839b479..4e421cdcc7 100644 --- a/.cli-generation-checksum +++ b/.cli-generation-checksum @@ -1 +1 @@ -58aefba2da0f8430afc48f085285b659c6c5c6f5f2069871a16aa4652ffa50f7 +51a944df342166086f945fcb9381aed8c9f6f5d455de6d123f0f10f135c61070 diff --git a/go.mod b/go.mod index e8cce4fac9..5ca1bc9ff6 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/confluentinc/ccloud-sdk-go-v2/networking-gateway v0.7.0 github.com/confluentinc/ccloud-sdk-go-v2/networking-ip v0.2.0 github.com/confluentinc/ccloud-sdk-go-v2/networking-privatelink v0.3.0 - github.com/confluentinc/ccloud-sdk-go-v2/org v0.12.0 + github.com/confluentinc/ccloud-sdk-go-v2/org v0.13.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 diff --git a/go.sum b/go.sum index e1aba52bde..7844968c5f 100644 --- a/go.sum +++ b/go.sum @@ -225,8 +225,8 @@ github.com/confluentinc/ccloud-sdk-go-v2/networking-ip v0.2.0 h1:ZHNF2DeqVlNPuKG github.com/confluentinc/ccloud-sdk-go-v2/networking-ip v0.2.0/go.mod h1:KTShFBZA7WG8LcxlWjJpoZFdWkJ+uOw3dDuwAHs5eKU= github.com/confluentinc/ccloud-sdk-go-v2/networking-privatelink v0.3.0 h1:mC0E1nKUt57AxMM4Lpdfd+KA/YZwJVwro9ER+dCUFi8= github.com/confluentinc/ccloud-sdk-go-v2/networking-privatelink v0.3.0/go.mod h1:GIHF2cYOUKx+6ycYokr4i8E4cuNBC22xqvO/IhqZ31U= -github.com/confluentinc/ccloud-sdk-go-v2/org v0.12.0 h1:c3oeexhk5MiIzh+frC5EH9OlkoqAZK8UYeyaQVbSA+M= -github.com/confluentinc/ccloud-sdk-go-v2/org v0.12.0/go.mod h1:f3KzqFA5c0PddJ5qe4MWxlEiZ2n1yhzwvmPsdfEU6dw= +github.com/confluentinc/ccloud-sdk-go-v2/org v0.13.0 h1:/H/6SmonnvOzhjLA/6xSTSvq6N/uMuoPc66VEp/qxV8= +github.com/confluentinc/ccloud-sdk-go-v2/org v0.13.0/go.mod h1:BNnhFTvGhJSbyaklv0YkoTDWUdiWppLyu2hzfdxOWYM= 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= diff --git a/internal/command.go b/internal/command.go index 4b83164ff9..17fd5a1af4 100644 --- a/internal/command.go +++ b/internal/command.go @@ -118,7 +118,7 @@ func NewConfluentCommand(cfg *config.Config) *cobra.Command { cmd.AddCommand(connect.New(cfg, prerunner)) cmd.AddCommand(context.New(prerunner)) cmd.AddCommand(endpoint.New(cfg, prerunner)) - cmd.AddCommand(environment.New(prerunner)) + cmd.AddCommand(environment.New(cfg, prerunner)) cmd.AddCommand(feedback.New(prerunner)) cmd.AddCommand(flink.New(cfg, prerunner)) cmd.AddCommand(iam.New(cfg, prerunner)) diff --git a/internal/connect/command_artifact_create.go b/internal/connect/command_artifact_create.go index 2aa4e0c79d..3ee5d4c1e8 100644 --- a/internal/connect/command_artifact_create.go +++ b/internal/connect/command_artifact_create.go @@ -61,7 +61,7 @@ func (c *artifactCommand) createArtifact(cmd *cobra.Command, args []string) erro if err != nil { return err } - if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { + if _, _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { return fmt.Errorf("environment '%s' not found", environment) } description, err := cmd.Flags().GetString("description") diff --git a/internal/connect/command_artifact_delete.go b/internal/connect/command_artifact_delete.go index 6629e7e48a..461a558e0e 100644 --- a/internal/connect/command_artifact_delete.go +++ b/internal/connect/command_artifact_delete.go @@ -45,7 +45,7 @@ func (c *artifactCommand) delete(cmd *cobra.Command, args []string) error { if err != nil { return err } - if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { + if _, _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { return fmt.Errorf("environment '%s' not found", environment) } diff --git a/internal/connect/command_artifact_describe.go b/internal/connect/command_artifact_describe.go index 9be4e5f00c..679e9a3e5d 100644 --- a/internal/connect/command_artifact_describe.go +++ b/internal/connect/command_artifact_describe.go @@ -43,7 +43,7 @@ func (c *artifactCommand) describe(cmd *cobra.Command, args []string) error { if err != nil { return err } - if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { + if _, _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { return fmt.Errorf("environment '%s' not found", environment) } diff --git a/internal/connect/command_artifact_list.go b/internal/connect/command_artifact_list.go index 37e1dc58b8..bfc4be0114 100644 --- a/internal/connect/command_artifact_list.go +++ b/internal/connect/command_artifact_list.go @@ -44,7 +44,7 @@ func (c *artifactCommand) list(cmd *cobra.Command, _ []string) error { if err != nil { return err } - if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { + if _, _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { return fmt.Errorf("environment '%s' not found", environment) } diff --git a/internal/environment/command.go b/internal/environment/command.go index d547fdf427..78e7b8e453 100644 --- a/internal/environment/command.go +++ b/internal/environment/command.go @@ -1,16 +1,29 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package environment import ( "github.com/spf13/cobra" + orgv2 "github.com/confluentinc/ccloud-sdk-go-v2/org/v2" + pcmd "github.com/confluentinc/cli/v4/pkg/cmd" + "github.com/confluentinc/cli/v4/pkg/config" + "github.com/confluentinc/cli/v4/pkg/output" ) -type command struct { +type environmentCommand struct { *pcmd.AuthenticatedCLICommand } -func New(prerunner pcmd.PreRunner) *cobra.Command { +type environmentOut struct { + IsCurrent bool `human:"Current" serialized:"is_current"` + ID string `human:"ID" serialized:"id"` + Name string `human:"Name" serialized:"name"` + StreamGovernancePackage string `human:"Stream Governance Package" serialized:"stream_governance_package"` +} + +func New(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command { //nolint:unparam cmd := &cobra.Command{ Use: "environment", Aliases: []string{"env"}, @@ -18,19 +31,36 @@ func New(prerunner pcmd.PreRunner) *cobra.Command { Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin}, } - c := &command{pcmd.NewAuthenticatedCLICommand(cmd, prerunner)} + c := &environmentCommand{ + AuthenticatedCLICommand: pcmd.NewAuthenticatedCLICommand(cmd, prerunner), + } - cmd.AddCommand(c.newCreateCommand()) - cmd.AddCommand(c.newDeleteCommand()) - cmd.AddCommand(c.newDescribeCommand()) - cmd.AddCommand(c.newListCommand()) - cmd.AddCommand(c.newUpdateCommand()) - cmd.AddCommand(c.newUseCommand()) + cmd.AddCommand( + c.newCreateCommand(), + c.newDeleteCommand(), + c.newDescribeCommand(), + c.newListCommand(), + c.newUpdateCommand(), + c.newUseCommand(), + // cli-tfgen:cli-subcommands + ) return cmd } -func (c *command) validArgs(cmd *cobra.Command, args []string) []string { +func (c *environmentCommand) printEnvironment(cmd *cobra.Command, environment orgv2.OrgV2Environment) error { + table := output.NewTable(cmd) + out := &environmentOut{ + IsCurrent: environment.GetId() == c.Context.GetCurrentEnvironment(), + ID: environment.GetId(), + Name: environment.GetDisplayName(), + StreamGovernancePackage: environment.StreamGovernanceConfig.GetPackage(), + } + table.Add(out) + return table.Print() +} + +func (c *environmentCommand) validArgs(cmd *cobra.Command, args []string) []string { if len(args) > 0 { return nil } @@ -38,7 +68,7 @@ func (c *command) validArgs(cmd *cobra.Command, args []string) []string { return c.validArgsMultiple(cmd, args) } -func (c *command) validArgsMultiple(cmd *cobra.Command, args []string) []string { +func (c *environmentCommand) validArgsMultiple(cmd *cobra.Command, args []string) []string { if err := c.PersistentPreRunE(cmd, args); err != nil { return nil } diff --git a/internal/environment/command_create.go b/internal/environment/command_create.go index df3ea245dd..a17732c11a 100644 --- a/internal/environment/command_create.go +++ b/internal/environment/command_create.go @@ -1,7 +1,8 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package environment import ( - "fmt" "strings" "github.com/spf13/cobra" @@ -9,58 +10,48 @@ import ( orgv2 "github.com/confluentinc/ccloud-sdk-go-v2/org/v2" pcmd "github.com/confluentinc/cli/v4/pkg/cmd" - "github.com/confluentinc/cli/v4/pkg/output" - "github.com/confluentinc/cli/v4/pkg/utils" + "github.com/confluentinc/cli/v4/pkg/errors" ) -func (c *command) newCreateCommand() *cobra.Command { +func (c *environmentCommand) newCreateCommand() *cobra.Command { cmd := &cobra.Command{ Use: "create ", - Short: "Create a new Confluent Cloud environment.", + Short: "Create an environment.", Args: cobra.ExactArgs(1), RunE: c.create, } - c.addStreamGovernancePackageFlag(cmd, "essentials") + // Required flags + + // Optional flags + cmd.Flags().String("governance-package", "", "Specify the Stream Governance package as \"essentials\" or \"advanced\". On create, if not specified, the \"essentials\" package is used. Downgrading the package from \"advanced\" to \"essentials\" is not allowed once the Schema Registry cluster is provisioned.") + pcmd.AddContextFlag(cmd, c.CLICommand) pcmd.AddOutputFlag(cmd) return cmd } -func (c *command) create(cmd *cobra.Command, args []string) error { +func (c *environmentCommand) create(cmd *cobra.Command, args []string) error { + name := args[0] + + createReq := orgv2.OrgV2Environment{} + + createReq.DisplayName = orgv2.PtrString(name) + // allOf: stream_governance_config governancePackage, err := cmd.Flags().GetString("governance-package") if err != nil { return err } - - environment := orgv2.OrgV2Environment{ - DisplayName: orgv2.PtrString(args[0]), - StreamGovernanceConfig: &orgv2.OrgV2StreamGovernanceConfig{Package: strings.ToUpper(governancePackage)}, + if governancePackage != "" { + createReq.SetStreamGovernanceConfig(orgv2.OrgV2StreamGovernanceConfig{ + Package: strings.ToUpper(governancePackage), + }) } - environment, err = c.V2Client.CreateOrgEnvironment(environment) + environment, httpResp, err := c.V2Client.CreateOrgEnvironment(createReq) if err != nil { - return err + return errors.CatchCCloudV2Error(err, httpResp) } - table := output.NewTable(cmd) - table.Add(&out{ - IsCurrent: environment.GetId() == c.Context.GetCurrentEnvironment(), - Id: environment.GetId(), - Name: environment.GetDisplayName(), - StreamGovernancePackage: environment.StreamGovernanceConfig.GetPackage(), - }) - if err := table.Print(); err != nil { - return err - } - - c.Context.AddEnvironment(environment.GetId()) - _ = c.Config.Save() - - return nil -} - -func (c *command) addStreamGovernancePackageFlag(cmd *cobra.Command, defaultValue string) { - values := utils.ArrayToCommaDelimitedString([]string{"essentials", "advanced"}, "or") - cmd.Flags().String("governance-package", defaultValue, fmt.Sprintf(`Specify the Stream Governance package as %s. Downgrading the package from "advanced" to "essentials" is not allowed once the Schema Registry cluster is provisioned.`, values)) + return c.printEnvironment(cmd, environment) } diff --git a/internal/environment/command_delete.go b/internal/environment/command_delete.go index 906a724324..fecc74d3ce 100644 --- a/internal/environment/command_delete.go +++ b/internal/environment/command_delete.go @@ -1,3 +1,5 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package environment import ( @@ -7,56 +9,60 @@ import ( pcmd "github.com/confluentinc/cli/v4/pkg/cmd" "github.com/confluentinc/cli/v4/pkg/deletion" "github.com/confluentinc/cli/v4/pkg/errors" - "github.com/confluentinc/cli/v4/pkg/resource" ) -func (c *command) newDeleteCommand() *cobra.Command { +func (c *environmentCommand) newDeleteCommand() *cobra.Command { cmd := &cobra.Command{ Use: "delete [id-2] ... [id-n]", - Short: "Delete one or more Confluent Cloud environments.", - Long: "Delete one or more Confluent Cloud environments and all of their resources.", + Short: "Delete one or more environments.", + Long: "Delete one or more Confluent Cloud environments and all resources they contain.", Args: cobra.MinimumNArgs(1), ValidArgsFunction: pcmd.NewValidArgsFunction(c.validArgsMultiple), RunE: c.delete, } + // Required flags + + // Optional flags + pcmd.AddContextFlag(cmd, c.CLICommand) pcmd.AddForceFlag(cmd) return cmd } -func (c *command) delete(cmd *cobra.Command, args []string) error { - existenceFunc := func(id string) bool { - _, err := c.V2Client.GetOrgEnvironment(id) +func (c *environmentCommand) delete(cmd *cobra.Command, args []string) error { + existenceFunc := func(primaryId string) bool { + _, _, err := c.V2Client.GetOrgEnvironment(primaryId) return err == nil } - if err := deletion.ValidateAndConfirm(cmd, args, existenceFunc, resource.Environment); err != nil { + if err := deletion.ValidateAndConfirm(cmd, args, existenceFunc, "environment"); err != nil { return err } - deleteFunc := func(id string) error { - return c.V2Client.DeleteOrgEnvironment(id) + deleteFunc := func(primaryId string) error { + return c.V2Client.DeleteOrgEnvironment(primaryId) } - deletedIds, err := deletion.Delete(cmd, args, deleteFunc, resource.Environment) - - errs := multierror.Append(err, c.deleteEnvironmentsFromConfig(deletedIds)) + deletedIds, err := deletion.Delete(cmd, args, deleteFunc, "environment") + errs := multierror.Append(err, c.clearEnvironmentsFromConfigIfDeleted(deletedIds)) return errs.ErrorOrNil() } -func (c *command) deleteEnvironmentsFromConfig(deletedIds []string) error { +// clearEnvironmentsFromConfigIfDeleted resets the login context's current environment +// when it is among the just-deleted ids, so a context-scoped `describe` doesn't resolve a +// stale, deleted id (which would 404 instead of reporting "no environment selected"). +// General over context-selectable resources; the cosmetic per-environment cache entry is +// intentionally left in place (see the create-side AddEnvironment omission). +func (c *environmentCommand) clearEnvironmentsFromConfigIfDeleted(deletedIds []string) error { errs := &multierror.Error{ErrorFormat: errors.CustomMultierrorList} for _, id := range deletedIds { if id == c.Context.GetCurrentEnvironment() { c.Context.SetCurrentEnvironment("") errs = multierror.Append(errs, c.Config.Save()) } - c.Context.DeleteEnvironment(id) - _ = c.Config.Save() } - return errs.ErrorOrNil() } diff --git a/internal/environment/command_describe.go b/internal/environment/command_describe.go index c6c4f56033..9732890166 100644 --- a/internal/environment/command_describe.go +++ b/internal/environment/command_describe.go @@ -1,3 +1,5 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package environment import ( @@ -5,32 +7,28 @@ import ( pcmd "github.com/confluentinc/cli/v4/pkg/cmd" "github.com/confluentinc/cli/v4/pkg/errors" - "github.com/confluentinc/cli/v4/pkg/output" ) -type out struct { - IsCurrent bool `human:"Current" serialized:"is_current"` - Id string `human:"ID" serialized:"id"` - Name string `human:"Name" serialized:"name"` - StreamGovernancePackage string `human:"Stream Governance Package" serialized:"stream_governance_package"` -} - -func (c *command) newDescribeCommand() *cobra.Command { +func (c *environmentCommand) newDescribeCommand() *cobra.Command { cmd := &cobra.Command{ Use: "describe [id]", - Short: "Describe a Confluent Cloud environment.", + Short: "Describe an environment.", Args: cobra.MaximumNArgs(1), ValidArgsFunction: pcmd.NewValidArgsFunction(c.validArgs), RunE: c.describe, } + // Required flags + + // Optional flags + pcmd.AddContextFlag(cmd, c.CLICommand) pcmd.AddOutputFlag(cmd) return cmd } -func (c *command) describe(cmd *cobra.Command, args []string) error { +func (c *environmentCommand) describe(cmd *cobra.Command, args []string) error { id := c.Context.GetCurrentEnvironment() if len(args) > 0 { id = args[0] @@ -42,17 +40,10 @@ func (c *command) describe(cmd *cobra.Command, args []string) error { ) } - environment, err := c.V2Client.GetOrgEnvironment(id) + environment, httpResp, err := c.V2Client.GetOrgEnvironment(id) if err != nil { - return errors.NewErrorWithSuggestions(err.Error(), "List available environments with `confluent environment list`.") + return errors.CatchCCloudV2Error(err, httpResp) } - table := output.NewTable(cmd) - table.Add(&out{ - IsCurrent: environment.GetId() == c.Context.GetCurrentEnvironment(), - Id: environment.GetId(), - Name: environment.GetDisplayName(), - StreamGovernancePackage: environment.StreamGovernanceConfig.GetPackage(), - }) - return table.Print() + return c.printEnvironment(cmd, environment) } diff --git a/internal/environment/command_list.go b/internal/environment/command_list.go index 19e7e4cf6b..4552c07603 100644 --- a/internal/environment/command_list.go +++ b/internal/environment/command_list.go @@ -1,3 +1,5 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package environment import ( @@ -7,21 +9,26 @@ import ( "github.com/confluentinc/cli/v4/pkg/output" ) -func (c *command) newListCommand() *cobra.Command { +func (c *environmentCommand) newListCommand() *cobra.Command { cmd := &cobra.Command{ Use: "list", - Short: "List Confluent Cloud environments.", + Short: "List environments.", Args: cobra.NoArgs, RunE: c.list, } + // Required flags + + // Optional flags + pcmd.AddContextFlag(cmd, c.CLICommand) pcmd.AddOutputFlag(cmd) return cmd } -func (c *command) list(cmd *cobra.Command, _ []string) error { +func (c *environmentCommand) list(cmd *cobra.Command, _ []string) error { + environments, err := c.V2Client.ListOrgEnvironments() if err != nil { return err @@ -29,12 +36,13 @@ func (c *command) list(cmd *cobra.Command, _ []string) error { list := output.NewList(cmd) for _, environment := range environments { - list.Add(&out{ + out := &environmentOut{ IsCurrent: environment.GetId() == c.Context.GetCurrentEnvironment(), - Id: environment.GetId(), + ID: environment.GetId(), Name: environment.GetDisplayName(), StreamGovernancePackage: environment.StreamGovernanceConfig.GetPackage(), - }) + } + list.Add(out) } return list.Print() } diff --git a/internal/environment/command_update.go b/internal/environment/command_update.go index a91bfe9624..01cad7aec5 100644 --- a/internal/environment/command_update.go +++ b/internal/environment/command_update.go @@ -1,3 +1,5 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package environment import ( @@ -8,59 +10,61 @@ import ( orgv2 "github.com/confluentinc/ccloud-sdk-go-v2/org/v2" pcmd "github.com/confluentinc/cli/v4/pkg/cmd" + "github.com/confluentinc/cli/v4/pkg/errors" "github.com/confluentinc/cli/v4/pkg/output" ) -func (c *command) newUpdateCommand() *cobra.Command { +func (c *environmentCommand) newUpdateCommand() *cobra.Command { cmd := &cobra.Command{ Use: "update ", - Short: "Update an existing Confluent Cloud environment.", + Short: "Update an existing environment.", Args: cobra.ExactArgs(1), ValidArgsFunction: pcmd.NewValidArgsFunction(c.validArgs), RunE: c.update, } - cmd.Flags().String("name", "", "New name for Confluent Cloud environment.") - c.addStreamGovernancePackageFlag(cmd, "") + // Required flags + + // Optional flags + cmd.Flags().String("governance-package", "", "Specify the Stream Governance package as \"essentials\" or \"advanced\". On create, if not specified, the \"essentials\" package is used. Downgrading the package from \"advanced\" to \"essentials\" is not allowed once the Schema Registry cluster is provisioned.") + cmd.Flags().String("name", "", "A human-readable name for the Environment.") + pcmd.AddContextFlag(cmd, c.CLICommand) pcmd.AddOutputFlag(cmd) - cmd.MarkFlagsOneRequired("name", "governance-package") - return cmd } -func (c *command) update(cmd *cobra.Command, args []string) error { - name, err := cmd.Flags().GetString("name") +func (c *environmentCommand) update(cmd *cobra.Command, args []string) error { + id := args[0] + + updateReq := orgv2.OrgV2Environment{} + + displayName, err := cmd.Flags().GetString("name") if err != nil { return err } + if displayName != "" { + updateReq.DisplayName = orgv2.PtrString(displayName) + } + + // allOf: stream_governance_config governancePackage, err := cmd.Flags().GetString("governance-package") if err != nil { return err } - - environment := orgv2.OrgV2Environment{} - if name != "" { - environment.SetDisplayName(name) - } if governancePackage != "" { - environment.SetStreamGovernanceConfig(orgv2.OrgV2StreamGovernanceConfig{ + updateReq.SetStreamGovernanceConfig(orgv2.OrgV2StreamGovernanceConfig{ Package: strings.ToUpper(governancePackage), }) } - - environment, err = c.V2Client.UpdateOrgEnvironment(args[0], environment) + environment, httpResp, err := c.V2Client.UpdateOrgEnvironment(id, updateReq) if err != nil { - return err + return errors.CatchCCloudV2Error(err, httpResp) } - table := output.NewTable(cmd) - table.Add(&out{ - IsCurrent: environment.GetId() == c.Context.GetCurrentEnvironment(), - Id: environment.GetId(), - Name: environment.GetDisplayName(), - StreamGovernancePackage: environment.StreamGovernanceConfig.GetPackage(), - }) - return table.Print() + if output.GetFormat(cmd) == output.Human { + output.Printf(c.Config.EnableColor, "Updated environment \"%s\".\n", id) + } + return c.printEnvironment(cmd, environment) } diff --git a/internal/environment/command_use.go b/internal/environment/command_use.go index 119065ae66..6e0ae859f9 100644 --- a/internal/environment/command_use.go +++ b/internal/environment/command_use.go @@ -1,22 +1,20 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package environment import ( - "fmt" - "github.com/spf13/cobra" pcmd "github.com/confluentinc/cli/v4/pkg/cmd" "github.com/confluentinc/cli/v4/pkg/errors" "github.com/confluentinc/cli/v4/pkg/output" - "github.com/confluentinc/cli/v4/pkg/plural" - "github.com/confluentinc/cli/v4/pkg/resource" ) -func (c *command) newUseCommand() *cobra.Command { +func (c *environmentCommand) newUseCommand() *cobra.Command { cmd := &cobra.Command{ Use: "use ", Short: "Use an environment in subsequent commands.", - Long: "Choose a Confluent Cloud environment to be used in subsequent commands which support passing an environment with the `--environment` flag.", + Long: "Choose the active Confluent Cloud environment for subsequent commands that accept the `--environment` flag.", Args: cobra.ExactArgs(1), ValidArgsFunction: pcmd.NewValidArgsFunction(c.validArgs), RunE: c.use, @@ -25,11 +23,14 @@ func (c *command) newUseCommand() *cobra.Command { return cmd } -func (c *command) use(_ *cobra.Command, args []string) error { +func (c *environmentCommand) use(_ *cobra.Command, args []string) error { id := args[0] - if _, err := c.V2Client.GetOrgEnvironment(id); err != nil { - return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(errors.ListResourceSuggestions, plural.Plural(resource.Environment), "confluent environment")) + if _, httpResp, err := c.V2Client.GetOrgEnvironment(id); err != nil { + return errors.NewErrorWithSuggestions( + errors.CatchCCloudV2Error(err, httpResp).Error(), + "List available environments with `confluent environment list`.", + ) } c.Context.SetCurrentEnvironment(id) @@ -37,6 +38,6 @@ func (c *command) use(_ *cobra.Command, args []string) error { return err } - output.Printf(c.Config.EnableColor, errors.UsingResourceMsg, resource.Environment, id) + output.Printf(c.Config.EnableColor, errors.UsingResourceMsg, "environment", id) return nil } diff --git a/internal/flink/command_artifact_create.go b/internal/flink/command_artifact_create.go index 409d84aba7..ff05b143d2 100644 --- a/internal/flink/command_artifact_create.go +++ b/internal/flink/command_artifact_create.go @@ -95,7 +95,7 @@ func (c *command) createArtifact(cmd *cobra.Command, args []string) error { if err != nil { return err } - if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { + if _, _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { return fmt.Errorf("environment '%s' not found", environment) } runtimeLanguage, err := cmd.Flags().GetString("runtime-language") diff --git a/internal/flink/command_artifact_delete.go b/internal/flink/command_artifact_delete.go index c183346f8d..685c265f1c 100644 --- a/internal/flink/command_artifact_delete.go +++ b/internal/flink/command_artifact_delete.go @@ -54,7 +54,7 @@ func (c *command) delete(cmd *cobra.Command, args []string) error { if err != nil { return err } - if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { + if _, _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { return fmt.Errorf("environment '%s' not found", environment) } diff --git a/internal/flink/command_artifact_describe.go b/internal/flink/command_artifact_describe.go index dcdba4a031..5c55a41082 100644 --- a/internal/flink/command_artifact_describe.go +++ b/internal/flink/command_artifact_describe.go @@ -50,7 +50,7 @@ func (c *command) describe(cmd *cobra.Command, args []string) error { if err != nil { return err } - if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { + if _, _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { return fmt.Errorf("environment '%s' not found", environment) } diff --git a/internal/flink/command_artifact_list.go b/internal/flink/command_artifact_list.go index fce6f0216b..d2f35387ba 100644 --- a/internal/flink/command_artifact_list.go +++ b/internal/flink/command_artifact_list.go @@ -59,7 +59,7 @@ func (c *command) list(cmd *cobra.Command, _ []string) error { if err != nil { return err } - if _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { + if _, _, err = c.V2Client.GetOrgEnvironment(environment); err != nil { return fmt.Errorf("environment '%s' not found", environment) } diff --git a/internal/flink/command_compute_pool_create.go b/internal/flink/command_compute_pool_create.go index 1f7f8c91e0..80bb372e2f 100644 --- a/internal/flink/command_compute_pool_create.go +++ b/internal/flink/command_compute_pool_create.go @@ -64,7 +64,7 @@ func (c *command) computePoolCreate(cmd *cobra.Command, args []string) error { return err } - environment, err := c.V2Client.GetOrgEnvironment(environmentId) + environment, _, err := c.V2Client.GetOrgEnvironment(environmentId) if err != nil { return err } diff --git a/internal/flink/command_compute_pool_update.go b/internal/flink/command_compute_pool_update.go index 10492ed6af..683985db08 100644 --- a/internal/flink/command_compute_pool_update.go +++ b/internal/flink/command_compute_pool_update.go @@ -60,7 +60,7 @@ func (c *command) computePoolUpdate(cmd *cobra.Command, args []string) error { return err } - environment, err := c.V2Client.GetOrgEnvironment(environmentId) + environment, _, err := c.V2Client.GetOrgEnvironment(environmentId) if err != nil { return err } diff --git a/internal/flink/command_connection_create.go b/internal/flink/command_connection_create.go index 4e567601a4..e8546649e9 100644 --- a/internal/flink/command_connection_create.go +++ b/internal/flink/command_connection_create.go @@ -78,7 +78,7 @@ func (c *command) connectionCreate(cmd *cobra.Command, args []string) error { return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_connection_delete.go b/internal/flink/command_connection_delete.go index addd5d9064..c28e7018c2 100644 --- a/internal/flink/command_connection_delete.go +++ b/internal/flink/command_connection_delete.go @@ -38,7 +38,7 @@ func (c *command) connectionDelete(cmd *cobra.Command, args []string) error { return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_connection_describe.go b/internal/flink/command_connection_describe.go index 98a9ddb9f6..e0862f7ca0 100644 --- a/internal/flink/command_connection_describe.go +++ b/internal/flink/command_connection_describe.go @@ -36,7 +36,7 @@ func (c *command) connectionDescribe(cmd *cobra.Command, args []string) error { return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_connection_list.go b/internal/flink/command_connection_list.go index 03d593b40a..148820bf5e 100644 --- a/internal/flink/command_connection_list.go +++ b/internal/flink/command_connection_list.go @@ -39,7 +39,7 @@ func (c *command) connectionList(cmd *cobra.Command, _ []string) error { return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_connection_update.go b/internal/flink/command_connection_update.go index b980360b26..443c185f4e 100644 --- a/internal/flink/command_connection_update.go +++ b/internal/flink/command_connection_update.go @@ -48,7 +48,7 @@ func (c *command) connectionUpdate(cmd *cobra.Command, args []string) error { return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_materialized_table_create.go b/internal/flink/command_materialized_table_create.go index 3e6af77876..c989d32a50 100644 --- a/internal/flink/command_materialized_table_create.go +++ b/internal/flink/command_materialized_table_create.go @@ -78,7 +78,7 @@ func (c *command) materializedTableCreate(cmd *cobra.Command, args []string) err return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_materialized_table_delete.go b/internal/flink/command_materialized_table_delete.go index 5ccd8957ab..8c23bbb361 100644 --- a/internal/flink/command_materialized_table_delete.go +++ b/internal/flink/command_materialized_table_delete.go @@ -38,7 +38,7 @@ func (c *command) materializedTableDelete(cmd *cobra.Command, args []string) err return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_materialized_table_describe.go b/internal/flink/command_materialized_table_describe.go index 77e9676540..5f92409ea1 100644 --- a/internal/flink/command_materialized_table_describe.go +++ b/internal/flink/command_materialized_table_describe.go @@ -37,7 +37,7 @@ func (c *command) materializedTableDescribe(cmd *cobra.Command, args []string) e return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_materialized_table_list.go b/internal/flink/command_materialized_table_list.go index d3b5d1550f..c6d680cb3f 100644 --- a/internal/flink/command_materialized_table_list.go +++ b/internal/flink/command_materialized_table_list.go @@ -33,7 +33,7 @@ func (c *command) materializedTableList(cmd *cobra.Command, _ []string) error { return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_materialized_table_update.go b/internal/flink/command_materialized_table_update.go index 57cb94ea3e..548b7ef445 100644 --- a/internal/flink/command_materialized_table_update.go +++ b/internal/flink/command_materialized_table_update.go @@ -56,7 +56,7 @@ func (c *command) materializedTableUpdate(cmd *cobra.Command, args []string) err return err } - if _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { + if _, _, err := c.V2Client.GetOrgEnvironment(environmentId); err != nil { return errors.NewErrorWithSuggestions(err.Error(), fmt.Sprintf(envNotFoundErrorMsg, environmentId)) } diff --git a/internal/flink/command_shell.go b/internal/flink/command_shell.go index cd9f305922..7d3e17e3db 100644 --- a/internal/flink/command_shell.go +++ b/internal/flink/command_shell.go @@ -173,7 +173,7 @@ func (c *command) startFlinkSqlClient(prerunner pcmd.PreRunner, cmd *cobra.Comma catalog := c.Context.GetCurrentFlinkCatalog() if catalog == "" { - environment, err := c.V2Client.GetOrgEnvironment(environmentId) + environment, _, err := c.V2Client.GetOrgEnvironment(environmentId) if err != nil { return errors.NewErrorWithSuggestions(err.Error(), "List available environments with `confluent environment list`.") } diff --git a/internal/flink/command_statement_create.go b/internal/flink/command_statement_create.go index eda49f8606..39c4f78e73 100644 --- a/internal/flink/command_statement_create.go +++ b/internal/flink/command_statement_create.go @@ -60,7 +60,7 @@ func (c *command) statementCreate(cmd *cobra.Command, args []string) error { return err } - environment, err := c.V2Client.GetOrgEnvironment(environmentId) + environment, _, err := c.V2Client.GetOrgEnvironment(environmentId) if err != nil { return errors.NewErrorWithSuggestions(err.Error(), "List available environments with `confluent environment list`.") } diff --git a/internal/rtce/command_region.go b/internal/rtce/command_region.go index 11d137154e..9edb5d092b 100644 --- a/internal/rtce/command_region.go +++ b/internal/rtce/command_region.go @@ -1,3 +1,5 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package rtce import ( @@ -21,7 +23,7 @@ type regionOut struct { func newRegionCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command { //nolint:unparam cmd := &cobra.Command{ Use: "region", - Short: "Manage RTCE regions.", + Short: "Manage Confluent Cloud RTCE regions.", Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin}, } diff --git a/internal/rtce/command_region_list.go b/internal/rtce/command_region_list.go index 85ece8e95f..9b834c13ea 100644 --- a/internal/rtce/command_region_list.go +++ b/internal/rtce/command_region_list.go @@ -1,3 +1,5 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package rtce import ( diff --git a/internal/rtce/command_rtce_topic.go b/internal/rtce/command_rtce_topic.go index 78ff7d4064..de90653178 100644 --- a/internal/rtce/command_rtce_topic.go +++ b/internal/rtce/command_rtce_topic.go @@ -31,7 +31,7 @@ type rtceTopicOut struct { func newRtceTopicCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command { //nolint:unparam cmd := &cobra.Command{ Use: "rtce-topic", - Short: "Manage RTCE topics.", + Short: "Manage Confluent Cloud RTCE topics.", Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin}, } diff --git a/internal/rtce/command_rtce_topic_update.go b/internal/rtce/command_rtce_topic_update.go index 9599999725..e2bbe83edc 100644 --- a/internal/rtce/command_rtce_topic_update.go +++ b/internal/rtce/command_rtce_topic_update.go @@ -16,7 +16,7 @@ import ( func (c *rtceTopicCommand) newUpdateCommand() *cobra.Command { cmd := &cobra.Command{ Use: "update ", - Short: "Update an RTCE topic.", + Short: "Update an existing RTCE topic.", Args: cobra.ExactArgs(1), ValidArgsFunction: pcmd.NewValidArgsFunction(c.validArgs), RunE: c.update, @@ -72,6 +72,8 @@ func (c *rtceTopicCommand) update(cmd *cobra.Command, args []string) error { return errors.CatchCCloudV2Error(err, httpResp) } - output.Printf(c.Config.EnableColor, "Updated RTCE topic \"%s\".\n", topicName) + if output.GetFormat(cmd) == output.Human { + output.Printf(c.Config.EnableColor, "Updated RTCE topic \"%s\".\n", topicName) + } return printRtceTopic(cmd, rtceTopic) } diff --git a/pkg/ccloudv2/org.go b/pkg/ccloudv2/org.go index 835c9d0568..9f13cd98f0 100644 --- a/pkg/ccloudv2/org.go +++ b/pkg/ccloudv2/org.go @@ -23,33 +23,21 @@ func (c *Client) orgApiContext() context.Context { return context.WithValue(context.Background(), orgv2.ContextAccessToken, c.cfg.Context().GetAuthToken()) } -func (c *Client) CreateOrgEnvironment(environment orgv2.OrgV2Environment) (orgv2.OrgV2Environment, error) { - res, httpResp, err := c.OrgClient.EnvironmentsOrgV2Api.CreateOrgV2Environment(c.orgApiContext()).OrgV2Environment(environment).Execute() - return res, errors.CatchCCloudV2Error(err, httpResp) -} - -func (c *Client) GetOrgEnvironment(envId string) (orgv2.OrgV2Environment, error) { - res, httpResp, err := c.OrgClient.EnvironmentsOrgV2Api.GetOrgV2Environment(c.orgApiContext(), envId).Execute() - return res, errors.CatchCCloudV2ResourceNotFoundError(err, envId, httpResp) -} - -func (c *Client) UpdateOrgEnvironment(envId string, updateEnvironment orgv2.OrgV2Environment) (orgv2.OrgV2Environment, error) { - res, httpResp, err := c.OrgClient.EnvironmentsOrgV2Api.UpdateOrgV2Environment(c.orgApiContext(), envId).OrgV2Environment(updateEnvironment).Execute() - return res, errors.CatchCCloudV2Error(err, httpResp) +func (c *Client) GetOrgOrganization(orgId string) (orgv2.OrgV2Organization, *http.Response, error) { + return c.OrgClient.OrganizationsOrgV2Api.GetOrgV2Organization(c.orgApiContext(), orgId).Execute() } -func (c *Client) DeleteOrgEnvironment(envId string) error { - httpResp, err := c.OrgClient.EnvironmentsOrgV2Api.DeleteOrgV2Environment(c.orgApiContext(), envId).Execute() - return errors.CatchCCloudV2Error(err, httpResp) +func (c *Client) UpdateOrgOrganization(orgId string, updateOrganization orgv2.OrgV2Organization) (orgv2.OrgV2Organization, *http.Response, error) { + return c.OrgClient.OrganizationsOrgV2Api.UpdateOrgV2Organization(c.orgApiContext(), orgId).OrgV2Organization(updateOrganization).Execute() } -func (c *Client) ListOrgEnvironments() ([]orgv2.OrgV2Environment, error) { - var list []orgv2.OrgV2Environment +func (c *Client) ListOrgOrganizations() ([]orgv2.OrgV2Organization, error) { + var list []orgv2.OrgV2Organization done := false pageToken := "" for !done { - page, httpResp, err := c.executeListEnvironments(pageToken) + page, httpResp, err := c.executeListOrganizations(pageToken) if err != nil { return nil, errors.CatchCCloudV2Error(err, httpResp) } @@ -63,29 +51,50 @@ func (c *Client) ListOrgEnvironments() ([]orgv2.OrgV2Environment, error) { return list, nil } -func (c *Client) executeListEnvironments(pageToken string) (orgv2.OrgV2EnvironmentList, *http.Response, error) { - req := c.OrgClient.EnvironmentsOrgV2Api.ListOrgV2Environments(c.orgApiContext()).PageSize(ccloudV2ListPageSize) +func (c *Client) executeListOrganizations(pageToken string) (orgv2.OrgV2OrganizationList, *http.Response, error) { + req := c.OrgClient.OrganizationsOrgV2Api.ListOrgV2Organizations(c.orgApiContext()).PageSize(ccloudV2ListPageSize) if pageToken != "" { req = req.PageToken(pageToken) } return req.Execute() } -func (c *Client) GetOrgOrganization(orgId string) (orgv2.OrgV2Organization, *http.Response, error) { - return c.OrgClient.OrganizationsOrgV2Api.GetOrgV2Organization(c.orgApiContext(), orgId).Execute() +// ===== org environments API calls ===== + +func (c *Client) CreateOrgEnvironment(req orgv2.OrgV2Environment) (orgv2.OrgV2Environment, *http.Response, error) { + createReq := c.OrgClient.EnvironmentsOrgV2Api. + CreateOrgV2Environment(c.orgApiContext()). + OrgV2Environment(req) + return createReq.Execute() } -func (c *Client) UpdateOrgOrganization(orgId string, updateOrganization orgv2.OrgV2Organization) (orgv2.OrgV2Organization, *http.Response, error) { - return c.OrgClient.OrganizationsOrgV2Api.UpdateOrgV2Organization(c.orgApiContext(), orgId).OrgV2Organization(updateOrganization).Execute() +func (c *Client) GetOrgEnvironment(id string) (orgv2.OrgV2Environment, *http.Response, error) { + getReq := c.OrgClient.EnvironmentsOrgV2Api. + GetOrgV2Environment(c.orgApiContext(), id) + return getReq.Execute() } -func (c *Client) ListOrgOrganizations() ([]orgv2.OrgV2Organization, error) { - var list []orgv2.OrgV2Organization +func (c *Client) UpdateOrgEnvironment(id string, update orgv2.OrgV2Environment) (orgv2.OrgV2Environment, *http.Response, error) { + updateReq := c.OrgClient.EnvironmentsOrgV2Api. + UpdateOrgV2Environment(c.orgApiContext(), id). + OrgV2Environment(update) + return updateReq.Execute() +} + +func (c *Client) DeleteOrgEnvironment(id string) error { + deleteReq := c.OrgClient.EnvironmentsOrgV2Api. + DeleteOrgV2Environment(c.orgApiContext(), id) + httpResp, err := deleteReq.Execute() + return errors.CatchCCloudV2Error(err, httpResp) +} + +func (c *Client) ListOrgEnvironments() ([]orgv2.OrgV2Environment, error) { + var list []orgv2.OrgV2Environment done := false pageToken := "" for !done { - page, httpResp, err := c.executeListOrganizations(pageToken) + page, httpResp, err := c.executeListEnvironments(pageToken) if err != nil { return nil, errors.CatchCCloudV2Error(err, httpResp) } @@ -96,11 +105,14 @@ func (c *Client) ListOrgOrganizations() ([]orgv2.OrgV2Organization, error) { return nil, err } } + return list, nil } -func (c *Client) executeListOrganizations(pageToken string) (orgv2.OrgV2OrganizationList, *http.Response, error) { - req := c.OrgClient.OrganizationsOrgV2Api.ListOrgV2Organizations(c.orgApiContext()).PageSize(ccloudV2ListPageSize) +func (c *Client) executeListEnvironments(pageToken string) (orgv2.OrgV2EnvironmentList, *http.Response, error) { + req := c.OrgClient.EnvironmentsOrgV2Api. + ListOrgV2Environments(c.orgApiContext()). + PageSize(ccloudV2ListPageSize) if pageToken != "" { req = req.PageToken(pageToken) } diff --git a/pkg/ccloudv2/rtce.go b/pkg/ccloudv2/rtce.go index fb7a5c2c86..91307c5550 100644 --- a/pkg/ccloudv2/rtce.go +++ b/pkg/ccloudv2/rtce.go @@ -25,6 +25,45 @@ func (c *Client) rtceApiContext() context.Context { return context.WithValue(context.Background(), rtcev1.ContextAccessToken, c.cfg.Context().GetAuthToken()) } +// ===== RTCE regions API calls ===== + +func (c *Client) ListRtceRegions(cloud string, region string) ([]rtcev1.RtceV1Region, error) { + var list []rtcev1.RtceV1Region + + done := false + pageToken := "" + for !done { + page, httpResp, err := c.executeListRegions(cloud, region, pageToken) + if err != nil { + return nil, errors.CatchCCloudV2Error(err, httpResp) + } + list = append(list, page.GetData()...) + + pageToken, done, err = extractNextPageToken(page.GetMetadata().Next) + if err != nil { + return nil, err + } + } + + return list, nil +} + +func (c *Client) executeListRegions(cloud string, region string, pageToken string) (rtcev1.RtceV1RegionList, *http.Response, error) { + req := c.RtceClient.RegionsRtceV1Api. + ListRtceV1Regions(c.rtceApiContext()). + PageSize(ccloudV2ListPageSize) + if cloud != "" { + req = req.Cloud(cloud) + } + if region != "" { + req = req.Region(region) + } + if pageToken != "" { + req = req.PageToken(pageToken) + } + return req.Execute() +} + // ===== RTCE topics API calls ===== func (c *Client) CreateRtceTopic(req rtcev1.RtceV1RtceTopic) (rtcev1.RtceV1RtceTopic, *http.Response, error) { @@ -96,42 +135,3 @@ func (c *Client) executeListRtceTopics(specCloud string, specRegion string, envi } return req.Execute() } - -// ===== RTCE regions API calls ===== - -func (c *Client) ListRtceRegions(cloud string, region string) ([]rtcev1.RtceV1Region, error) { - var list []rtcev1.RtceV1Region - - done := false - pageToken := "" - for !done { - page, httpResp, err := c.executeListRegions(cloud, region, pageToken) - if err != nil { - return nil, errors.CatchCCloudV2Error(err, httpResp) - } - list = append(list, page.GetData()...) - - pageToken, done, err = extractNextPageToken(page.GetMetadata().Next) - if err != nil { - return nil, err - } - } - - return list, nil -} - -func (c *Client) executeListRegions(cloud string, region string, pageToken string) (rtcev1.RtceV1RegionList, *http.Response, error) { - req := c.RtceClient.RegionsRtceV1Api. - ListRtceV1Regions(c.rtceApiContext()). - PageSize(ccloudV2ListPageSize) - if cloud != "" { - req = req.Cloud(cloud) - } - if region != "" { - req = req.Region(region) - } - if pageToken != "" { - req = req.PageToken(pageToken) - } - return req.Execute() -} diff --git a/pkg/cmd/flags.go b/pkg/cmd/flags.go index 1c10e9bd21..c36d2ba0c3 100644 --- a/pkg/cmd/flags.go +++ b/pkg/cmd/flags.go @@ -194,7 +194,7 @@ func AutocompleteEnvironments(v1Client *ccloudv1.Client, v2Client *ccloudv2.Clie } if auditLog := user.GetOrganization().GetAuditLog(); auditLog.GetServiceAccountId() != 0 { - environment, err := v2Client.GetOrgEnvironment(auditLog.GetAccountId()) + environment, _, err := v2Client.GetOrgEnvironment(auditLog.GetAccountId()) if err != nil { return nil } diff --git a/test/fixtures/output/environment/3.golden b/test/fixtures/output/environment/3.golden index 7fa1020401..67fe104505 100644 --- a/test/fixtures/output/environment/3.golden +++ b/test/fixtures/output/environment/3.golden @@ -1,3 +1,4 @@ +Updated environment "env-595". +---------------------------+----------------+ | Current | true | | ID | env-595 | diff --git a/test/fixtures/output/environment/create-help.golden b/test/fixtures/output/environment/create-help.golden index f504019ea2..f5c87cd491 100644 --- a/test/fixtures/output/environment/create-help.golden +++ b/test/fixtures/output/environment/create-help.golden @@ -1,10 +1,10 @@ -Create a new Confluent Cloud environment. +Create an environment. Usage: confluent environment create [flags] Flags: - --governance-package string Specify the Stream Governance package as "essentials" or "advanced". Downgrading the package from "advanced" to "essentials" is not allowed once the Schema Registry cluster is provisioned. (default "essentials") + --governance-package string Specify the Stream Governance package as "essentials" or "advanced". On create, if not specified, the "essentials" package is used. Downgrading the package from "advanced" to "essentials" is not allowed once the Schema Registry cluster is provisioned. --context string CLI context name. -o, --output string Specify the output format as "human", "json", or "yaml". (default "human") diff --git a/test/fixtures/output/environment/delete-help.golden b/test/fixtures/output/environment/delete-help.golden index 3cab4d1c2f..b4ee120eed 100644 --- a/test/fixtures/output/environment/delete-help.golden +++ b/test/fixtures/output/environment/delete-help.golden @@ -1,4 +1,4 @@ -Delete one or more Confluent Cloud environments and all of their resources. +Delete one or more Confluent Cloud environments and all resources they contain. Usage: confluent environment delete [id-2] ... [id-n] [flags] diff --git a/test/fixtures/output/environment/describe-help.golden b/test/fixtures/output/environment/describe-help.golden index 1865b0cd27..0b5629d5c7 100644 --- a/test/fixtures/output/environment/describe-help.golden +++ b/test/fixtures/output/environment/describe-help.golden @@ -1,4 +1,4 @@ -Describe a Confluent Cloud environment. +Describe an environment. Usage: confluent environment describe [id] [flags] diff --git a/test/fixtures/output/environment/help.golden b/test/fixtures/output/environment/help.golden index ec88db3852..3d72c79bff 100644 --- a/test/fixtures/output/environment/help.golden +++ b/test/fixtures/output/environment/help.golden @@ -7,11 +7,11 @@ Aliases: environment, env Available Commands: - create Create a new Confluent Cloud environment. - delete Delete one or more Confluent Cloud environments. - describe Describe a Confluent Cloud environment. - list List Confluent Cloud environments. - update Update an existing Confluent Cloud environment. + create Create an environment. + delete Delete one or more environments. + describe Describe an environment. + list List environments. + update Update an existing environment. use Use an environment in subsequent commands. Global Flags: diff --git a/test/fixtures/output/environment/list-help.golden b/test/fixtures/output/environment/list-help.golden index c1de6464b1..0f1d31d926 100644 --- a/test/fixtures/output/environment/list-help.golden +++ b/test/fixtures/output/environment/list-help.golden @@ -1,4 +1,4 @@ -List Confluent Cloud environments. +List environments. Usage: confluent environment list [flags] diff --git a/test/fixtures/output/environment/update-help.golden b/test/fixtures/output/environment/update-help.golden index 58ff87547d..e8aadf5aed 100644 --- a/test/fixtures/output/environment/update-help.golden +++ b/test/fixtures/output/environment/update-help.golden @@ -1,11 +1,11 @@ -Update an existing Confluent Cloud environment. +Update an existing environment. Usage: confluent environment update [flags] Flags: - --name string New name for Confluent Cloud environment. - --governance-package string Specify the Stream Governance package as "essentials" or "advanced". Downgrading the package from "advanced" to "essentials" is not allowed once the Schema Registry cluster is provisioned. + --governance-package string Specify the Stream Governance package as "essentials" or "advanced". On create, if not specified, the "essentials" package is used. Downgrading the package from "advanced" to "essentials" is not allowed once the Schema Registry cluster is provisioned. + --name string A human-readable name for the Environment. --context string CLI context name. -o, --output string Specify the output format as "human", "json", or "yaml". (default "human") diff --git a/test/fixtures/output/environment/use-help.golden b/test/fixtures/output/environment/use-help.golden index 0ccc9af84f..5676e2a9b9 100644 --- a/test/fixtures/output/environment/use-help.golden +++ b/test/fixtures/output/environment/use-help.golden @@ -1,4 +1,4 @@ -Choose a Confluent Cloud environment to be used in subsequent commands which support passing an environment with the `--environment` flag. +Choose the active Confluent Cloud environment for subsequent commands that accept the `--environment` flag. Usage: confluent environment use [flags] diff --git a/test/fixtures/output/rtce/help.golden b/test/fixtures/output/rtce/help.golden index 18e3dca17e..3577e52232 100644 --- a/test/fixtures/output/rtce/help.golden +++ b/test/fixtures/output/rtce/help.golden @@ -4,8 +4,8 @@ Usage: confluent rtce [command] Available Commands: - region Manage RTCE regions. - rtce-topic Manage RTCE topics. + region Manage Confluent Cloud RTCE regions. + rtce-topic Manage Confluent Cloud RTCE topics. Global Flags: -h, --help Show help for this command. diff --git a/test/fixtures/output/rtce/region/help.golden b/test/fixtures/output/rtce/region/help.golden index 188300b759..e3e2ff8a14 100644 --- a/test/fixtures/output/rtce/region/help.golden +++ b/test/fixtures/output/rtce/region/help.golden @@ -1,4 +1,4 @@ -Manage RTCE regions. +Manage Confluent Cloud RTCE regions. Usage: confluent rtce region [command] diff --git a/test/fixtures/output/rtce/rtce-topic/help.golden b/test/fixtures/output/rtce/rtce-topic/help.golden index 8cb3c38168..014def1f7e 100644 --- a/test/fixtures/output/rtce/rtce-topic/help.golden +++ b/test/fixtures/output/rtce/rtce-topic/help.golden @@ -1,4 +1,4 @@ -Manage RTCE topics. +Manage Confluent Cloud RTCE topics. Usage: confluent rtce rtce-topic [command] @@ -8,7 +8,7 @@ Available Commands: delete Delete one or more RTCE topics. describe Describe an RTCE topic. list List RTCE topics. - update Update an RTCE topic. + update Update an existing RTCE topic. Global Flags: -h, --help Show help for this command. diff --git a/test/fixtures/output/rtce/rtce-topic/update-help.golden b/test/fixtures/output/rtce/rtce-topic/update-help.golden index d7c47b7954..fa6238b77d 100644 --- a/test/fixtures/output/rtce/rtce-topic/update-help.golden +++ b/test/fixtures/output/rtce/rtce-topic/update-help.golden @@ -1,4 +1,4 @@ -Update an RTCE topic. +Update an existing RTCE topic. Usage: confluent rtce rtce-topic update [flags] diff --git a/test/live/environment_live_test.go b/test/live/environment_live_test.go index 0fad3d9bce..6b897fbebb 100644 --- a/test/live/environment_live_test.go +++ b/test/live/environment_live_test.go @@ -1,5 +1,7 @@ //go:build live_test && (all || core) +// Code generated by cli-terraform-generator; DO NOT EDIT. + package live import ( @@ -11,31 +13,30 @@ func (s *CLILiveTestSuite) TestEnvironmentCRUDLive() { t.Parallel() state := s.setupTestContext(t) - envName := uniqueName("env") - updatedEnvName := envName + "-updated" + // Variables + environmentName := uniqueName("enviro") - // Register cleanup immediately — runs even if test fails (LIFO order) - s.registerCleanup(t, "environment delete {{.env_id}} --force", state) + // Cleanup (LIFO — execution is reverse-registration order) + s.registerCleanup(t, "environment delete {{.environment_id}} --force", state) steps := []CLILiveTest{ { Name: "Create environment", - Args: "environment create " + envName + " -o json", + Args: "environment create " + environmentName + " -o json", ExitCode: 0, JSONFields: map[string]string{ - "name": envName, + "name": environmentName, }, JSONFieldsExist: []string{"id"}, - CaptureID: "env_id", + CaptureID: "environment_id", }, { Name: "Describe environment", - Args: "environment describe {{.env_id}} -o json", + Args: "environment describe {{.environment_id}} -o json", UseStateVars: true, ExitCode: 0, JSONFields: map[string]string{ - "name": envName, - "id": "", // any non-empty value + "name": environmentName, }, }, { @@ -43,32 +44,23 @@ func (s *CLILiveTestSuite) TestEnvironmentCRUDLive() { Args: "environment list", UseStateVars: true, ExitCode: 0, - Contains: []string{envName}, + Contains: []string{environmentName}, }, { Name: "Update environment name", - Args: "environment update {{.env_id}} --name " + updatedEnvName, + Args: "environment update {{.environment_id}} --name " + environmentName + "-updated", UseStateVars: true, ExitCode: 0, }, - { - Name: "Describe updated environment", - Args: "environment describe {{.env_id}} -o json", - UseStateVars: true, - ExitCode: 0, - JSONFields: map[string]string{ - "name": updatedEnvName, - }, - }, { Name: "Delete environment", - Args: "environment delete {{.env_id}} --force", + Args: "environment delete {{.environment_id}} --force", UseStateVars: true, ExitCode: 0, }, { Name: "Verify deletion", - Args: "environment describe {{.env_id}}", + Args: "environment describe {{.environment_id}}", UseStateVars: true, ExitCode: 1, }, diff --git a/test/live/region_live_test.go b/test/live/region_live_test.go new file mode 100644 index 0000000000..5a347ee38d --- /dev/null +++ b/test/live/region_live_test.go @@ -0,0 +1,32 @@ +//go:build live_test && (all || rtce) + +// Code generated by cli-terraform-generator; DO NOT EDIT. + +package live + +import ( + "testing" +) + +func (s *CLILiveTestSuite) TestRegionCRUDLive() { + t := s.T() + t.Parallel() + state := s.setupTestContext(t) + + // Cleanup (LIFO — execution is reverse-registration order) + + steps := []CLILiveTest{ + { + Name: "List RTCE regions", + Args: "rtce region list", + UseStateVars: true, + ExitCode: 0, + }, + } + + for _, step := range steps { + t.Run(step.Name, func(t *testing.T) { + s.runLiveCommand(t, step, state) + }) + } +} diff --git a/test/region_test.go b/test/region_test.go index eec4e2ad5c..91f1b2f19e 100644 --- a/test/region_test.go +++ b/test/region_test.go @@ -1,3 +1,5 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package test func (s *CLITestSuite) TestRtceRegionList() { diff --git a/test/test-server/org_handlers.go b/test/test-server/org_handlers.go index aed5e58f6b..7b6925febf 100644 --- a/test/test-server/org_handlers.go +++ b/test/test-server/org_handlers.go @@ -93,10 +93,19 @@ func handleOrgEnvironments(t *testing.T) http.HandlerFunc { err := json.NewDecoder(r.Body).Decode(req) require.NoError(t, err) + // The real API defaults Stream Governance to ESSENTIALS when the create request + // omits stream_governance_config entirely (the CLI sends no config unless + // --governance-package is set). A non-nil config always carries a non-empty + // package (the CLI gates the flag on non-empty); a nil package would be a 400, + // which we don't mock. + sgc := req.StreamGovernanceConfig + if sgc == nil { + sgc = &orgv2.OrgV2StreamGovernanceConfig{Package: "ESSENTIALS"} + } environment := &orgv2.OrgV2Environment{ Id: orgv2.PtrString("env-5555"), DisplayName: orgv2.PtrString(req.GetDisplayName()), - StreamGovernanceConfig: req.StreamGovernanceConfig, + StreamGovernanceConfig: sgc, } err = json.NewEncoder(w).Encode(environment) require.NoError(t, err) diff --git a/test/test-server/region_handler.go b/test/test-server/region_handler.go index 2f5d929603..ee71fa1ea0 100644 --- a/test/test-server/region_handler.go +++ b/test/test-server/region_handler.go @@ -1,3 +1,5 @@ +// Code generated by cli-terraform-generator; DO NOT EDIT. + package testserver import (