Search in sources :

Example 1 with ListAssetsRequest

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

the class AsyncListAssetsPaged method asyncListAssetsPaged.

public static void asyncListAssetsPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setPageSize(883849137).setPageToken("pageToken873572522").addAllRelationshipTypes(new ArrayList<String>()).build();
        while (true) {
            ListAssetsResponse response = assetServiceClient.listAssetsCallable().call(request);
            for (Asset element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) Asset(com.google.cloud.asset.v1.Asset) ListAssetsResponse(com.google.cloud.asset.v1.ListAssetsResponse)

Example 2 with ListAssetsRequest

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

the class AssetServiceClientTest method listAssetsTest2.

@Test
public void listAssetsTest2() throws Exception {
    Asset responsesElement = Asset.newBuilder().build();
    ListAssetsResponse expectedResponse = ListAssetsResponse.newBuilder().setNextPageToken("").addAllAssets(Arrays.asList(responsesElement)).build();
    mockAssetService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListAssetsPagedResponse pagedListResponse = client.listAssets(parent);
    List<Asset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAssetService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse) Test(org.junit.Test)

Example 3 with ListAssetsRequest

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

the class ListAssetsExample method listAssets.

public static void listAssets(String projectId, String[] assetTypes, ContentType contentType) throws IOException, IllegalArgumentException {
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        // Build initial ListAssetsRequest without setting page token.
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(parent.toString()).addAllAssetTypes(Arrays.asList(assetTypes)).setContentType(contentType).build();
        // Repeatedly call ListAssets until page token is empty.
        ListAssetsPagedResponse response = client.listAssets(request);
        System.out.println(response);
        while (!response.getNextPageToken().isEmpty()) {
            request = request.toBuilder().setPageToken(response.getNextPageToken()).build();
            response = client.listAssets(request);
            System.out.println(response);
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)

Example 4 with ListAssetsRequest

use of com.google.cloud.asset.v1.ListAssetsRequest in project google-cloud-java by GoogleCloudPlatform.

the class SecurityMarkSnippets method listAssetsWithQueryMarks.

// [END securitycenter_add_finding_security_marks]
/**
 * Lists all assets with a filter on security marks.
 *
 * @param organizationName The organization to list assets for.
 */
// [START securitycenter_list_assets_with_security_marks]
static ImmutableList<ListAssetsResult> listAssetsWithQueryMarks(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request for to list all assets filtered by a specific security mark.
        // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(organizationName.toString()).setFilter("security_marks.marks.key_a = \"value_a\"").build();
        // Call the API.
        ListAssetsPagedResponse response = client.listAssets(request);
        // This creates one list for all assets.  If your organization has a large number of assets
        // this can cause out of memory issues.  You can process them batches by returning
        // the Iterable returned response.iterateAll() directly.
        ImmutableList<ListAssetsResult> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("Assets with security mark - key_a=value_a:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : ListAssetsRequest(com.google.cloud.securitycenter.v1.ListAssetsRequest) ListAssetsResult(com.google.cloud.securitycenter.v1.ListAssetsResponse.ListAssetsResult) ListAssetsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListAssetsPagedResponse) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 5 with ListAssetsRequest

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

the class AsyncListAssets method asyncListAssets.

public static void asyncListAssets() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setPageSize(883849137).setPageToken("pageToken873572522").addAllRelationshipTypes(new ArrayList<String>()).build();
        ApiFuture<Asset> future = assetServiceClient.listAssetsPagedCallable().futureCall(request);
        // Do something.
        for (Asset element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) Asset(com.google.cloud.asset.v1.Asset)

Aggregations

AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)3 ListAssetsPagedResponse (com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)3 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)3 Asset (com.google.cloud.asset.v1.Asset)2 ListAssetsRequest (com.google.cloud.securitycenter.v1.ListAssetsRequest)2 ListAssetsResult (com.google.cloud.securitycenter.v1.ListAssetsResponse.ListAssetsResult)2 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)2 ListAssetsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListAssetsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ResourceName (com.google.api.resourcenames.ResourceName)1 ListAssetsResponse (com.google.cloud.asset.v1.ListAssetsResponse)1 ProjectName (com.google.cloud.asset.v1.ProjectName)1