Search in sources :

Example 1 with ListHmacKeysRequest

use of com.google.storage.v2.ListHmacKeysRequest in project gapic-generator-java by googleapis.

the class AsyncListHmacKeysPaged method asyncListHmacKeysPaged.

public static void asyncListHmacKeysPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ListHmacKeysRequest request = ListHmacKeysRequest.newBuilder().setProject(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").setServiceAccountEmail("serviceAccountEmail1825953988").setShowDeletedKeys(true).setCommonRequestParams(CommonRequestParams.newBuilder().build()).build();
        while (true) {
            ListHmacKeysResponse response = storageClient.listHmacKeysCallable().call(request);
            for (HmacKeyMetadata element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : HmacKeyMetadata(com.google.storage.v2.HmacKeyMetadata) ListHmacKeysRequest(com.google.storage.v2.ListHmacKeysRequest) ListHmacKeysResponse(com.google.storage.v2.ListHmacKeysResponse) StorageClient(com.google.storage.v2.StorageClient)

Example 2 with ListHmacKeysRequest

use of com.google.storage.v2.ListHmacKeysRequest in project java-storage by googleapis.

the class StorageClientTest method listHmacKeysTest.

@Test
public void listHmacKeysTest() throws Exception {
    HmacKeyMetadata responsesElement = HmacKeyMetadata.newBuilder().build();
    ListHmacKeysResponse expectedResponse = ListHmacKeysResponse.newBuilder().setNextPageToken("").addAllHmacKeys(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    ProjectName project = ProjectName.of("[PROJECT]");
    ListHmacKeysPagedResponse pagedListResponse = client.listHmacKeys(project);
    List<HmacKeyMetadata> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getHmacKeysList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockStorage.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListHmacKeysRequest actualRequest = ((ListHmacKeysRequest) actualRequests.get(0));
    Assert.assertEquals(project.toString(), actualRequest.getProject());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListHmacKeysPagedResponse(com.google.storage.v2.StorageClient.ListHmacKeysPagedResponse) Test(org.junit.Test)

Example 3 with ListHmacKeysRequest

use of com.google.storage.v2.ListHmacKeysRequest in project java-storage by googleapis.

the class StorageClientTest method listHmacKeysTest2.

@Test
public void listHmacKeysTest2() throws Exception {
    HmacKeyMetadata responsesElement = HmacKeyMetadata.newBuilder().build();
    ListHmacKeysResponse expectedResponse = ListHmacKeysResponse.newBuilder().setNextPageToken("").addAllHmacKeys(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    String project = "project-309310695";
    ListHmacKeysPagedResponse pagedListResponse = client.listHmacKeys(project);
    List<HmacKeyMetadata> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getHmacKeysList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockStorage.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListHmacKeysRequest actualRequest = ((ListHmacKeysRequest) actualRequests.get(0));
    Assert.assertEquals(project, actualRequest.getProject());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListHmacKeysPagedResponse(com.google.storage.v2.StorageClient.ListHmacKeysPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with ListHmacKeysRequest

use of com.google.storage.v2.ListHmacKeysRequest in project gapic-generator-java by googleapis.

the class AsyncListHmacKeys method asyncListHmacKeys.

public static void asyncListHmacKeys() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ListHmacKeysRequest request = ListHmacKeysRequest.newBuilder().setProject(ProjectName.of("[PROJECT]").toString()).setPageSize(883849137).setPageToken("pageToken873572522").setServiceAccountEmail("serviceAccountEmail1825953988").setShowDeletedKeys(true).setCommonRequestParams(CommonRequestParams.newBuilder().build()).build();
        ApiFuture<HmacKeyMetadata> future = storageClient.listHmacKeysPagedCallable().futureCall(request);
        // Do something.
        for (HmacKeyMetadata element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : HmacKeyMetadata(com.google.storage.v2.HmacKeyMetadata) ListHmacKeysRequest(com.google.storage.v2.ListHmacKeysRequest) StorageClient(com.google.storage.v2.StorageClient)

Example 5 with ListHmacKeysRequest

use of com.google.storage.v2.ListHmacKeysRequest in project gapic-generator-java by googleapis.

the class StorageClientTest method listHmacKeysTest2.

@Test
public void listHmacKeysTest2() throws Exception {
    HmacKeyMetadata responsesElement = HmacKeyMetadata.newBuilder().build();
    ListHmacKeysResponse expectedResponse = ListHmacKeysResponse.newBuilder().setNextPageToken("").addAllHmacKeys(Arrays.asList(responsesElement)).build();
    mockStorage.addResponse(expectedResponse);
    String project = "project-309310695";
    ListHmacKeysPagedResponse pagedListResponse = client.listHmacKeys(project);
    List<HmacKeyMetadata> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getHmacKeysList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockStorage.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListHmacKeysRequest actualRequest = ((ListHmacKeysRequest) actualRequests.get(0));
    Assert.assertEquals(project, actualRequest.getProject());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListHmacKeysPagedResponse(com.google.storage.v2.StorageClient.ListHmacKeysPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)4 ListHmacKeysPagedResponse (com.google.storage.v2.StorageClient.ListHmacKeysPagedResponse)4 Test (org.junit.Test)4 ByteString (com.google.protobuf.ByteString)2 HmacKeyMetadata (com.google.storage.v2.HmacKeyMetadata)2 ListHmacKeysRequest (com.google.storage.v2.ListHmacKeysRequest)2 StorageClient (com.google.storage.v2.StorageClient)2 ListHmacKeysResponse (com.google.storage.v2.ListHmacKeysResponse)1