Search in sources :

Example 1 with CreateKeyRingRequest

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);
    }
}
Also used : KeyRing(com.google.cloud.kms.v1.KeyRing) CreateKeyRingRequest(com.google.cloud.kms.v1.CreateKeyRingRequest) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Example 2 with CreateKeyRingRequest

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;
}
Also used : GetKeyRingRequest(com.google.cloud.kms.v1.GetKeyRingRequest) CreateKeyRingRequest(com.google.cloud.kms.v1.CreateKeyRingRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) KeyManagementServiceGrpc(com.google.cloud.kms.v1.KeyManagementServiceGrpc)

Example 3 with CreateKeyRingRequest

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;
}
Also used : GetKeyRingRequest(com.google.cloud.kms.v1.GetKeyRingRequest) CreateKeyRingRequest(com.google.cloud.kms.v1.CreateKeyRingRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) KeyManagementServiceBlockingStub(com.google.cloud.kms.v1.KeyManagementServiceGrpc.KeyManagementServiceBlockingStub)

Example 4 with CreateKeyRingRequest

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();
    }
}
Also used : KeyRing(com.google.cloud.kms.v1.KeyRing) CreateKeyRingRequest(com.google.cloud.kms.v1.CreateKeyRingRequest) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Aggregations

CreateKeyRingRequest (com.google.cloud.kms.v1.CreateKeyRingRequest)4 GetKeyRingRequest (com.google.cloud.kms.v1.GetKeyRingRequest)2 KeyManagementServiceClient (com.google.cloud.kms.v1.KeyManagementServiceClient)2 KeyRing (com.google.cloud.kms.v1.KeyRing)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 KeyManagementServiceGrpc (com.google.cloud.kms.v1.KeyManagementServiceGrpc)1 KeyManagementServiceBlockingStub (com.google.cloud.kms.v1.KeyManagementServiceGrpc.KeyManagementServiceBlockingStub)1