Search in sources :

Example 6 with SourceName

use of org.orcid.jaxb.model.common_v2.SourceName 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

SourceName (org.orcid.jaxb.model.common_v2.SourceName)4 Test (org.junit.Test)3 Source (org.orcid.jaxb.model.common_v2.Source)3 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)2 SourceName (com.google.cloud.securitycenter.v1.SourceName)2 IOException (java.io.IOException)2 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)2 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)2 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)2 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)1 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)1 ListFindingsRequest (com.google.cloud.securitycenter.v1.ListFindingsRequest)1 ListFindingsResult (com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)1 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)1 ListFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse)1 ArrayList (java.util.ArrayList)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 BaseTest (org.orcid.core.BaseTest)1 SourceOrcid (org.orcid.jaxb.model.common_v2.SourceOrcid)1 FamilyName (org.orcid.jaxb.model.message.FamilyName)1