Search in sources :

Example 1 with KeyRing

use of com.google.cloud.kms.v1.KeyRing in project ranger by apache.

the class RangerGoogleCloudHSMProvider method onInitialization.

@Override
public void onInitialization() throws Exception {
    this.validateGcpProps();
    if (logger.isDebugEnabled()) {
        logger.debug("==> onInitialization() : {gcpProjectId - " + this.gcpProjectId + ", gcpLocationId - " + this.gcpLocationId + ", gcpKeyRingId - " + this.gcpKeyRingId + ", gcpAppCredFile Path - " + this.gcpAppCredFile + "}");
    }
    String errorMessage = null;
    client = getKeyClient(this.gcpAppCredFile);
    KeyRing keyRingResponse = null;
    if (client != null) {
        this.keyRingName = KeyRingName.of(this.gcpProjectId, this.gcpLocationId, this.gcpKeyRingId);
        if (this.keyRingName != null) {
            keyRingResponse = this.client.getKeyRing(this.keyRingName.toString());
            if (keyRingResponse == null) {
                errorMessage = "Unable to get Key Ring response for Project : " + this.gcpProjectId + " and Location : " + this.gcpLocationId;
            } else if (keyRingResponse != null && !keyRingResponse.getName().endsWith(this.gcpKeyRingId)) {
                errorMessage = "Key Ring with name : " + this.gcpKeyRingId + " does not exist for Project : " + this.gcpProjectId + " and Location : " + this.gcpLocationId;
            }
        } else {
            errorMessage = "Unable to get Key Ring response for Project : " + this.gcpProjectId + " and Location : " + this.gcpLocationId;
        }
    } else {
        errorMessage = "Unable to create client object for Google Cloud HSM. Please check the Key HSM Log file OR Verify Google App Credential JSON file.";
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== onInitialization() : {this.keyRingName - " + this.keyRingName + ", keyRingResponse - " + keyRingResponse + "}");
    }
    if (!StringUtils.isEmpty(errorMessage)) {
        throw new RuntimeCryptoException(errorMessage);
    }
}
Also used : RuntimeCryptoException(org.bouncycastle.crypto.RuntimeCryptoException) KeyRing(com.google.cloud.kms.v1.KeyRing) ByteString(com.google.protobuf.ByteString)

Aggregations

KeyRing (com.google.cloud.kms.v1.KeyRing)1 ByteString (com.google.protobuf.ByteString)1 RuntimeCryptoException (org.bouncycastle.crypto.RuntimeCryptoException)1