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);
}
}
Aggregations