Skip to content

Commit

Permalink
Fix on-prem kafka rest bug (#2787)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgagniere committed Jun 3, 2024
1 parent f28a56a commit f84f281
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion internal/connect/command_plugin_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newInstallCommand(prerunner pcmd.PreRunner) *cobra.Command {
Code: "confluent connect plugin install confluentinc/kafka-connect-datagen:latest --plugin-directory $CONFLUENT_HOME/plugins --worker-configurations $CONFLUENT_HOME/etc/kafka/connect-distributed.properties",
},
),
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonCloudLogin},
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout},
}

cmd.Flags().String("plugin-directory", "", "The plugin installation directory. If not specified, a default will be selected based on your Confluent Platform installation.")
Expand Down
2 changes: 1 addition & 1 deletion internal/kafka/command_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func newBrokerCommand(prerunner pcmd.PreRunner) *cobra.Command {
cmd := &cobra.Command{
Use: "broker",
Short: "Manage Kafka brokers.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireOnPremLogin},
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout},
}

c := &brokerCommand{pcmd.NewAuthenticatedWithMDSCLICommand(cmd, prerunner)}
Expand Down
5 changes: 2 additions & 3 deletions internal/kafka/command_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ type consumerOut struct {

func newConsumerCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command {
cmd := &cobra.Command{
Use: "consumer",
Short: "Manage Kafka consumers.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLoginOrOnPremLogin},
Use: "consumer",
Short: "Manage Kafka consumers.",
}

c := &consumerCommand{}
Expand Down
8 changes: 3 additions & 5 deletions internal/kafka/command_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ type linkCommand struct {

func newLinkCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command {
cmd := &cobra.Command{
Use: "link",
Short: "Manage inter-cluster links.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLoginOrOnPremLogin},
Use: "link",
Short: "Manage inter-cluster links.",
}

c := &linkCommand{}

if cfg.IsCloudLogin() {
c.AuthenticatedCLICommand = pcmd.NewAuthenticatedCLICommand(cmd, prerunner)

cmd.AddCommand(c.newConfigurationCommand(cfg))
cmd.AddCommand(c.newCreateCommand())
cmd.AddCommand(c.newDeleteCommand())
cmd.AddCommand(c.newDescribeCommand())
Expand All @@ -40,13 +38,13 @@ func newLinkCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command
c.AuthenticatedCLICommand = pcmd.NewAuthenticatedWithMDSCLICommand(cmd, prerunner)
c.PersistentPreRunE = prerunner.InitializeOnPremKafkaRest(c.AuthenticatedCLICommand)

cmd.AddCommand(c.newConfigurationCommand(cfg))
cmd.AddCommand(c.newCreateCommandOnPrem())
cmd.AddCommand(c.newDeleteCommandOnPrem())
cmd.AddCommand(c.newDescribeCommandOnPrem())
cmd.AddCommand(c.newListCommandOnPrem())
cmd.AddCommand(c.newTaskCommandOnPrem())
}
cmd.AddCommand(c.newConfigurationCommand(cfg))

return cmd
}
Expand Down
5 changes: 2 additions & 3 deletions internal/kafka/command_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ type partitionCommand struct {

func newPartitionCommand(cfg *config.Config, prerunner pcmd.PreRunner) *cobra.Command {
cmd := &cobra.Command{
Use: "partition",
Short: "Manage Kafka partitions.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLoginOrOnPremLogin},
Use: "partition",
Short: "Manage Kafka partitions.",
}

c := &partitionCommand{}
Expand Down
2 changes: 1 addition & 1 deletion internal/kafka/command_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func newReplicaCommand(prerunner pcmd.PreRunner) *cobra.Command {
cmd := &cobra.Command{
Use: "replica",
Short: "Manage Kafka replicas.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireOnPremLogin},
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout},
}

c := &replicaCommand{pcmd.NewAuthenticatedWithMDSCLICommand(cmd, prerunner)}
Expand Down
2 changes: 1 addition & 1 deletion internal/secret/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func New(prerunner pcmd.PreRunner, flagResolver pcmd.FlagResolver, plugin secret
cmd := &cobra.Command{
Use: "secret",
Short: "Manage secrets for Confluent Platform.",
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonCloudLogin},
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout},
}

c := &command{
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/run_requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
RequireCloudLoginOrOnPremLogin = "cloud-login-or-on-prem-login"
RequireNonAPIKeyCloudLogin = "non-api-key-cloud-login"
RequireNonAPIKeyCloudLoginOrOnPremLogin = "non-api-key-cloud-login-or-on-prem-login"
RequireNonCloudLogin = "non-cloud-login"
RequireCloudLogout = "cloud-logout"
RequireOnPremLogin = "on-prem-login"
)

Expand Down Expand Up @@ -45,8 +45,8 @@ func ErrIfMissingRunRequirement(cmd *cobra.Command, cfg *config.Config) error {
f = cfg.CheckIsNonAPIKeyCloudLogin
case RequireNonAPIKeyCloudLoginOrOnPremLogin:
f = cfg.CheckIsNonAPIKeyCloudLoginOrOnPremLogin
case RequireNonCloudLogin:
f = cfg.CheckIsNonCloudLogin
case RequireCloudLogout:
f = cfg.CheckIsCloudLogout
case RequireOnPremLogin:
f = cfg.CheckIsOnPremLogin
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
ErrorMsg: "you must log in to Confluent Cloud with a username and password or log in to Confluent Platform to use this command",
SuggestionsMsg: "Log in with `confluent login` or `confluent login --url <mds-url>`.\n" + signupSuggestion,
}
RequireNonCloudLogin = &errors.RunRequirementError{
RequireCloudLogout = &errors.RunRequirementError{
ErrorMsg: "you must log out of Confluent Cloud to use this command",
SuggestionsMsg: "Log out with `confluent logout`.\n",
}
Expand Down Expand Up @@ -710,9 +710,9 @@ func (c *Config) CheckIsNonAPIKeyCloudLoginOrOnPremLogin() error {
return nil
}

func (c *Config) CheckIsNonCloudLogin() error {
func (c *Config) CheckIsCloudLogout() error {
if c.isCloud() {
return RequireNonCloudLogin
return RequireCloudLogout
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/output/kafka/broker/list-cloud-login.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Error: this is not a Confluent Cloud command. You must log in to Confluent Platform to use this command
Error: you must log out of Confluent Cloud to use this command

Suggestions:
Log in to Confluent Platform with `confluent login --url <mds-url>`.
See available commands with `--help`.
Log out with `confluent logout`.

4 changes: 2 additions & 2 deletions test/fixtures/output/kafka/broker/list-not-logged-in.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error: you must log in to Confluent Platform to use this command
Error: Kafka REST URL not found

Suggestions:
Log in to Confluent Platform with `confluent login --url <mds-url>`.
Use the `--url` flag or set `CONFLUENT_REST_URL`.

0 comments on commit f84f281

Please sign in to comment.