Skip to content

Commit ee2c33c

Browse files
feat: [Kms] Added DeleteCryptoKey and DeleteCryptoKeyVersion RPCs to permanently remove resources (#8919)
* feat: Added DeleteCryptoKey and DeleteCryptoKeyVersion RPCs to permanently remove resources feat: Introduced the RetiredResource resource to track records of deleted keys and prevent the reuse of their resource names feat: Added ListRetiredResources and GetRetiredResource RPCs to manage and view these records PiperOrigin-RevId: 868670725 Source-Link: googleapis/googleapis@f248ed0 Source-Link: googleapis/googleapis-gen@78b3172 Copy-Tag: eyJwIjoiS21zLy5Pd2xCb3QueWFtbCIsImgiOiI3OGIzMTcyMTZhOTYxZTEwZjQyNjQ4N2YxMDk3MjgwNDkxMmI4NWVjIn0= * 🦉 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 389027c commit ee2c33c

20 files changed

Lines changed: 2042 additions & 0 deletions

Kms/metadata/V1/Resources.php

317 Bytes
Binary file not shown.

Kms/metadata/V1/Service.php

1.71 KB
Binary file not shown.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/*
3+
* Copyright 2026 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 cloudkms_v1_generated_KeyManagementService_DeleteCryptoKey_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Kms\V1\Client\KeyManagementServiceClient;
29+
use Google\Cloud\Kms\V1\DeleteCryptoKeyRequest;
30+
use Google\Rpc\Status;
31+
32+
/**
33+
* Permanently deletes the given [CryptoKey][google.cloud.kms.v1.CryptoKey].
34+
* All child [CryptoKeyVersions][google.cloud.kms.v1.CryptoKeyVersion] must
35+
* have been previously deleted using
36+
* [KeyManagementService.DeleteCryptoKeyVersion][google.cloud.kms.v1.KeyManagementService.DeleteCryptoKeyVersion].
37+
* The specified crypto key will be immediately and permanently deleted upon
38+
* calling this method. This action cannot be undone.
39+
*
40+
* @param string $formattedName The [name][google.cloud.kms.v1.CryptoKey.name] of the
41+
* [CryptoKey][google.cloud.kms.v1.CryptoKey] to delete. Please see
42+
* {@see KeyManagementServiceClient::cryptoKeyName()} for help formatting this field.
43+
*/
44+
function delete_crypto_key_sample(string $formattedName): void
45+
{
46+
// Create a client.
47+
$keyManagementServiceClient = new KeyManagementServiceClient();
48+
49+
// Prepare the request message.
50+
$request = (new DeleteCryptoKeyRequest())
51+
->setName($formattedName);
52+
53+
// Call the API and handle any network failures.
54+
try {
55+
/** @var OperationResponse $response */
56+
$response = $keyManagementServiceClient->deleteCryptoKey($request);
57+
$response->pollUntilComplete();
58+
59+
if ($response->operationSucceeded()) {
60+
printf('Operation completed successfully.' . PHP_EOL);
61+
} else {
62+
/** @var Status $error */
63+
$error = $response->getError();
64+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
65+
}
66+
} catch (ApiException $ex) {
67+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
68+
}
69+
}
70+
71+
/**
72+
* Helper to execute the sample.
73+
*
74+
* This sample has been automatically generated and should be regarded as a code
75+
* template only. It will require modifications to work:
76+
* - It may require correct/in-range values for request initialization.
77+
* - It may require specifying regional endpoints when creating the service client,
78+
* please see the apiEndpoint client configuration option for more details.
79+
*/
80+
function callSample(): void
81+
{
82+
$formattedName = KeyManagementServiceClient::cryptoKeyName(
83+
'[PROJECT]',
84+
'[LOCATION]',
85+
'[KEY_RING]',
86+
'[CRYPTO_KEY]'
87+
);
88+
89+
delete_crypto_key_sample($formattedName);
90+
}
91+
// [END cloudkms_v1_generated_KeyManagementService_DeleteCryptoKey_sync]
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/*
3+
* Copyright 2026 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 cloudkms_v1_generated_KeyManagementService_DeleteCryptoKeyVersion_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\OperationResponse;
28+
use Google\Cloud\Kms\V1\Client\KeyManagementServiceClient;
29+
use Google\Cloud\Kms\V1\DeleteCryptoKeyVersionRequest;
30+
use Google\Rpc\Status;
31+
32+
/**
33+
* Permanently deletes the given
34+
* [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]. Only possible if
35+
* the version has not been previously imported and if its
36+
* [state][google.cloud.kms.v1.CryptoKeyVersion.state] is one of
37+
* [DESTROYED][CryptoKeyVersionState.DESTROYED],
38+
* [IMPORT_FAILED][CryptoKeyVersionState.IMPORT_FAILED], or
39+
* [GENERATION_FAILED][CryptoKeyVersionState.GENERATION_FAILED].
40+
* Successfully imported
41+
* [CryptoKeyVersions][google.cloud.kms.v1.CryptoKeyVersion] cannot be deleted
42+
* at this time. The specified version will be immediately and permanently
43+
* deleted upon calling this method. This action cannot be undone.
44+
*
45+
* @param string $formattedName The [name][google.cloud.kms.v1.CryptoKeyVersion.name] of the
46+
* [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] to delete. Please see
47+
* {@see KeyManagementServiceClient::cryptoKeyVersionName()} for help formatting this field.
48+
*/
49+
function delete_crypto_key_version_sample(string $formattedName): void
50+
{
51+
// Create a client.
52+
$keyManagementServiceClient = new KeyManagementServiceClient();
53+
54+
// Prepare the request message.
55+
$request = (new DeleteCryptoKeyVersionRequest())
56+
->setName($formattedName);
57+
58+
// Call the API and handle any network failures.
59+
try {
60+
/** @var OperationResponse $response */
61+
$response = $keyManagementServiceClient->deleteCryptoKeyVersion($request);
62+
$response->pollUntilComplete();
63+
64+
if ($response->operationSucceeded()) {
65+
printf('Operation completed successfully.' . PHP_EOL);
66+
} else {
67+
/** @var Status $error */
68+
$error = $response->getError();
69+
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
70+
}
71+
} catch (ApiException $ex) {
72+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
73+
}
74+
}
75+
76+
/**
77+
* Helper to execute the sample.
78+
*
79+
* This sample has been automatically generated and should be regarded as a code
80+
* template only. It will require modifications to work:
81+
* - It may require correct/in-range values for request initialization.
82+
* - It may require specifying regional endpoints when creating the service client,
83+
* please see the apiEndpoint client configuration option for more details.
84+
*/
85+
function callSample(): void
86+
{
87+
$formattedName = KeyManagementServiceClient::cryptoKeyVersionName(
88+
'[PROJECT]',
89+
'[LOCATION]',
90+
'[KEY_RING]',
91+
'[CRYPTO_KEY]',
92+
'[CRYPTO_KEY_VERSION]'
93+
);
94+
95+
delete_crypto_key_version_sample($formattedName);
96+
}
97+
// [END cloudkms_v1_generated_KeyManagementService_DeleteCryptoKeyVersion_sync]
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/*
3+
* Copyright 2026 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 cloudkms_v1_generated_KeyManagementService_GetRetiredResource_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Cloud\Kms\V1\Client\KeyManagementServiceClient;
28+
use Google\Cloud\Kms\V1\GetRetiredResourceRequest;
29+
use Google\Cloud\Kms\V1\RetiredResource;
30+
31+
/**
32+
* Retrieves a specific [RetiredResource][google.cloud.kms.v1.RetiredResource]
33+
* resource, which represents the record of a deleted
34+
* [CryptoKey][google.cloud.kms.v1.CryptoKey].
35+
*
36+
* @param string $formattedName The [name][google.cloud.kms.v1.RetiredResource.name] of the
37+
* [RetiredResource][google.cloud.kms.v1.RetiredResource] to get. Please see
38+
* {@see KeyManagementServiceClient::retiredResourceName()} for help formatting this field.
39+
*/
40+
function get_retired_resource_sample(string $formattedName): void
41+
{
42+
// Create a client.
43+
$keyManagementServiceClient = new KeyManagementServiceClient();
44+
45+
// Prepare the request message.
46+
$request = (new GetRetiredResourceRequest())
47+
->setName($formattedName);
48+
49+
// Call the API and handle any network failures.
50+
try {
51+
/** @var RetiredResource $response */
52+
$response = $keyManagementServiceClient->getRetiredResource($request);
53+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
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 = KeyManagementServiceClient::retiredResourceName(
71+
'[PROJECT]',
72+
'[LOCATION]',
73+
'[RETIRED_RESOURCE]'
74+
);
75+
76+
get_retired_resource_sample($formattedName);
77+
}
78+
// [END cloudkms_v1_generated_KeyManagementService_GetRetiredResource_sync]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/*
3+
* Copyright 2026 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 cloudkms_v1_generated_KeyManagementService_ListRetiredResources_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
28+
use Google\Cloud\Kms\V1\Client\KeyManagementServiceClient;
29+
use Google\Cloud\Kms\V1\ListRetiredResourcesRequest;
30+
use Google\Cloud\Kms\V1\RetiredResource;
31+
32+
/**
33+
* Lists the [RetiredResources][google.cloud.kms.v1.RetiredResource] which are
34+
* the records of deleted [CryptoKeys][google.cloud.kms.v1.CryptoKey].
35+
* RetiredResources prevent the reuse of these resource names after deletion.
36+
*
37+
* @param string $formattedParent The project-specific location holding the
38+
* [RetiredResources][google.cloud.kms.v1.RetiredResource], in the format
39+
* `projects/&#42;/locations/*`. Please see
40+
* {@see KeyManagementServiceClient::locationName()} for help formatting this field.
41+
*/
42+
function list_retired_resources_sample(string $formattedParent): void
43+
{
44+
// Create a client.
45+
$keyManagementServiceClient = new KeyManagementServiceClient();
46+
47+
// Prepare the request message.
48+
$request = (new ListRetiredResourcesRequest())
49+
->setParent($formattedParent);
50+
51+
// Call the API and handle any network failures.
52+
try {
53+
/** @var PagedListResponse $response */
54+
$response = $keyManagementServiceClient->listRetiredResources($request);
55+
56+
/** @var RetiredResource $element */
57+
foreach ($response as $element) {
58+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
59+
}
60+
} catch (ApiException $ex) {
61+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
62+
}
63+
}
64+
65+
/**
66+
* Helper to execute the sample.
67+
*
68+
* This sample has been automatically generated and should be regarded as a code
69+
* template only. It will require modifications to work:
70+
* - It may require correct/in-range values for request initialization.
71+
* - It may require specifying regional endpoints when creating the service client,
72+
* please see the apiEndpoint client configuration option for more details.
73+
*/
74+
function callSample(): void
75+
{
76+
$formattedParent = KeyManagementServiceClient::locationName('[PROJECT]', '[LOCATION]');
77+
78+
list_retired_resources_sample($formattedParent);
79+
}
80+
// [END cloudkms_v1_generated_KeyManagementService_ListRetiredResources_sync]

0 commit comments

Comments
 (0)