6f9eacfd1d5f6ebf961d134f538e7613c0b9fc25,kms/api-client/snippets.py,,enable_crypto_key_version,#Any#Any#Any#Any#Any#,159

Before Change


    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 enable the CryptoKeyVersion.
    crypto_keys = kms_client.projects().locations().keyRings().cryptoKeys()
    request = crypto_keys.cryptoKeyVersions().patch(
        name=name, body={"state": "ENABLED"}, updateMask="state")
    response = request.execute()

    print("CryptoKeyVersion {}\"s state has been set to {}.".format(
        name, response["state"]))
// [END kms_enable_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 enable the CryptoKeyVersion.
    new_state = enums.CryptoKeyVersion.CryptoKeyVersionState.ENABLED
    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_enable_cryptokey_version]

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 15

Instances


Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 6f9eacfd1d5f6ebf961d134f538e7613c0b9fc25
Time: 2019-01-07
Author: d.sanche14@gmail.com
File Name: kms/api-client/snippets.py
Class Name:
Method Name: enable_crypto_key_version


Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 6f9eacfd1d5f6ebf961d134f538e7613c0b9fc25
Time: 2019-01-07
Author: d.sanche14@gmail.com
File Name: kms/api-client/snippets.py
Class Name:
Method Name: restore_crypto_key_version


Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 6f9eacfd1d5f6ebf961d134f538e7613c0b9fc25
Time: 2019-01-07
Author: d.sanche14@gmail.com
File Name: kms/api-client/snippets.py
Class Name:
Method Name: destroy_crypto_key_version


Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 6f9eacfd1d5f6ebf961d134f538e7613c0b9fc25
Time: 2019-01-07
Author: d.sanche14@gmail.com
File Name: kms/api-client/snippets.py
Class Name:
Method Name: disable_crypto_key_version