use of com.google.cloud.kms.v1.GetCryptoKeyRequest in project java-storage by googleapis.
the class ITStorageTest method ensureKmsKeyExistsForTests.
private static String ensureKmsKeyExistsForTests(KeyManagementServiceBlockingStub kmsStub, String projectId, String location, String keyRingName, String keyName) throws StatusRuntimeException {
String kmsKeyResourcePath = CryptoKeyName.of(projectId, location, keyRingName, keyName).toString();
try {
// Attempt to Get CryptoKey
requestParamsHeader.put(requestParamsKey, "name=" + kmsKeyResourcePath);
GetCryptoKeyRequest getCryptoKeyRequest = GetCryptoKeyRequest.newBuilder().setName(kmsKeyResourcePath).build();
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub stubForGetCryptoKey = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
stubForGetCryptoKey.getCryptoKey(getCryptoKeyRequest);
} catch (StatusRuntimeException ex) {
if (ex.getStatus().getCode() == Status.Code.NOT_FOUND) {
String kmsKeyRingResourcePath = KeyRingName.of(projectId, location, keyRingName).toString();
CryptoKey cryptoKey = CryptoKey.newBuilder().setPurpose(CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT).build();
CreateCryptoKeyRequest createCryptoKeyRequest = CreateCryptoKeyRequest.newBuilder().setCryptoKeyId(keyName).setParent(kmsKeyRingResourcePath).setCryptoKey(cryptoKey).build();
requestParamsHeader.put(requestParamsKey, "parent=" + kmsKeyRingResourcePath);
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub stubForCreateCryptoKey = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
stubForCreateCryptoKey.createCryptoKey(createCryptoKeyRequest);
} else {
throw ex;
}
}
return kmsKeyResourcePath;
}
use of com.google.cloud.kms.v1.GetCryptoKeyRequest in project gapic-generator-java by googleapis.
the class SyncGetCryptoKey method syncGetCryptoKey.
public static void syncGetCryptoKey() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
GetCryptoKeyRequest request = GetCryptoKeyRequest.newBuilder().setName(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).build();
CryptoKey response = keyManagementServiceClient.getCryptoKey(request);
}
}
use of com.google.cloud.kms.v1.GetCryptoKeyRequest in project gapic-generator-java by googleapis.
the class AsyncGetCryptoKey method asyncGetCryptoKey.
public static void asyncGetCryptoKey() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
GetCryptoKeyRequest request = GetCryptoKeyRequest.newBuilder().setName(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).build();
ApiFuture<CryptoKey> future = keyManagementServiceClient.getCryptoKeyCallable().futureCall(request);
// Do something.
CryptoKey response = future.get();
}
}
Aggregations