KeyRing.
// Creates an API client for the KMS API.
kms_client = googleapiclient.discovery.build("cloudkms", "v1")
// Construct the resource name of the CryptoKeyVersion.
name = (
"projects/{}/locations/{}/keyRings/{}/cryptoKeys/{}/"
"cryptoKeyVersions/{}"
.format(
project_id, location_id, key_ring_id, crypto_key_id, version_id))
// Use the KMS API to disable the CryptoKeyVersion.
crypto_keys = kms_client.projects().locations().keyRings().cryptoKeys()
request = crypto_keys.cryptoKeyVersions().patch(
name=name, body={"state": "DISABLED"}, updateMask="state")
response = request.execute()
print("CryptoKeyVersion {}\"s state has been set to {}.".format(
name, response["state"]))
// [END kms_disable_cryptokey_version]
After Change
KeyRing.
// Creates an API client for the KMS API.
client = kms_v1.KeyManagementServiceClient()
// Construct the resource name of the CryptoKeyVersion.
name = client.crypto_key_version_path(project_id, location_id, key_ring_id,
crypto_key_id, version_id)
// Use the KMS API to disable the CryptoKeyVersion.
new_state = enums.CryptoKeyVersion.CryptoKeyVersionState.DISABLED
version = {"name": name, "state": new_state}
update_mask = {"paths": ["state"]}
// Print results
response = client.update_crypto_key_version(version, update_mask)
print("CryptoKeyVersion {}\"s state has been set to {}.".format(
name, response.state))
// [END kms_disable_cryptokey_version]