Skip to content

Commit

Permalink
[CLI-955] Verify that input Kafka cluster IDs have the correct prefix (
Browse files Browse the repository at this point in the history
…#1492)

Co-authored-by: Brian Strauch <[email protected]>
  • Loading branch information
sgagniere and brianstrauch authored Nov 3, 2022
1 parent 75a31cb commit 4e3564e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/cmd/kafka/command_cluster_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/confluentinc/cli/internal/pkg/errors"
"github.com/confluentinc/cli/internal/pkg/kafkarest"
"github.com/confluentinc/cli/internal/pkg/output"
"github.com/confluentinc/cli/internal/pkg/resource"
)

var (
Expand Down Expand Up @@ -125,6 +126,9 @@ func (c *clusterCommand) describe(cmd *cobra.Command, args []string) error {

func (c *clusterCommand) getLkcForDescribe(args []string) (string, error) {
if len(args) > 0 {
if resource.LookupType(args[0]) != resource.KafkaCluster {
return "", errors.Errorf(errors.KafkaClusterMissingPrefixErrorMsg, args[0])
}
return args[0], nil
}

Expand Down
3 changes: 3 additions & 0 deletions internal/pkg/dynamic-config/dynamic_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func (d *DynamicContext) GetKafkaClusterForCommand() (*v1.KafkaClusterConfig, er
}

cluster, err := d.FindKafkaCluster(clusterId)
if resource.LookupType(clusterId) != resource.KafkaCluster {
return nil, errors.Errorf(errors.KafkaClusterMissingPrefixErrorMsg, clusterId)
}
return cluster, errors.CatchKafkaNotFoundError(err, clusterId, nil)
}

Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/errors/error_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ const (
"Ensure the cluster is not associated with any active Connect clusters."
ChooseRightEnvironmentSuggestions = "Ensure the cluster ID you entered is valid.\n" +
"Ensure the cluster you are specifying belongs to the currently selected environment with `confluent kafka cluster list`, `confluent environment list`, and `confluent environment use`."
UnknownTopicErrorMsg = `unknown topic "%s"`
MdsUrlNotFoundSuggestions = "Pass the `--url` flag or set the `CONFLUENT_PLATFORM_MDS_URL` environment variable."
UnknownTopicErrorMsg = `unknown topic "%s"`
MdsUrlNotFoundSuggestions = "Pass the `--url` flag or set the `CONFLUENT_PLATFORM_MDS_URL` environment variable."
KafkaClusterMissingPrefixErrorMsg = `Kafka cluster "%s" is missing required prefix "lkc-"`

// kafka topic commands
FailedToCreateProducerErrorMsg = "failed to create producer: %v"
Expand Down

0 comments on commit 4e3564e

Please sign in to comment.