Search in sources :

Example 1 with ListSourcesPagedResponse

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

the class SourceSnippets method listSources.

// [END securitycenter_create_source]
/**
 * List sources under an organization.
 *
 * @param organizationName The organization for the source.
 */
// [START securitycenter_list_sources]
static ImmutableList<Source> listSources(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to list sources in an organization.
        // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
        ListSourcesRequest.Builder request = ListSourcesRequest.newBuilder().setParent(organizationName.toString());
        // Call the API.
        ListSourcesPagedResponse response = client.listSources(request.build());
        // This creates one list for all sources.  If your organization has a large number of sources
        // this can cause out of memory issues.  You can process them batches by returning
        // the Iterable returned response.iterateAll() directly.
        ImmutableList<Source> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("Sources:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : ListSourcesRequest(com.google.cloud.securitycenter.v1.ListSourcesRequest) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) ListSourcesPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListSourcesPagedResponse) Source(com.google.cloud.securitycenter.v1.Source)

Aggregations

ListSourcesRequest (com.google.cloud.securitycenter.v1.ListSourcesRequest)1 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)1 ListSourcesPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListSourcesPagedResponse)1 Source (com.google.cloud.securitycenter.v1.Source)1 IOException (java.io.IOException)1