From 09040fffdf31b011d90d79abe2e9fc29d1bb4ae9 Mon Sep 17 00:00:00 2001 From: Jonathan Y Date: Tue, 17 Feb 2026 18:24:14 +0000 Subject: [PATCH 1/4] feat: add .NET samples for hard delete and retired resources --- kms/api/Kms.Samples/DeleteKey.cs | 35 +++++++++++++++++++ kms/api/Kms.Samples/DeleteKeyVersion.cs | 35 +++++++++++++++++++ kms/api/Kms.Samples/GetRetiredResource.cs | 36 +++++++++++++++++++ kms/api/Kms.Samples/Kms.Samples.csproj | 2 +- kms/api/Kms.Samples/ListRetiredResources.cs | 38 +++++++++++++++++++++ 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 kms/api/Kms.Samples/DeleteKey.cs create mode 100644 kms/api/Kms.Samples/DeleteKeyVersion.cs create mode 100644 kms/api/Kms.Samples/GetRetiredResource.cs create mode 100644 kms/api/Kms.Samples/ListRetiredResources.cs diff --git a/kms/api/Kms.Samples/DeleteKey.cs b/kms/api/Kms.Samples/DeleteKey.cs new file mode 100644 index 00000000000..33df19b5266 --- /dev/null +++ b/kms/api/Kms.Samples/DeleteKey.cs @@ -0,0 +1,35 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// [START kms_delete_key] +using Google.Cloud.Kms.V1; + +public class DeleteKeySample +{ + public CryptoKey DeleteKey(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key") + { + // Create the client. + KeyManagementServiceClient client = KeyManagementServiceClient.Create(); + + // Build the key name. + CryptoKeyName keyName = new CryptoKeyName(projectId, locationId, keyRingId, keyId); + + // Call the API. + CryptoKey result = client.DeleteCryptoKey(keyName); + + // Return the result. + return result; + } +} +// [END kms_delete_key] diff --git a/kms/api/Kms.Samples/DeleteKeyVersion.cs b/kms/api/Kms.Samples/DeleteKeyVersion.cs new file mode 100644 index 00000000000..e13a457677a --- /dev/null +++ b/kms/api/Kms.Samples/DeleteKeyVersion.cs @@ -0,0 +1,35 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// [START kms_delete_key_version] +using Google.Cloud.Kms.V1; + +public class DeleteKeyVersionSample +{ + public CryptoKeyVersion DeleteKeyVersion(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key", string versionId = "123") + { + // Create the client. + KeyManagementServiceClient client = KeyManagementServiceClient.Create(); + + // Build the key version name. + CryptoKeyVersionName versionName = new CryptoKeyVersionName(projectId, locationId, keyRingId, keyId, versionId); + + // Call the API. + CryptoKeyVersion result = client.DeleteCryptoKeyVersion(versionName); + + // Return the result. + return result; + } +} +// [END kms_delete_key_version] diff --git a/kms/api/Kms.Samples/GetRetiredResource.cs b/kms/api/Kms.Samples/GetRetiredResource.cs new file mode 100644 index 00000000000..0b2f8a56f16 --- /dev/null +++ b/kms/api/Kms.Samples/GetRetiredResource.cs @@ -0,0 +1,36 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// [START kms_get_retired_resource] +using Google.Cloud.Kms.V1; + +public class GetRetiredResourceSample +{ + public RetiredResource GetRetiredResource( + string projectId = "my-project", string locationId = "us-east1", string retiredResourceId = "my-retired-resource") + { + // Create the client. + KeyManagementServiceClient client = KeyManagementServiceClient.Create(); + + // Build the retired resource name. + RetiredResourceName name = new RetiredResourceName(projectId, locationId, retiredResourceId); + + // Call the API. + RetiredResource result = client.GetRetiredResource(name); + + // Return the result. + return result; + } +} +// [END kms_get_retired_resource] diff --git a/kms/api/Kms.Samples/Kms.Samples.csproj b/kms/api/Kms.Samples/Kms.Samples.csproj index 931baf4606d..76af1c86f4e 100644 --- a/kms/api/Kms.Samples/Kms.Samples.csproj +++ b/kms/api/Kms.Samples/Kms.Samples.csproj @@ -5,6 +5,6 @@ - + diff --git a/kms/api/Kms.Samples/ListRetiredResources.cs b/kms/api/Kms.Samples/ListRetiredResources.cs new file mode 100644 index 00000000000..f6c5a6cfe0a --- /dev/null +++ b/kms/api/Kms.Samples/ListRetiredResources.cs @@ -0,0 +1,38 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// [START kms_list_retired_resources] +using Google.Api.Gax; +using Google.Cloud.Kms.V1; +using System.Collections.Generic; + +public class ListRetiredResourcesSample +{ + public IEnumerable ListRetiredResources( + string projectId = "my-project", string locationId = "us-east1") + { + // Create the client. + KeyManagementServiceClient client = KeyManagementServiceClient.Create(); + + // Build the location name. + LocationName locationName = new LocationName(projectId, locationId); + + // Call the API. + PagedEnumerable response = client.ListRetiredResources(locationName); + + // Return the result. + return response; + } +} +// [END kms_list_retired_resources] From 082a3d9ef35bacaa9873be1beb2c8f7d2a9a194a Mon Sep 17 00:00:00 2001 From: Jonathan Y Date: Tue, 17 Feb 2026 18:51:23 +0000 Subject: [PATCH 2/4] fix: resolve CI failures for KMS samples --- kms/api/Kms.Samples/DeleteKey.cs | 5 +++-- kms/api/Kms.Samples/DeleteKeyVersion.cs | 5 +++-- kms/api/Kms.Samples/GetRetiredResource.cs | 1 + kms/api/Kms.Samples/ListRetiredResources.cs | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kms/api/Kms.Samples/DeleteKey.cs b/kms/api/Kms.Samples/DeleteKey.cs index 33df19b5266..ece23f0d723 100644 --- a/kms/api/Kms.Samples/DeleteKey.cs +++ b/kms/api/Kms.Samples/DeleteKey.cs @@ -14,10 +14,11 @@ // [START kms_delete_key] using Google.Cloud.Kms.V1; +using Google.LongRunning; public class DeleteKeySample { - public CryptoKey DeleteKey(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key") + public Operation DeleteKey(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key") { // Create the client. KeyManagementServiceClient client = KeyManagementServiceClient.Create(); @@ -26,7 +27,7 @@ public CryptoKey DeleteKey(string projectId = "my-project", string locationId = CryptoKeyName keyName = new CryptoKeyName(projectId, locationId, keyRingId, keyId); // Call the API. - CryptoKey result = client.DeleteCryptoKey(keyName); + Operation result = client.DeleteCryptoKey(keyName); // Return the result. return result; diff --git a/kms/api/Kms.Samples/DeleteKeyVersion.cs b/kms/api/Kms.Samples/DeleteKeyVersion.cs index e13a457677a..e5ef5733dd4 100644 --- a/kms/api/Kms.Samples/DeleteKeyVersion.cs +++ b/kms/api/Kms.Samples/DeleteKeyVersion.cs @@ -14,10 +14,11 @@ // [START kms_delete_key_version] using Google.Cloud.Kms.V1; +using Google.LongRunning; public class DeleteKeyVersionSample { - public CryptoKeyVersion DeleteKeyVersion(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key", string versionId = "123") + public Operation DeleteKeyVersion(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key", string versionId = "123") { // Create the client. KeyManagementServiceClient client = KeyManagementServiceClient.Create(); @@ -26,7 +27,7 @@ public CryptoKeyVersion DeleteKeyVersion(string projectId = "my-project", string CryptoKeyVersionName versionName = new CryptoKeyVersionName(projectId, locationId, keyRingId, keyId, versionId); // Call the API. - CryptoKeyVersion result = client.DeleteCryptoKeyVersion(versionName); + Operation result = client.DeleteCryptoKeyVersion(versionName); // Return the result. return result; diff --git a/kms/api/Kms.Samples/GetRetiredResource.cs b/kms/api/Kms.Samples/GetRetiredResource.cs index 0b2f8a56f16..fe6ed087366 100644 --- a/kms/api/Kms.Samples/GetRetiredResource.cs +++ b/kms/api/Kms.Samples/GetRetiredResource.cs @@ -13,6 +13,7 @@ // limitations under the License. // [START kms_get_retired_resource] +using Google.Api.Gax.ResourceNames; using Google.Cloud.Kms.V1; public class GetRetiredResourceSample diff --git a/kms/api/Kms.Samples/ListRetiredResources.cs b/kms/api/Kms.Samples/ListRetiredResources.cs index f6c5a6cfe0a..a7b852fb706 100644 --- a/kms/api/Kms.Samples/ListRetiredResources.cs +++ b/kms/api/Kms.Samples/ListRetiredResources.cs @@ -14,6 +14,7 @@ // [START kms_list_retired_resources] using Google.Api.Gax; +using Google.Api.Gax.ResourceNames; using Google.Cloud.Kms.V1; using System.Collections.Generic; From 09fa01b1915d930d7db3660fc26763ba21d056c9 Mon Sep 17 00:00:00 2001 From: Jonathan Y Date: Tue, 17 Feb 2026 19:00:44 +0000 Subject: [PATCH 3/4] fix: return LRO protobuf objects directly --- kms/api/Kms.Samples/DeleteKey.cs | 2 +- kms/api/Kms.Samples/DeleteKeyVersion.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kms/api/Kms.Samples/DeleteKey.cs b/kms/api/Kms.Samples/DeleteKey.cs index ece23f0d723..c15c7f92991 100644 --- a/kms/api/Kms.Samples/DeleteKey.cs +++ b/kms/api/Kms.Samples/DeleteKey.cs @@ -27,7 +27,7 @@ public Operation DeleteKey(string projectId = "my-project", string locationId = CryptoKeyName keyName = new CryptoKeyName(projectId, locationId, keyRingId, keyId); // Call the API. - Operation result = client.DeleteCryptoKey(keyName); + Operation result = client.DeleteCryptoKey(keyName).ToProto(); // Return the result. return result; diff --git a/kms/api/Kms.Samples/DeleteKeyVersion.cs b/kms/api/Kms.Samples/DeleteKeyVersion.cs index e5ef5733dd4..8b93d84b3d9 100644 --- a/kms/api/Kms.Samples/DeleteKeyVersion.cs +++ b/kms/api/Kms.Samples/DeleteKeyVersion.cs @@ -27,7 +27,7 @@ public Operation DeleteKeyVersion(string projectId = "my-project", string locati CryptoKeyVersionName versionName = new CryptoKeyVersionName(projectId, locationId, keyRingId, keyId, versionId); // Call the API. - Operation result = client.DeleteCryptoKeyVersion(versionName); + Operation result = client.DeleteCryptoKeyVersion(versionName).ToProto(); // Return the result. return result; From 7823f656f0cb05aaa35b1577936a8772d1b7be29 Mon Sep 17 00:00:00 2001 From: Jonathan Y Date: Tue, 17 Feb 2026 19:11:37 +0000 Subject: [PATCH 4/4] fix: use strongly-typed Operation returned by client --- kms/api/Kms.Samples/DeleteKey.cs | 5 +++-- kms/api/Kms.Samples/DeleteKeyVersion.cs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kms/api/Kms.Samples/DeleteKey.cs b/kms/api/Kms.Samples/DeleteKey.cs index c15c7f92991..c45b325f7d8 100644 --- a/kms/api/Kms.Samples/DeleteKey.cs +++ b/kms/api/Kms.Samples/DeleteKey.cs @@ -15,10 +15,11 @@ // [START kms_delete_key] using Google.Cloud.Kms.V1; using Google.LongRunning; +using Google.Protobuf.WellKnownTypes; public class DeleteKeySample { - public Operation DeleteKey(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key") + public Operation DeleteKey(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key") { // Create the client. KeyManagementServiceClient client = KeyManagementServiceClient.Create(); @@ -27,7 +28,7 @@ public Operation DeleteKey(string projectId = "my-project", string locationId = CryptoKeyName keyName = new CryptoKeyName(projectId, locationId, keyRingId, keyId); // Call the API. - Operation result = client.DeleteCryptoKey(keyName).ToProto(); + Operation result = client.DeleteCryptoKey(keyName); // Return the result. return result; diff --git a/kms/api/Kms.Samples/DeleteKeyVersion.cs b/kms/api/Kms.Samples/DeleteKeyVersion.cs index 8b93d84b3d9..77ce67936bc 100644 --- a/kms/api/Kms.Samples/DeleteKeyVersion.cs +++ b/kms/api/Kms.Samples/DeleteKeyVersion.cs @@ -15,10 +15,11 @@ // [START kms_delete_key_version] using Google.Cloud.Kms.V1; using Google.LongRunning; +using Google.Protobuf.WellKnownTypes; public class DeleteKeyVersionSample { - public Operation DeleteKeyVersion(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key", string versionId = "123") + public Operation DeleteKeyVersion(string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key", string versionId = "123") { // Create the client. KeyManagementServiceClient client = KeyManagementServiceClient.Create(); @@ -27,7 +28,7 @@ public Operation DeleteKeyVersion(string projectId = "my-project", string locati CryptoKeyVersionName versionName = new CryptoKeyVersionName(projectId, locationId, keyRingId, keyId, versionId); // Call the API. - Operation result = client.DeleteCryptoKeyVersion(versionName).ToProto(); + Operation result = client.DeleteCryptoKeyVersion(versionName); // Return the result. return result;