Search in sources :

Example 1 with GroupAssetsPagedResponse

use of com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse in project google-cloud-java by GoogleCloudPlatform.

the class AssetSnippets method groupAssets.

// [END securitycenter_list_assets_and_changes]
/**
 * Groups all assets by their specified properties (e.g. type) for an organization.
 *
 * @param organizationName The organization to group assets for.
 */
// [START securitycenter_group_all_assets]
static ImmutableList<GroupResult> groupAssets(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request for to group all assets by type in an organization.
        // OrganizationName organizationName = OrganizationName.of("123234324");
        GroupAssetsRequest.Builder request = GroupAssetsRequest.newBuilder().setGroupBy("security_center_properties.resource_type").setParent(organizationName.toString());
        // Call the API.
        GroupAssetsPagedResponse response = client.groupAssets(request.build());
        // 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<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("All assets:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : GroupAssetsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) GroupAssetsRequest(com.google.cloud.securitycenter.v1.GroupAssetsRequest)

Example 2 with GroupAssetsPagedResponse

use of com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse in project google-cloud-java by GoogleCloudPlatform.

the class AssetSnippets method groupAssetsWithCompareDuration.

// [END securitycenter_group_all_assets_with_filter]
/**
 * Groups all assets by their state_changes (ADDED/DELETED/ACTIVE) during a period of time for an
 * organization.
 *
 * @param organizationName The organization to group assets for.
 */
// [START securitycenter_group_all_assets_with_compare_duration]
static ImmutableList<GroupResult> groupAssetsWithCompareDuration(OrganizationName organizationName, Duration duration) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request for to group all assets during a period of time in an
        // organization.
        // OrganizationName organizationName = OrganizationName.of("123234324");
        GroupAssetsRequest.Builder request = GroupAssetsRequest.newBuilder().setGroupBy("state_change").setParent(organizationName.toString());
        request.getCompareDurationBuilder().setSeconds(duration.getSeconds()).setNanos(duration.getNano());
        // Call the API.
        GroupAssetsPagedResponse response = client.groupAssets(request.build());
        // 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<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("All assets:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : GroupAssetsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) GroupAssetsRequest(com.google.cloud.securitycenter.v1.GroupAssetsRequest)

Example 3 with GroupAssetsPagedResponse

use of com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse in project google-cloud-java by GoogleCloudPlatform.

the class AssetSnippets method groupAssetsWithFilter.

// [END securitycenter_group_all_assets]
/**
 * Filters all assets by their specified properties and groups them by specified properties for an
 * organization.
 *
 * @param organizationName The organization to group assets for.
 */
// [START securitycenter_group_all_assets_with_filter]
static ImmutableList<GroupResult> groupAssetsWithFilter(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request for to filter all assets by type and group them by project in an
        // organization.
        // OrganizationName organizationName = OrganizationName.of("123234324");
        GroupAssetsRequest.Builder request = GroupAssetsRequest.newBuilder().setFilter("security_center_properties.resource_type=\"google.cloud.resourcemanager.Project\"").setGroupBy("security_center_properties.resource_project").setParent(organizationName.toString());
        // Call the API.
        GroupAssetsPagedResponse response = client.groupAssets(request.build());
        // 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<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("All assets:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : GroupAssetsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) GroupAssetsRequest(com.google.cloud.securitycenter.v1.GroupAssetsRequest)

Aggregations

GroupAssetsRequest (com.google.cloud.securitycenter.v1.GroupAssetsRequest)3 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)3 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)3 GroupAssetsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse)3 IOException (java.io.IOException)3