Search in sources :

Example 6 with ListCryptoKeyVersionsRequest

use of com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest in project gapic-generator-java by googleapis.

the class AsyncListCryptoKeyVersions method asyncListCryptoKeyVersions.

public static void asyncListCryptoKeyVersions() throws Exception {
    // It may require modifications to work in your environment.
    try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
        ListCryptoKeyVersionsRequest request = ListCryptoKeyVersionsRequest.newBuilder().setParent(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").setFilter("filter-1274492040").setOrderBy("orderBy-1207110587").build();
        ApiFuture<CryptoKeyVersion> future = keyManagementServiceClient.listCryptoKeyVersionsPagedCallable().futureCall(request);
        // Do something.
        for (CryptoKeyVersion element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : ListCryptoKeyVersionsRequest(com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest) CryptoKeyVersion(com.google.cloud.kms.v1.CryptoKeyVersion) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Example 7 with ListCryptoKeyVersionsRequest

use of com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest in project gapic-generator-java by googleapis.

the class AsyncListCryptoKeyVersionsPaged method asyncListCryptoKeyVersionsPaged.

public static void asyncListCryptoKeyVersionsPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
        ListCryptoKeyVersionsRequest request = ListCryptoKeyVersionsRequest.newBuilder().setParent(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").setFilter("filter-1274492040").setOrderBy("orderBy-1207110587").build();
        while (true) {
            ListCryptoKeyVersionsResponse response = keyManagementServiceClient.listCryptoKeyVersionsCallable().call(request);
            for (CryptoKeyVersion element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : ListCryptoKeyVersionsRequest(com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest) ListCryptoKeyVersionsResponse(com.google.cloud.kms.v1.ListCryptoKeyVersionsResponse) CryptoKeyVersion(com.google.cloud.kms.v1.CryptoKeyVersion) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient)

Example 8 with ListCryptoKeyVersionsRequest

use of com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest in project gapic-generator-java by googleapis.

the class KeyManagementServiceClientTest method listCryptoKeyVersionsTest2.

@Test
public void listCryptoKeyVersionsTest2() throws Exception {
    CryptoKeyVersion responsesElement = CryptoKeyVersion.newBuilder().build();
    ListCryptoKeyVersionsResponse expectedResponse = ListCryptoKeyVersionsResponse.newBuilder().setNextPageToken("").addAllCryptoKeyVersions(Arrays.asList(responsesElement)).build();
    mockKeyManagementService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListCryptoKeyVersionsPagedResponse pagedListResponse = client.listCryptoKeyVersions(parent);
    List<CryptoKeyVersion> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getCryptoKeyVersionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKeyManagementService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListCryptoKeyVersionsRequest actualRequest = ((ListCryptoKeyVersionsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) ListCryptoKeyVersionsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListCryptoKeyVersionsPagedResponse) Test(org.junit.Test)

Aggregations

CryptoKeyVersion (com.google.cloud.kms.v1.CryptoKeyVersion)4 KeyManagementServiceClient (com.google.cloud.kms.v1.KeyManagementServiceClient)4 ListCryptoKeyVersionsPagedResponse (com.google.cloud.kms.v1.KeyManagementServiceClient.ListCryptoKeyVersionsPagedResponse)4 ListCryptoKeyVersionsRequest (com.google.cloud.kms.v1.ListCryptoKeyVersionsRequest)4 AbstractMessage (com.google.protobuf.AbstractMessage)4 Test (org.junit.Test)4 CryptoKey (com.google.cloud.kms.v1.CryptoKey)2 ByteString (com.google.protobuf.ByteString)2 FieldMask (com.google.protobuf.FieldMask)2 AfterClass (org.junit.AfterClass)2 ListCryptoKeyVersionsResponse (com.google.cloud.kms.v1.ListCryptoKeyVersionsResponse)1