Search in sources :

Example 6 with GroupResult

use of com.google.cloud.securitycenter.v1.GroupResult 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)

Example 7 with GroupResult

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

the class FindingSnippets method groupFindingsWithSource.

// [END securitycenter_group_all_findings]
/**
 * Group findings under an organization and a source by their specified properties (e.g.
 * category).
 *
 * @param sourceName The source to limit the findings to.
 */
// [START securitycenter_group_findings_with_source]
static ImmutableList<GroupResult> groupFindingsWithSource(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        GroupFindingsRequest.Builder request = GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("category");
        // Call the API.
        GroupFindingsPagedResponse response = client.groupFindings(request.build());
        // This creates one list for all findings.  If your organization has a large number of
        // findings
        // 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("Findings:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : GroupFindingsRequest(com.google.cloud.securitycenter.v1.GroupFindingsRequest) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) GroupFindingsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 8 with GroupResult

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

the class FindingSnippets method groupFindings.

// [END securitycenter_test_iam]
/**
 * Group all findings under an organization across all sources by their specified properties (e.g.
 * category).
 *
 * @param organizationName The organizatoin to group all findings for.
 */
// [START securitycenter_group_all_findings]
static ImmutableList<GroupResult> groupFindings(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // OrganizationName organizationName = OrganizationName.of("123234324");
        SourceName sourceName = SourceName.of(organizationName.getOrganization(), "-");
        GroupFindingsRequest.Builder request = GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("category");
        // Call the API.
        GroupFindingsPagedResponse response = client.groupFindings(request.build());
        // This creates one list for all findings.  If your organization has a large number of
        // findings
        // 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("Findings:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : GroupFindingsRequest(com.google.cloud.securitycenter.v1.GroupFindingsRequest) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) SourceName(com.google.cloud.securitycenter.v1.SourceName) GroupFindingsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Aggregations

GroupResult (com.google.cloud.securitycenter.v1.GroupResult)8 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)8 IOException (java.io.IOException)8 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)5 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)5 GroupAssetsRequest (com.google.cloud.securitycenter.v1.GroupAssetsRequest)3 GroupAssetsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse)3 SourceName (com.google.cloud.securitycenter.v1.SourceName)1 Instant (org.threeten.bp.Instant)1