Skip to content

Commit b5ccef1

Browse files
feat: [ManagedKafka] add Managed Kafka ACL API (#8335)
* feat: add Managed Kafka ACL API PiperOrigin-RevId: 762087424 Source-Link: googleapis/googleapis@10878b0 Source-Link: googleapis/googleapis-gen@d9af0dd Copy-Tag: eyJwIjoiTWFuYWdlZEthZmthLy5Pd2xCb3QueWFtbCIsImgiOiJkOWFmMGRkNTE4ZjZlOWVkNzM0YTZjZjRlYmE2ODI5YzAwNDcxNGExIn0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 68c5d41 commit b5ccef1

27 files changed

Lines changed: 3772 additions & 78 deletions
2.39 KB
Binary file not shown.
424 Bytes
Binary file not shown.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/*
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START managedkafka_v1_generated_ManagedKafka_AddAclEntry_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Cloud\ManagedKafka\V1\AclEntry;
28+
use Google\Cloud\ManagedKafka\V1\AddAclEntryRequest;
29+
use Google\Cloud\ManagedKafka\V1\AddAclEntryResponse;
30+
use Google\Cloud\ManagedKafka\V1\Client\ManagedKafkaClient;
31+
32+
/**
33+
* Incremental update: Adds an acl entry to an acl. Creates the acl if it does
34+
* not exist yet.
35+
*
36+
* @param string $formattedAcl The name of the acl to add the acl entry to.
37+
* Structured like:
38+
* `projects/{project}/locations/{location}/clusters/{cluster}/acls/{acl_id}`.
39+
*
40+
* The structure of `acl_id` defines the Resource Pattern (resource_type,
41+
* resource_name, pattern_type) of the acl. See `Acl.name` for
42+
* details. Please see
43+
* {@see ManagedKafkaClient::aclName()} for help formatting this field.
44+
* @param string $aclEntryPrincipal The principal. Specified as Google Cloud account, with the Kafka
45+
* StandardAuthorizer prefix "User:". For example:
46+
* "User:test-kafka-client&#64;test-project.iam.gserviceaccount.com".
47+
* Can be the wildcard "User:*" to refer to all users.
48+
* @param string $aclEntryPermissionType The permission type. Accepted values are (case insensitive):
49+
* ALLOW, DENY.
50+
* @param string $aclEntryOperation The operation type. Allowed values are (case insensitive): ALL,
51+
* READ, WRITE, CREATE, DELETE, ALTER, DESCRIBE, CLUSTER_ACTION,
52+
* DESCRIBE_CONFIGS, ALTER_CONFIGS, and IDEMPOTENT_WRITE. See
53+
* https://kafka.apache.org/documentation/#operations_resources_and_protocols
54+
* for valid combinations of resource_type and operation for different Kafka
55+
* API requests.
56+
* @param string $aclEntryHost The host. Must be set to "*" for Managed Service for Apache
57+
* Kafka.
58+
*/
59+
function add_acl_entry_sample(
60+
string $formattedAcl,
61+
string $aclEntryPrincipal,
62+
string $aclEntryPermissionType,
63+
string $aclEntryOperation,
64+
string $aclEntryHost
65+
): void {
66+
// Create a client.
67+
$managedKafkaClient = new ManagedKafkaClient();
68+
69+
// Prepare the request message.
70+
$aclEntry = (new AclEntry())
71+
->setPrincipal($aclEntryPrincipal)
72+
->setPermissionType($aclEntryPermissionType)
73+
->setOperation($aclEntryOperation)
74+
->setHost($aclEntryHost);
75+
$request = (new AddAclEntryRequest())
76+
->setAcl($formattedAcl)
77+
->setAclEntry($aclEntry);
78+
79+
// Call the API and handle any network failures.
80+
try {
81+
/** @var AddAclEntryResponse $response */
82+
$response = $managedKafkaClient->addAclEntry($request);
83+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
84+
} catch (ApiException $ex) {
85+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
86+
}
87+
}
88+
89+
/**
90+
* Helper to execute the sample.
91+
*
92+
* This sample has been automatically generated and should be regarded as a code
93+
* template only. It will require modifications to work:
94+
* - It may require correct/in-range values for request initialization.
95+
* - It may require specifying regional endpoints when creating the service client,
96+
* please see the apiEndpoint client configuration option for more details.
97+
*/
98+
function callSample(): void
99+
{
100+
$formattedAcl = ManagedKafkaClient::aclName('[PROJECT]', '[LOCATION]', '[CLUSTER]', '[ACL]');
101+
$aclEntryPrincipal = '[PRINCIPAL]';
102+
$aclEntryPermissionType = '[PERMISSION_TYPE]';
103+
$aclEntryOperation = '[OPERATION]';
104+
$aclEntryHost = '[HOST]';
105+
106+
add_acl_entry_sample(
107+
$formattedAcl,
108+
$aclEntryPrincipal,
109+
$aclEntryPermissionType,
110+
$aclEntryOperation,
111+
$aclEntryHost
112+
);
113+
}
114+
// [END managedkafka_v1_generated_ManagedKafka_AddAclEntry_sync]
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/*
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START managedkafka_v1_generated_ManagedKafka_CreateAcl_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Cloud\ManagedKafka\V1\Acl;
28+
use Google\Cloud\ManagedKafka\V1\AclEntry;
29+
use Google\Cloud\ManagedKafka\V1\Client\ManagedKafkaClient;
30+
use Google\Cloud\ManagedKafka\V1\CreateAclRequest;
31+
32+
/**
33+
* Creates a new acl in the given project, location, and cluster.
34+
*
35+
* @param string $formattedParent The parent cluster in which to create the acl.
36+
* Structured like
37+
* `projects/{project}/locations/{location}/clusters/{cluster}`. Please see
38+
* {@see ManagedKafkaClient::clusterName()} for help formatting this field.
39+
* @param string $aclId The ID to use for the acl, which will become the final component
40+
* of the acl's name. The structure of `acl_id` defines the Resource Pattern
41+
* (resource_type, resource_name, pattern_type) of the acl. `acl_id` is
42+
* structured like one of the following:
43+
*
44+
* For acls on the cluster:
45+
* `cluster`
46+
*
47+
* For acls on a single resource within the cluster:
48+
* `topic/{resource_name}`
49+
* `consumerGroup/{resource_name}`
50+
* `transactionalId/{resource_name}`
51+
*
52+
* For acls on all resources that match a prefix:
53+
* `topicPrefixed/{resource_name}`
54+
* `consumerGroupPrefixed/{resource_name}`
55+
* `transactionalIdPrefixed/{resource_name}`
56+
*
57+
* For acls on all resources of a given type (i.e. the wildcard literal "*"):
58+
* `allTopics` (represents `topic/*`)
59+
* `allConsumerGroups` (represents `consumerGroup/*`)
60+
* `allTransactionalIds` (represents `transactionalId/*`)
61+
* @param string $aclAclEntriesPrincipal The principal. Specified as Google Cloud account, with the Kafka
62+
* StandardAuthorizer prefix "User:". For example:
63+
* "User:test-kafka-client&#64;test-project.iam.gserviceaccount.com".
64+
* Can be the wildcard "User:*" to refer to all users.
65+
* @param string $aclAclEntriesPermissionType The permission type. Accepted values are (case insensitive):
66+
* ALLOW, DENY.
67+
* @param string $aclAclEntriesOperation The operation type. Allowed values are (case insensitive): ALL,
68+
* READ, WRITE, CREATE, DELETE, ALTER, DESCRIBE, CLUSTER_ACTION,
69+
* DESCRIBE_CONFIGS, ALTER_CONFIGS, and IDEMPOTENT_WRITE. See
70+
* https://kafka.apache.org/documentation/#operations_resources_and_protocols
71+
* for valid combinations of resource_type and operation for different Kafka
72+
* API requests.
73+
* @param string $aclAclEntriesHost The host. Must be set to "*" for Managed Service for Apache
74+
* Kafka.
75+
*/
76+
function create_acl_sample(
77+
string $formattedParent,
78+
string $aclId,
79+
string $aclAclEntriesPrincipal,
80+
string $aclAclEntriesPermissionType,
81+
string $aclAclEntriesOperation,
82+
string $aclAclEntriesHost
83+
): void {
84+
// Create a client.
85+
$managedKafkaClient = new ManagedKafkaClient();
86+
87+
// Prepare the request message.
88+
$aclEntry = (new AclEntry())
89+
->setPrincipal($aclAclEntriesPrincipal)
90+
->setPermissionType($aclAclEntriesPermissionType)
91+
->setOperation($aclAclEntriesOperation)
92+
->setHost($aclAclEntriesHost);
93+
$aclAclEntries = [$aclEntry,];
94+
$acl = (new Acl())
95+
->setAclEntries($aclAclEntries);
96+
$request = (new CreateAclRequest())
97+
->setParent($formattedParent)
98+
->setAclId($aclId)
99+
->setAcl($acl);
100+
101+
// Call the API and handle any network failures.
102+
try {
103+
/** @var Acl $response */
104+
$response = $managedKafkaClient->createAcl($request);
105+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
106+
} catch (ApiException $ex) {
107+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
108+
}
109+
}
110+
111+
/**
112+
* Helper to execute the sample.
113+
*
114+
* This sample has been automatically generated and should be regarded as a code
115+
* template only. It will require modifications to work:
116+
* - It may require correct/in-range values for request initialization.
117+
* - It may require specifying regional endpoints when creating the service client,
118+
* please see the apiEndpoint client configuration option for more details.
119+
*/
120+
function callSample(): void
121+
{
122+
$formattedParent = ManagedKafkaClient::clusterName('[PROJECT]', '[LOCATION]', '[CLUSTER]');
123+
$aclId = '[ACL_ID]';
124+
$aclAclEntriesPrincipal = '[PRINCIPAL]';
125+
$aclAclEntriesPermissionType = '[PERMISSION_TYPE]';
126+
$aclAclEntriesOperation = '[OPERATION]';
127+
$aclAclEntriesHost = '[HOST]';
128+
129+
create_acl_sample(
130+
$formattedParent,
131+
$aclId,
132+
$aclAclEntriesPrincipal,
133+
$aclAclEntriesPermissionType,
134+
$aclAclEntriesOperation,
135+
$aclAclEntriesHost
136+
);
137+
}
138+
// [END managedkafka_v1_generated_ManagedKafka_CreateAcl_sync]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/*
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START managedkafka_v1_generated_ManagedKafka_DeleteAcl_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Cloud\ManagedKafka\V1\Client\ManagedKafkaClient;
28+
use Google\Cloud\ManagedKafka\V1\DeleteAclRequest;
29+
30+
/**
31+
* Deletes an acl.
32+
*
33+
* @param string $formattedName The name of the acl to delete.
34+
* Structured like:
35+
* `projects/{project}/locations/{location}/clusters/{cluster}/acls/{acl_id}`.
36+
*
37+
* The structure of `acl_id` defines the Resource Pattern (resource_type,
38+
* resource_name, pattern_type) of the acl. See `Acl.name` for details. Please see
39+
* {@see ManagedKafkaClient::aclName()} for help formatting this field.
40+
*/
41+
function delete_acl_sample(string $formattedName): void
42+
{
43+
// Create a client.
44+
$managedKafkaClient = new ManagedKafkaClient();
45+
46+
// Prepare the request message.
47+
$request = (new DeleteAclRequest())
48+
->setName($formattedName);
49+
50+
// Call the API and handle any network failures.
51+
try {
52+
$managedKafkaClient->deleteAcl($request);
53+
printf('Call completed successfully.' . PHP_EOL);
54+
} catch (ApiException $ex) {
55+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
56+
}
57+
}
58+
59+
/**
60+
* Helper to execute the sample.
61+
*
62+
* This sample has been automatically generated and should be regarded as a code
63+
* template only. It will require modifications to work:
64+
* - It may require correct/in-range values for request initialization.
65+
* - It may require specifying regional endpoints when creating the service client,
66+
* please see the apiEndpoint client configuration option for more details.
67+
*/
68+
function callSample(): void
69+
{
70+
$formattedName = ManagedKafkaClient::aclName('[PROJECT]', '[LOCATION]', '[CLUSTER]', '[ACL]');
71+
72+
delete_acl_sample($formattedName);
73+
}
74+
// [END managedkafka_v1_generated_ManagedKafka_DeleteAcl_sync]

0 commit comments

Comments
 (0)