diff --git a/internal/api-key/command.go b/internal/api-key/command.go index c5409f4802..2708affd7b 100644 --- a/internal/api-key/command.go +++ b/internal/api-key/command.go @@ -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) @@ -108,9 +108,9 @@ func (c *command) addResourceFlag(cmd *cobra.Command, isStore bool) { i++ } - // TODO: update the suggestions when the suggestions[i] related with Tableflow is ready if !isStore { suggestions = append(suggestions, "cloud") + suggestions = append(suggestions, "global") suggestions = append(suggestions, "flink") suggestions = append(suggestions, "tableflow") } @@ -192,7 +192,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) @@ -232,6 +232,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" diff --git a/internal/api-key/command_create.go b/internal/api-key/command_create.go index b942f8ba79..521d5a8f3f 100644 --- a/internal/api-key/command_create.go +++ b/internal/api-key/command_create.go @@ -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{ + 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", @@ -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 { diff --git a/internal/api-key/command_list.go b/internal/api-key/command_list.go index d539e291e0..dfdd2a0294 100644 --- a/internal/api-key/command_list.go +++ b/internal/api-key/command_list.go @@ -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 } @@ -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 diff --git a/internal/api-key/command_test.go b/internal/api-key/command_test.go index b66304019c..89a5fb8fbb 100644 --- a/internal/api-key/command_test.go +++ b/internal/api-key/command_test.go @@ -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")})) diff --git a/internal/local/dir/etc/confluent-control-center/control-center-local.properties b/internal/local/dir/etc/confluent-control-center/control-center-local.properties new file mode 100644 index 0000000000..8602bca970 --- /dev/null +++ b/internal/local/dir/etc/confluent-control-center/control-center-local.properties @@ -0,0 +1,2 @@ +confluent.controlcenter.alertmanager.config.file=abc +confluent.controlcenter.prometheus.rules.file=def diff --git a/pkg/resource/resource.go b/pkg/resource/resource.go index a56592ddd9..9c3d903d10 100644 --- a/pkg/resource/resource.go +++ b/pkg/resource/resource.go @@ -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" @@ -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 } diff --git a/test/api_key_test.go b/test/api_key_test.go index 2efbff3ea3..f7cc92d0cb 100644 --- a/test/api_key_test.go +++ b/test/api_key_test.go @@ -160,6 +160,7 @@ func (s *CLITestSuite) TestApiKeyCreate() { tests := []CLITest{ {args: "api-key create --resource flink --cloud aws --region us-east-1", fixture: "api-key/create-flink.golden"}, {args: "api-key create --resource lkc-ab123 --service-account sa-123456", fixture: "api-key/55.golden", exitCode: 1}, + {args: "api-key create --description human-output --resource global", fixture: "api-key/create-global.golden"}, } for _, test := range tests { @@ -186,8 +187,8 @@ func (s *CLITestSuite) TestApiKeyDescribe() { func (s *CLITestSuite) TestApiKeyDelete() { tests := []CLITest{ // delete multiple API keys - {args: "api-key delete MYKEY7 MYKEY8 MYKEY19", fixture: "api-key/delete/multiple-fail.golden", exitCode: 1}, - {args: "api-key delete MYKEY6 MYKEY18 MYKEY19", fixture: "api-key/delete/multiple-fail-plural.golden", exitCode: 1}, + {args: "api-key delete MYKEY7 MYKEY8 MYKEY20", fixture: "api-key/delete/multiple-fail.golden", exitCode: 1}, + {args: "api-key delete MYKEY6 MYKEY18 MYKEY20", fixture: "api-key/delete/multiple-fail-plural.golden", exitCode: 1}, {args: "api-key delete MYKEY7 MYKEY8", input: "n\n", fixture: "api-key/delete/multiple-refuse.golden"}, {args: "api-key delete MYKEY7 MYKEY8", input: "y\n", fixture: "api-key/delete/multiple-success.golden"}, } diff --git a/test/fixtures/output/api-key/54.golden b/test/fixtures/output/api-key/54.golden index f3d7781aab..1d76e0d519 100644 --- a/test/fixtures/output/api-key/54.golden +++ b/test/fixtures/output/api-key/54.golden @@ -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 @@ -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). diff --git a/test/fixtures/output/api-key/create-global.golden b/test/fixtures/output/api-key/create-global.golden new file mode 100644 index 0000000000..1247dbc298 --- /dev/null +++ b/test/fixtures/output/api-key/create-global.golden @@ -0,0 +1,6 @@ +It may take a couple of minutes for the API key to be ready. +Save the API key and secret. The secret is not retrievable later. ++------------+------------+ +| API Key | MYKEY19 | +| API Secret | MYSECRET19 | ++------------+------------+ diff --git a/test/fixtures/output/api-key/create-help.golden b/test/fixtures/output/api-key/create-help.golden index 60cfbfc6c8..6377e467a8 100644 --- a/test/fixtures/output/api-key/create-help.golden +++ b/test/fixtures/output/api-key/create-help.golden @@ -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 @@ -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). diff --git a/test/fixtures/output/api-key/create-resource-autocomplete.golden b/test/fixtures/output/api-key/create-resource-autocomplete.golden index a770c21b16..6322a27a53 100644 --- a/test/fixtures/output/api-key/create-resource-autocomplete.golden +++ b/test/fixtures/output/api-key/create-resource-autocomplete.golden @@ -5,6 +5,7 @@ lsrc-1234 account schema-registry lksqlc-ksql5 account ksql lksqlc-woooo kay cee queue elle cloud +global flink tableflow :4 diff --git a/test/fixtures/output/api-key/delete/multiple-fail-plural.golden b/test/fixtures/output/api-key/delete/multiple-fail-plural.golden index 08c1f300d0..1aac64a615 100644 --- a/test/fixtures/output/api-key/delete/multiple-fail-plural.golden +++ b/test/fixtures/output/api-key/delete/multiple-fail-plural.golden @@ -1,4 +1,4 @@ -Error: API key "MYKEY19" not found +Error: API key "MYKEY20" not found Suggestions: List available API keys with `confluent api-key list`. diff --git a/test/fixtures/output/api-key/delete/multiple-fail.golden b/test/fixtures/output/api-key/delete/multiple-fail.golden index 08c1f300d0..1aac64a615 100644 --- a/test/fixtures/output/api-key/delete/multiple-fail.golden +++ b/test/fixtures/output/api-key/delete/multiple-fail.golden @@ -1,4 +1,4 @@ -Error: API key "MYKEY19" not found +Error: API key "MYKEY20" not found Suggestions: List available API keys with `confluent api-key list`. diff --git a/test/fixtures/output/api-key/describe-autocomplete.golden b/test/fixtures/output/api-key/describe-autocomplete.golden index f5438768bd..56b23624d7 100644 --- a/test/fixtures/output/api-key/describe-autocomplete.golden +++ b/test/fixtures/output/api-key/describe-autocomplete.golden @@ -12,6 +12,7 @@ MYKEY15 yaml-output MYKEY16 my-cool-app MYKEY17 MYKEY18 +MYKEY19 human-output MYKEY2 MYKEY3 MYKEY4 my-cool-app diff --git a/test/fixtures/output/api-key/list-help.golden b/test/fixtures/output/api-key/list-help.golden index cd4ae61af3..3a871fcd69 100644 --- a/test/fixtures/output/api-key/list-help.golden +++ b/test/fixtures/output/api-key/list-help.golden @@ -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. diff --git a/test/test-server/iam_handlers.go b/test/test-server/iam_handlers.go index 0c67c13560..e86cd4e617 100644 --- a/test/test-server/iam_handlers.go +++ b/test/test-server/iam_handlers.go @@ -176,6 +176,9 @@ func getKind(id string) string { if id == "cloud" { return "Cloud" } + if id == "global" { + return "Global" + } if id == "tableflow" { return "Tableflow" }