use of com.google.cloud.kms.v1.GetKeyRingRequest in project gapic-generator-java by googleapis.
the class AsyncGetKeyRing method asyncGetKeyRing.
public static void asyncGetKeyRing() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
GetKeyRingRequest request = GetKeyRingRequest.newBuilder().setName(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString()).build();
ApiFuture<KeyRing> future = keyManagementServiceClient.getKeyRingCallable().futureCall(request);
// Do something.
KeyRing response = future.get();
}
}
use of com.google.cloud.kms.v1.GetKeyRingRequest in project java-kms by googleapis.
the class ITKmsTest method getKeyRing.
private static KeyRing getKeyRing(KeyManagementServiceGrpc.KeyManagementServiceBlockingStub kmsStub, String projectId) throws StatusRuntimeException {
String kmsKeyRingResourcePath = KeyRingName.of(projectId, ITKmsTest.KMS_KEY_RING_LOCATION, ITKmsTest.KMS_KEY_RING_NAME).toString();
try {
GetKeyRingRequest getKeyRingRequest = GetKeyRingRequest.newBuilder().setName(kmsKeyRingResourcePath).build();
requestParamsHeader.put(requestParamsKey, "name=" + kmsKeyRingResourcePath);
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub stubForGetKeyRing = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
return stubForGetKeyRing.getKeyRing(getKeyRingRequest);
} catch (StatusRuntimeException ex) {
if (ex.getStatus().getCode() == Status.Code.NOT_FOUND) {
String keyRingParent = LocationName.of(projectId, ITKmsTest.KMS_KEY_RING_LOCATION).toString();
CreateKeyRingRequest createKeyRingRequest = CreateKeyRingRequest.newBuilder().setParent(keyRingParent).setKeyRingId(ITKmsTest.KMS_KEY_RING_NAME).build();
requestParamsHeader.put(requestParamsKey, "parent=" + keyRingParent);
KeyManagementServiceGrpc.KeyManagementServiceBlockingStub stubForCreateKeyRing = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
return stubForCreateKeyRing.createKeyRing(createKeyRingRequest);
} else {
Assert.fail("Error creating or looking up key");
}
}
return null;
}
use of com.google.cloud.kms.v1.GetKeyRingRequest in project java-storage by googleapis.
the class ITStorageTest method ensureKmsKeyRingExistsForTests.
private static String ensureKmsKeyRingExistsForTests(KeyManagementServiceBlockingStub kmsStub, String projectId, String location, String keyRingName) throws StatusRuntimeException {
String kmsKeyRingResourcePath = KeyRingName.of(projectId, location, keyRingName).toString();
try {
// Attempt to Get KeyRing
GetKeyRingRequest getKeyRingRequest = GetKeyRingRequest.newBuilder().setName(kmsKeyRingResourcePath).build();
requestParamsHeader.put(requestParamsKey, "name=" + kmsKeyRingResourcePath);
KeyManagementServiceBlockingStub stubForGetKeyRing = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
stubForGetKeyRing.getKeyRing(getKeyRingRequest);
} catch (StatusRuntimeException ex) {
if (ex.getStatus().getCode() == Status.Code.NOT_FOUND) {
// Create KmsKeyRing
String keyRingParent = LocationName.of(projectId, location).toString();
CreateKeyRingRequest createKeyRingRequest = CreateKeyRingRequest.newBuilder().setParent(keyRingParent).setKeyRingId(keyRingName).build();
requestParamsHeader.put(requestParamsKey, "parent=" + keyRingParent);
KeyManagementServiceBlockingStub stubForCreateKeyRing = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
stubForCreateKeyRing.createKeyRing(createKeyRingRequest);
} else {
throw ex;
}
}
return kmsKeyRingResourcePath;
}
Aggregations