use of com.google.cloud.kms.v1.CreateKeyRingRequest in project gapic-generator-java by googleapis.
the class SyncCreateKeyRing method syncCreateKeyRing.
public static void syncCreateKeyRing() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
CreateKeyRingRequest request = CreateKeyRingRequest.newBuilder().setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setKeyRingId("keyRingId-2027180374").setKeyRing(KeyRing.newBuilder().build()).build();
KeyRing response = keyManagementServiceClient.createKeyRing(request);
}
}
use of com.google.cloud.kms.v1.CreateKeyRingRequest 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.CreateKeyRingRequest 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;
}
use of com.google.cloud.kms.v1.CreateKeyRingRequest in project gapic-generator-java by googleapis.
the class AsyncCreateKeyRing method asyncCreateKeyRing.
public static void asyncCreateKeyRing() throws Exception {
// It may require modifications to work in your environment.
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
CreateKeyRingRequest request = CreateKeyRingRequest.newBuilder().setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setKeyRingId("keyRingId-2027180374").setKeyRing(KeyRing.newBuilder().build()).build();
ApiFuture<KeyRing> future = keyManagementServiceClient.createKeyRingCallable().futureCall(request);
// Do something.
KeyRing response = future.get();
}
}
Aggregations