Skip to content

Commit 10b0fa1

Browse files
feat: [NetworkSecurity] add address groups API (#8552)
* feat: add address groups API PiperOrigin-RevId: 802118490 Source-Link: googleapis/googleapis@3346b30 Source-Link: googleapis/googleapis-gen@066cd0c Copy-Tag: eyJwIjoiTmV0d29ya1NlY3VyaXR5Ly5Pd2xCb3QueWFtbCIsImgiOiIwNjZjZDBjOWM1NmRhMjJiMGQ1MmI0Yjg5M2QxOTBiOWQyYjIxODVhIn0= * 🦉 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 4e019e7 commit 10b0fa1

56 files changed

Lines changed: 11313 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
9.24 KB
Binary file not shown.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 networksecurity_v1_generated_AddressGroupService_AddAddressGroupItems_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\NetworkSecurity\V1\AddAddressGroupItemsRequest;
29+
use Google\Cloud\NetworkSecurity\V1\AddressGroup;
30+
use Google\Cloud\NetworkSecurity\V1\Client\AddressGroupServiceClient;
31+
use Google\Rpc\Status;
32+
33+
/**
34+
* Adds items to an address group.
35+
*
36+
* @param string $formattedAddressGroup A name of the AddressGroup to add items to. Must be in the format
37+
* `projects|organization/&#42;/locations/{location}/addressGroups/*`. Please see
38+
* {@see AddressGroupServiceClient::addressGroupName()} for help formatting this field.
39+
* @param string $itemsElement List of items to add.
40+
*/
41+
function add_address_group_items_sample(string $formattedAddressGroup, string $itemsElement): void
42+
{
43+
// Create a client.
44+
$addressGroupServiceClient = new AddressGroupServiceClient();
45+
46+
// Prepare the request message.
47+
$items = [$itemsElement,];
48+
$request = (new AddAddressGroupItemsRequest())
49+
->setAddressGroup($formattedAddressGroup)
50+
->setItems($items);
51+
52+
// Call the API and handle any network failures.
53+
try {
54+
/** @var OperationResponse $response */
55+
$response = $addressGroupServiceClient->addAddressGroupItems($request);
56+
$response->pollUntilComplete();
57+
58+
if ($response->operationSucceeded()) {
59+
/** @var AddressGroup $result */
60+
$result = $response->getResult();
61+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
62+
} else {
63+
/** @var Status $error */
64+
$error = $response->getError();
65+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
66+
}
67+
} catch (ApiException $ex) {
68+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
69+
}
70+
}
71+
72+
/**
73+
* Helper to execute the sample.
74+
*
75+
* This sample has been automatically generated and should be regarded as a code
76+
* template only. It will require modifications to work:
77+
* - It may require correct/in-range values for request initialization.
78+
* - It may require specifying regional endpoints when creating the service client,
79+
* please see the apiEndpoint client configuration option for more details.
80+
*/
81+
function callSample(): void
82+
{
83+
$formattedAddressGroup = AddressGroupServiceClient::addressGroupName(
84+
'[PROJECT]',
85+
'[LOCATION]',
86+
'[ADDRESS_GROUP]'
87+
);
88+
$itemsElement = '[ITEMS]';
89+
90+
add_address_group_items_sample($formattedAddressGroup, $itemsElement);
91+
}
92+
// [END networksecurity_v1_generated_AddressGroupService_AddAddressGroupItems_sync]
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 networksecurity_v1_generated_AddressGroupService_CloneAddressGroupItems_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\NetworkSecurity\V1\AddressGroup;
29+
use Google\Cloud\NetworkSecurity\V1\Client\AddressGroupServiceClient;
30+
use Google\Cloud\NetworkSecurity\V1\CloneAddressGroupItemsRequest;
31+
use Google\Rpc\Status;
32+
33+
/**
34+
* Clones items from one address group to another.
35+
*
36+
* @param string $formattedAddressGroup A name of the AddressGroup to clone items to. Must be in the
37+
* format `projects|organization/&#42;/locations/{location}/addressGroups/*`. Please see
38+
* {@see AddressGroupServiceClient::addressGroupName()} for help formatting this field.
39+
* @param string $formattedSourceAddressGroup Source address group to clone items from. Please see
40+
* {@see AddressGroupServiceClient::addressGroupName()} for help formatting this field.
41+
*/
42+
function clone_address_group_items_sample(
43+
string $formattedAddressGroup,
44+
string $formattedSourceAddressGroup
45+
): void {
46+
// Create a client.
47+
$addressGroupServiceClient = new AddressGroupServiceClient();
48+
49+
// Prepare the request message.
50+
$request = (new CloneAddressGroupItemsRequest())
51+
->setAddressGroup($formattedAddressGroup)
52+
->setSourceAddressGroup($formattedSourceAddressGroup);
53+
54+
// Call the API and handle any network failures.
55+
try {
56+
/** @var OperationResponse $response */
57+
$response = $addressGroupServiceClient->cloneAddressGroupItems($request);
58+
$response->pollUntilComplete();
59+
60+
if ($response->operationSucceeded()) {
61+
/** @var AddressGroup $result */
62+
$result = $response->getResult();
63+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
64+
} else {
65+
/** @var Status $error */
66+
$error = $response->getError();
67+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
68+
}
69+
} catch (ApiException $ex) {
70+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
71+
}
72+
}
73+
74+
/**
75+
* Helper to execute the sample.
76+
*
77+
* This sample has been automatically generated and should be regarded as a code
78+
* template only. It will require modifications to work:
79+
* - It may require correct/in-range values for request initialization.
80+
* - It may require specifying regional endpoints when creating the service client,
81+
* please see the apiEndpoint client configuration option for more details.
82+
*/
83+
function callSample(): void
84+
{
85+
$formattedAddressGroup = AddressGroupServiceClient::addressGroupName(
86+
'[PROJECT]',
87+
'[LOCATION]',
88+
'[ADDRESS_GROUP]'
89+
);
90+
$formattedSourceAddressGroup = AddressGroupServiceClient::addressGroupName(
91+
'[PROJECT]',
92+
'[LOCATION]',
93+
'[ADDRESS_GROUP]'
94+
);
95+
96+
clone_address_group_items_sample($formattedAddressGroup, $formattedSourceAddressGroup);
97+
}
98+
// [END networksecurity_v1_generated_AddressGroupService_CloneAddressGroupItems_sync]
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 networksecurity_v1_generated_AddressGroupService_CreateAddressGroup_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\NetworkSecurity\V1\AddressGroup;
29+
use Google\Cloud\NetworkSecurity\V1\AddressGroup\Type;
30+
use Google\Cloud\NetworkSecurity\V1\Client\AddressGroupServiceClient;
31+
use Google\Cloud\NetworkSecurity\V1\CreateAddressGroupRequest;
32+
use Google\Rpc\Status;
33+
34+
/**
35+
* Creates a new address group in a given project and location.
36+
*
37+
* @param string $formattedParent The parent resource of the AddressGroup. Must be in the
38+
* format `projects/&#42;/locations/{location}`. Please see
39+
* {@see AddressGroupServiceClient::organizationLocationName()} for help formatting this field.
40+
* @param string $addressGroupId Short name of the AddressGroup resource to be created.
41+
* This value should be 1-63 characters long, containing only
42+
* letters, numbers, hyphens, and underscores, and should not start
43+
* with a number. E.g. "authz_policy".
44+
* @param string $addressGroupName Name of the AddressGroup resource. It matches pattern
45+
* `projects/&#42;/locations/{location}/addressGroups/<address_group>`.
46+
* @param int $addressGroupType The type of the Address Group. Possible values are "IPv4" or
47+
* "IPV6".
48+
* @param int $addressGroupCapacity Capacity of the Address Group
49+
*/
50+
function create_address_group_sample(
51+
string $formattedParent,
52+
string $addressGroupId,
53+
string $addressGroupName,
54+
int $addressGroupType,
55+
int $addressGroupCapacity
56+
): void {
57+
// Create a client.
58+
$addressGroupServiceClient = new AddressGroupServiceClient();
59+
60+
// Prepare the request message.
61+
$addressGroup = (new AddressGroup())
62+
->setName($addressGroupName)
63+
->setType($addressGroupType)
64+
->setCapacity($addressGroupCapacity);
65+
$request = (new CreateAddressGroupRequest())
66+
->setParent($formattedParent)
67+
->setAddressGroupId($addressGroupId)
68+
->setAddressGroup($addressGroup);
69+
70+
// Call the API and handle any network failures.
71+
try {
72+
/** @var OperationResponse $response */
73+
$response = $addressGroupServiceClient->createAddressGroup($request);
74+
$response->pollUntilComplete();
75+
76+
if ($response->operationSucceeded()) {
77+
/** @var AddressGroup $result */
78+
$result = $response->getResult();
79+
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
80+
} else {
81+
/** @var Status $error */
82+
$error = $response->getError();
83+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
84+
}
85+
} catch (ApiException $ex) {
86+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
87+
}
88+
}
89+
90+
/**
91+
* Helper to execute the sample.
92+
*
93+
* This sample has been automatically generated and should be regarded as a code
94+
* template only. It will require modifications to work:
95+
* - It may require correct/in-range values for request initialization.
96+
* - It may require specifying regional endpoints when creating the service client,
97+
* please see the apiEndpoint client configuration option for more details.
98+
*/
99+
function callSample(): void
100+
{
101+
$formattedParent = AddressGroupServiceClient::organizationLocationName(
102+
'[ORGANIZATION]',
103+
'[LOCATION]'
104+
);
105+
$addressGroupId = '[ADDRESS_GROUP_ID]';
106+
$addressGroupName = '[NAME]';
107+
$addressGroupType = Type::TYPE_UNSPECIFIED;
108+
$addressGroupCapacity = 0;
109+
110+
create_address_group_sample(
111+
$formattedParent,
112+
$addressGroupId,
113+
$addressGroupName,
114+
$addressGroupType,
115+
$addressGroupCapacity
116+
);
117+
}
118+
// [END networksecurity_v1_generated_AddressGroupService_CreateAddressGroup_sync]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 networksecurity_v1_generated_AddressGroupService_DeleteAddressGroup_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\NetworkSecurity\V1\Client\AddressGroupServiceClient;
29+
use Google\Cloud\NetworkSecurity\V1\DeleteAddressGroupRequest;
30+
use Google\Rpc\Status;
31+
32+
/**
33+
* Deletes a single address group.
34+
*
35+
* @param string $formattedName A name of the AddressGroup to delete. Must be in the format
36+
* `projects/&#42;/locations/{location}/addressGroups/*`. Please see
37+
* {@see AddressGroupServiceClient::addressGroupName()} for help formatting this field.
38+
*/
39+
function delete_address_group_sample(string $formattedName): void
40+
{
41+
// Create a client.
42+
$addressGroupServiceClient = new AddressGroupServiceClient();
43+
44+
// Prepare the request message.
45+
$request = (new DeleteAddressGroupRequest())
46+
->setName($formattedName);
47+
48+
// Call the API and handle any network failures.
49+
try {
50+
/** @var OperationResponse $response */
51+
$response = $addressGroupServiceClient->deleteAddressGroup($request);
52+
$response->pollUntilComplete();
53+
54+
if ($response->operationSucceeded()) {
55+
printf('Operation completed successfully.' . PHP_EOL);
56+
} else {
57+
/** @var Status $error */
58+
$error = $response->getError();
59+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
60+
}
61+
} catch (ApiException $ex) {
62+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
63+
}
64+
}
65+
66+
/**
67+
* Helper to execute the sample.
68+
*
69+
* This sample has been automatically generated and should be regarded as a code
70+
* template only. It will require modifications to work:
71+
* - It may require correct/in-range values for request initialization.
72+
* - It may require specifying regional endpoints when creating the service client,
73+
* please see the apiEndpoint client configuration option for more details.
74+
*/
75+
function callSample(): void
76+
{
77+
$formattedName = AddressGroupServiceClient::addressGroupName(
78+
'[PROJECT]',
79+
'[LOCATION]',
80+
'[ADDRESS_GROUP]'
81+
);
82+
83+
delete_address_group_sample($formattedName);
84+
}
85+
// [END networksecurity_v1_generated_AddressGroupService_DeleteAddressGroup_sync]

0 commit comments

Comments
 (0)