Search in sources :

Example 1 with CryptoKeyVersion

use of com.google.api.services.cloudkms.v1.model.CryptoKeyVersion in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method createCryptoKeyVersion.

// [END kms_create_cryptokey]
// [START kms_create_cryptokey_version]
/**
 * Creates a new crypto key version for the given id.
 */
public static void createCryptoKeyVersion(String projectId, String locationId, String keyRingId, String cryptoKeyId) throws IOException {
    // Create the Cloud KMS client.
    CloudKMS kms = createAuthorizedClient();
    // The resource name of the cryptoKey
    String cryptoKeys = String.format("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s", projectId, locationId, keyRingId, cryptoKeyId);
    CryptoKeyVersion version = new CryptoKeyVersion();
    CryptoKeyVersion newVersion = kms.projects().locations().keyRings().cryptoKeys().cryptoKeyVersions().create(cryptoKeys, version).execute();
    System.out.println(newVersion);
}
Also used : CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS) CryptoKeyVersion(com.google.api.services.cloudkms.v1.model.CryptoKeyVersion)

Example 2 with CryptoKeyVersion

use of com.google.api.services.cloudkms.v1.model.CryptoKeyVersion in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method restoreCryptoKeyVersion.

// [END kms_destroy_cryptokey_version]
// [START kms_restore_cryptokey_version]
/**
 * Restores the given version of a crypto key that is currently scheduled for destruction.
 */
public static CryptoKeyVersion restoreCryptoKeyVersion(String projectId, String locationId, String keyRingId, String cryptoKeyId, String version) throws IOException {
    // Create the Cloud KMS client.
    CloudKMS kms = createAuthorizedClient();
    // The resource name of the cryptoKey version
    String cryptoKeyVersion = String.format("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s", projectId, locationId, keyRingId, cryptoKeyId, version);
    RestoreCryptoKeyVersionRequest restoreRequest = new RestoreCryptoKeyVersionRequest();
    CryptoKeyVersion restored = kms.projects().locations().keyRings().cryptoKeys().cryptoKeyVersions().restore(cryptoKeyVersion, restoreRequest).execute();
    System.out.println(restored);
    return restored;
}
Also used : CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS) RestoreCryptoKeyVersionRequest(com.google.api.services.cloudkms.v1.model.RestoreCryptoKeyVersionRequest) CryptoKeyVersion(com.google.api.services.cloudkms.v1.model.CryptoKeyVersion)

Example 3 with CryptoKeyVersion

use of com.google.api.services.cloudkms.v1.model.CryptoKeyVersion in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method listCryptoKeyVersions.

/**
 * Prints all the versions for the given crypto key.
 */
public static void listCryptoKeyVersions(String projectId, String locationId, String keyRingId, String cryptoKeyId) throws IOException {
    // Create the Cloud KMS client.
    CloudKMS kms = createAuthorizedClient();
    // The resource name of the cryptoKey
    String cryptoKeys = String.format("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s", projectId, locationId, keyRingId, cryptoKeyId);
    ListCryptoKeyVersionsResponse versions = kms.projects().locations().keyRings().cryptoKeys().cryptoKeyVersions().list(cryptoKeys).execute();
    for (CryptoKeyVersion version : versions.getCryptoKeyVersions()) {
        System.out.println(version);
    }
}
Also used : CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS) ListCryptoKeyVersionsResponse(com.google.api.services.cloudkms.v1.model.ListCryptoKeyVersionsResponse) CryptoKeyVersion(com.google.api.services.cloudkms.v1.model.CryptoKeyVersion)

Example 4 with CryptoKeyVersion

use of com.google.api.services.cloudkms.v1.model.CryptoKeyVersion in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method disableCryptoKeyVersion.

// [END kms_create_cryptokey_version]
// [START kms_disable_cryptokey_version]
/**
 * Disables the given version of the crypto key.
 */
public static CryptoKeyVersion disableCryptoKeyVersion(String projectId, String locationId, String keyRingId, String cryptoKeyId, String version) throws IOException {
    // Create the Cloud KMS client.
    CloudKMS kms = createAuthorizedClient();
    // The resource name of the cryptoKey version
    String cryptoKeyVersion = String.format("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s", projectId, locationId, keyRingId, cryptoKeyId, version);
    CryptoKeyVersion newVersionState = new CryptoKeyVersion().setState("DISABLED");
    CryptoKeyVersion response = kms.projects().locations().keyRings().cryptoKeys().cryptoKeyVersions().patch(cryptoKeyVersion, newVersionState).setUpdateMask("state").execute();
    System.out.println(response);
    return response;
}
Also used : CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS) CryptoKeyVersion(com.google.api.services.cloudkms.v1.model.CryptoKeyVersion)

Example 5 with CryptoKeyVersion

use of com.google.api.services.cloudkms.v1.model.CryptoKeyVersion in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method destroyCryptoKeyVersion.

// [END kms_enable_cryptokey_version]
// [START kms_destroy_cryptokey_version]
/**
 * Marks the given version of a crypto key to be destroyed at a scheduled future point.
 */
public static CryptoKeyVersion destroyCryptoKeyVersion(String projectId, String locationId, String keyRingId, String cryptoKeyId, String version) throws IOException {
    // Create the Cloud KMS client.
    CloudKMS kms = createAuthorizedClient();
    // The resource name of the cryptoKey version
    String cryptoKeyVersion = String.format("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s", projectId, locationId, keyRingId, cryptoKeyId, version);
    DestroyCryptoKeyVersionRequest destroyRequest = new DestroyCryptoKeyVersionRequest();
    CryptoKeyVersion destroyed = kms.projects().locations().keyRings().cryptoKeys().cryptoKeyVersions().destroy(cryptoKeyVersion, destroyRequest).execute();
    System.out.println(destroyed);
    return destroyed;
}
Also used : CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS) CryptoKeyVersion(com.google.api.services.cloudkms.v1.model.CryptoKeyVersion) DestroyCryptoKeyVersionRequest(com.google.api.services.cloudkms.v1.model.DestroyCryptoKeyVersionRequest)

Aggregations

CloudKMS (com.google.api.services.cloudkms.v1.CloudKMS)6 CryptoKeyVersion (com.google.api.services.cloudkms.v1.model.CryptoKeyVersion)6 DestroyCryptoKeyVersionRequest (com.google.api.services.cloudkms.v1.model.DestroyCryptoKeyVersionRequest)1 ListCryptoKeyVersionsResponse (com.google.api.services.cloudkms.v1.model.ListCryptoKeyVersionsResponse)1 RestoreCryptoKeyVersionRequest (com.google.api.services.cloudkms.v1.model.RestoreCryptoKeyVersionRequest)1