Skip to content
7 changes: 5 additions & 2 deletions internal/api-key/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func New(prerunner pcmd.PreRunner) *cobra.Command {
func (c *command) addResourceFlag(cmd *cobra.Command, isStore bool) {
description := "The ID of the resource the API key is for."
if !isStore {
description += ` Use "cloud" for a Cloud API key, "flink" for a Flink API key, or "tableflow" for a Tableflow API key.`
description += ` Use "cloud" for a Cloud API key, "global" for a Global API key, "flink" for a Flink API key, or "tableflow" for a Tableflow API key.`
}

cmd.Flags().String("resource", "", description)
Expand Down Expand Up @@ -111,6 +111,7 @@ func (c *command) addResourceFlag(cmd *cobra.Command, isStore bool) {
// TODO: update the suggestions when the suggestions[i] related with Tableflow is ready
Comment thread
taohaowang marked this conversation as resolved.
Outdated
if !isStore {
suggestions = append(suggestions, "cloud")
suggestions = append(suggestions, "global")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: keep the alphabetical ordering.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the order.

suggestions = append(suggestions, "flink")
suggestions = append(suggestions, "tableflow")
}
Expand Down Expand Up @@ -192,7 +193,7 @@ func (c *command) resolveResourceId(cmd *cobra.Command, v2Client *ccloudv2.Clien
var apiKey string

switch resourceType {
case presource.Cloud, presource.Flink, presource.Tableflow:
case presource.Cloud, presource.Flink, presource.Tableflow, presource.Global:
break
case presource.KafkaCluster:
cluster, err := kafka.FindCluster(c.V2Client, c.Context, resource)
Expand Down Expand Up @@ -232,6 +233,8 @@ func getResourceType(resource apikeysv2.ObjectReference) string {
switch resource.GetKind() {
case "Cloud":
return "cloud"
case "Global":
return "global"
case "Cluster":
if getResourceApi(resource) == "cmk" {
return "kafka"
Expand Down
6 changes: 6 additions & 0 deletions internal/api-key/command_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (c *command) newCreateCommand() *cobra.Command {
Text: "Create a Cloud API key:",
Code: "confluent api-key create --resource cloud",
},
examples.Example{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create the dedicated integration test in api_key_test.go to verify the global API key?

Something like:

{args: "api-key create --description human-output --resource global", fixture: "api-key/xxx.golden"},

Text: "Create a Global API key:",
Code: "confluent api-key create --resource global",
},
examples.Example{
Text: `Create a Flink API key for region "N. Virginia (us-east-1)":`,
Code: "confluent api-key create --resource flink --cloud aws --region us-east-1",
Expand Down Expand Up @@ -115,6 +119,8 @@ func (c *command) create(cmd *cobra.Command, _ []string) error {
switch resourceType {
case resource.Cloud:
key.Spec.Resource.Id = resource.Cloud
case resource.Global:
key.Spec.Resource.Id = resource.Global
case resource.Flink:
environmentId, err := c.Context.EnvironmentId()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/api-key/command_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *command) list(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
if resourceType == presource.Cloud || resourceType == presource.Tableflow {
if resourceType == presource.Cloud || resourceType == presource.Tableflow || resourceType == presource.Global {
clusterId = resourceType
}

Expand Down Expand Up @@ -185,7 +185,7 @@ func (c *command) getEmail(resourceId string, auditLogServiceAccountId int32, re
}

func getResourceId(id string) string {
if id == presource.Cloud || id == presource.Tableflow {
if id == presource.Cloud || id == presource.Tableflow || id == presource.Global {
return ""
}
return id
Expand Down
1 change: 1 addition & 0 deletions internal/api-key/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

func TestGetResourceType(t *testing.T) {
require.Equal(t, "cloud", getResourceType(apikeysv2.ObjectReference{Kind: apikeysv2.PtrString("Cloud")}))
require.Equal(t, "global", getResourceType(apikeysv2.ObjectReference{Kind: apikeysv2.PtrString("Global")}))
require.Equal(t, "flink-region", getResourceType(apikeysv2.ObjectReference{ApiVersion: apikeysv2.PtrString("fcpm/v2"), Kind: apikeysv2.PtrString("Region")}))
require.Equal(t, "kafka", getResourceType(apikeysv2.ObjectReference{ApiVersion: apikeysv2.PtrString("cmk/v2"), Kind: apikeysv2.PtrString("Cluster")}))
require.Equal(t, "ksql", getResourceType(apikeysv2.ObjectReference{Kind: apikeysv2.PtrString("ksqlDB")}))
Expand Down
3 changes: 2 additions & 1 deletion pkg/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
FlinkStatement = "Flink SQL statement"
FlinkConnection = "Flink connection"
Gateway = "gateway"
Global = "global"
IdentityPool = "identity pool"
IdentityProvider = "identity provider"
IpGroup = "IP group"
Expand Down Expand Up @@ -144,7 +145,7 @@ var resourceToPrefix = map[string]string{
}

func LookupType(id string) string {
if id == Cloud || id == Flink || id == Tableflow {
if id == Cloud || id == Flink || id == Tableflow || id == Global {
return id
}

Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/output/api-key/54.golden
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Create a Cloud API key:

$ confluent api-key create --resource cloud

Create a Global API key:

$ confluent api-key create --resource global

Create a Flink API key for region "N. Virginia (us-east-1)":

$ confluent api-key create --resource flink --cloud aws --region us-east-1
Expand All @@ -32,7 +36,7 @@ Create a Tableflow API key:
$ confluent api-key create --resource tableflow

Flags:
--resource string REQUIRED: The ID of the resource the API key is for. Use "cloud" for a Cloud API key, "flink" for a Flink API key, or "tableflow" for a Tableflow API key.
--resource string REQUIRED: The ID of the resource the API key is for. Use "cloud" for a Cloud API key, "global" for a Global API key, "flink" for a Flink API key, or "tableflow" for a Tableflow API key.
--description string Description of API key.
--cloud string Specify the cloud provider as "aws", "azure", or "gcp".
--region string Cloud region for Flink (use "confluent flink region list" to see all).
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/output/api-key/create-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Create a Cloud API key:

$ confluent api-key create --resource cloud

Create a Global API key:

$ confluent api-key create --resource global

Create a Flink API key for region "N. Virginia (us-east-1)":

$ confluent api-key create --resource flink --cloud aws --region us-east-1
Expand All @@ -33,7 +37,7 @@ Create a Tableflow API key:
$ confluent api-key create --resource tableflow

Flags:
--resource string REQUIRED: The ID of the resource the API key is for. Use "cloud" for a Cloud API key, "flink" for a Flink API key, or "tableflow" for a Tableflow API key.
--resource string REQUIRED: The ID of the resource the API key is for. Use "cloud" for a Cloud API key, "global" for a Global API key, "flink" for a Flink API key, or "tableflow" for a Tableflow API key.
--description string Description of API key.
--cloud string Specify the cloud provider as "aws", "azure", or "gcp".
--region string Cloud region for Flink (use "confluent flink region list" to see all).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ lsrc-1234 account schema-registry
lksqlc-ksql5 account ksql
lksqlc-woooo kay cee queue elle
cloud
global
flink
tableflow
:4
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/api-key/list-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ List the API keys that belong to service account "sa-123456" on cluster "lkc-123
$ confluent api-key list --resource lkc-123456 --service-account sa-123456

Flags:
--resource string The ID of the resource the API key is for. Use "cloud" for a Cloud API key, "flink" for a Flink API key, or "tableflow" for a Tableflow API key.
--resource string The ID of the resource the API key is for. Use "cloud" for a Cloud API key, "global" for a Global API key, "flink" for a Flink API key, or "tableflow" for a Tableflow API key.
--current-user Show only API keys belonging to current user.
--environment string Environment ID.
--service-account string Service account ID.
Expand Down