use of com.google.api.gax.rpc.AlreadyExistsException in project ranger by apache.
the class RangerGoogleCloudHSMProvider method generateMasterKey.
@Override
public boolean generateMasterKey(String unused_password) throws Throwable {
// The ENCRYPT_DECRYPT key purpose enables symmetric encryption.
// All keys with key purpose ENCRYPT_DECRYPT use the GOOGLE_SYMMETRIC_ENCRYPTION algorithm.
// No parameters are used with this algorithm.
CryptoKey key = CryptoKey.newBuilder().setPurpose(CryptoKeyPurpose.ENCRYPT_DECRYPT).setVersionTemplate(CryptoKeyVersionTemplate.newBuilder().setProtectionLevel(ProtectionLevel.HSM).setAlgorithm(CryptoKeyVersionAlgorithm.GOOGLE_SYMMETRIC_ENCRYPTION)).build();
// Create the key.
CryptoKey createdKey = null;
try {
createdKey = client.createCryptoKey(this.keyRingName, this.gcpMasterKeyName, key);
} catch (Exception e) {
if (e instanceof AlreadyExistsException) {
logger.info("MasterKey with the name '" + this.gcpMasterKeyName + "' already exist.");
return true;
} else {
throw new RuntimeCryptoException("Failed to create master key with name '" + this.gcpMasterKeyName + "', Error - " + e.getMessage());
}
}
if (createdKey == null) {
logger.info("Failed to create master key : " + this.gcpMasterKeyName);
return false;
}
logger.info("Master Key Created Successfully On Google Cloud HSM : " + this.gcpMasterKeyName);
return true;
}
Aggregations