Search in sources :

Example 1 with SearchAllIamPoliciesPagedResponse

use of com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse in project java-asset by googleapis.

the class SearchAllIamPoliciesExample method searchAllIamPolicies.

// Searches for all the iam policies within the given scope.
public static void searchAllIamPolicies(String scope, String query) {
    // TODO(developer): Replace these variables before running the sample.
    int pageSize = 0;
    String pageToken = "";
    SearchAllIamPoliciesRequest request = SearchAllIamPoliciesRequest.newBuilder().setScope(scope).setQuery(query).setPageSize(pageSize).setPageToken(pageToken).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AssetServiceClient client = AssetServiceClient.create()) {
        SearchAllIamPoliciesPagedResponse response = client.searchAllIamPolicies(request);
        System.out.println("Search completed successfully:\n" + response.getPage().getValues());
    } catch (IOException e) {
        System.out.println(String.format("Failed to create client:%n%s", e.toString()));
    } catch (InvalidArgumentException e) {
        System.out.println(String.format("Invalid request:%n%s", e.toString()));
    } catch (ApiException e) {
        System.out.println(String.format("Error during SearchAllIamPolicies:%n%s", e.toString()));
    }
}
Also used : SearchAllIamPoliciesPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) SearchAllIamPoliciesRequest(com.google.cloud.asset.v1.SearchAllIamPoliciesRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) IOException(java.io.IOException) ApiException(com.google.api.gax.rpc.ApiException)

Example 2 with SearchAllIamPoliciesPagedResponse

use of com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse in project gapic-generator-java by googleapis.

the class AssetServiceClientTest method searchAllIamPoliciesTest.

@Test
public void searchAllIamPoliciesTest() throws Exception {
    IamPolicySearchResult responsesElement = IamPolicySearchResult.newBuilder().build();
    SearchAllIamPoliciesResponse expectedResponse = SearchAllIamPoliciesResponse.newBuilder().setNextPageToken("").addAllResults(Arrays.asList(responsesElement)).build();
    mockAssetService.addResponse(expectedResponse);
    String scope = "scope109264468";
    String query = "query107944136";
    SearchAllIamPoliciesPagedResponse pagedListResponse = client.searchAllIamPolicies(scope, query);
    List<IamPolicySearchResult> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAssetService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SearchAllIamPoliciesRequest actualRequest = ((SearchAllIamPoliciesRequest) actualRequests.get(0));
    Assert.assertEquals(scope, actualRequest.getScope());
    Assert.assertEquals(query, actualRequest.getQuery());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : SearchAllIamPoliciesPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 3 with SearchAllIamPoliciesPagedResponse

use of com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse in project java-asset by googleapis.

the class AssetServiceClientTest method searchAllIamPoliciesTest.

@Test
public void searchAllIamPoliciesTest() throws Exception {
    IamPolicySearchResult responsesElement = IamPolicySearchResult.newBuilder().build();
    SearchAllIamPoliciesResponse expectedResponse = SearchAllIamPoliciesResponse.newBuilder().setNextPageToken("").addAllResults(Arrays.asList(responsesElement)).build();
    mockAssetService.addResponse(expectedResponse);
    String scope = "scope109264468";
    String query = "query107944136";
    SearchAllIamPoliciesPagedResponse pagedListResponse = client.searchAllIamPolicies(scope, query);
    List<IamPolicySearchResult> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAssetService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SearchAllIamPoliciesRequest actualRequest = ((SearchAllIamPoliciesRequest) actualRequests.get(0));
    Assert.assertEquals(scope, actualRequest.getScope());
    Assert.assertEquals(query, actualRequest.getQuery());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : SearchAllIamPoliciesPagedResponse(com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllIamPoliciesPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Aggregations

SearchAllIamPoliciesPagedResponse (com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 ApiException (com.google.api.gax.rpc.ApiException)1 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)1 SearchAllIamPoliciesRequest (com.google.cloud.asset.v1.SearchAllIamPoliciesRequest)1 SearchAllIamPoliciesPagedResponse (com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllIamPoliciesPagedResponse)1 IOException (java.io.IOException)1