use of com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class SecurityMarkSnippets method listFindingsWithQueryMarks.
// [END securitycenter_list_assets_with_security_marks]
/**
* List all findings with a filter on security marks.
*
* @param sourceName The source to list filtered findings for.
*/
// [START securitycenter_list_findings_with_security_marks]
static ImmutableList<ListFindingsResult> listFindingsWithQueryMarks(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to list all findings filtered by a specific security mark.
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
// "423432321");
String filter = "NOT security_marks.marks.key_a=\"value_a\"";
ListFindingsRequest.Builder request = ListFindingsRequest.newBuilder().setParent(sourceName.toString()).setFilter(filter);
// Call the API.
ListFindingsPagedResponse response = client.listFindings(request.build());
// This creates one list for all findings in the filter.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<ListFindingsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Findings with security mark - key_a=value_a:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class FindingSnippets method listFindingsAtTime.
// [END securitycenter_list_filtered_findings]
/**
* List findings at a specific time under a source.
*
* @param sourceName The source to list findings at a specific time for.
*/
// [START securitycenter_list_findings_at_time]
static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
// /*sourceId=*/"423432321");
// 5 days ago
Instant fiveDaysAgo = Instant.now().minus(Duration.ofDays(5));
ListFindingsRequest.Builder request = ListFindingsRequest.newBuilder().setParent(sourceName.toString()).setReadTime(Timestamp.newBuilder().setSeconds(fiveDaysAgo.getEpochSecond()).setNanos(fiveDaysAgo.getNano()));
// Call the API.
ListFindingsPagedResponse response = client.listFindings(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 in incrementally
// by returning the Iterable returned response.iterateAll() directly.
ImmutableList<ListFindingsResult> 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);
}
}
use of com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class FindingSnippets method listAllFindings.
// [END securitycenter_update_finding_state]
/**
* List all findings under an organization.
*
* @param organizationName The source to list all findings for.
*/
// [START securitycenter_list_all_findings]
static ImmutableList<ListFindingsResult> listAllFindings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
// "-" Indicates listing across all sources.
SourceName sourceName = SourceName.of(organizationName.getOrganization(), "-");
ListFindingsRequest.Builder request = ListFindingsRequest.newBuilder().setParent(sourceName.toString());
// Call the API.
ListFindingsPagedResponse response = client.listFindings(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 in incrementally
// by returning the Iterable returned response.iterateAll() directly.
ImmutableList<ListFindingsResult> 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);
}
}
use of com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class FindingSnippets method listFilteredFindings.
// [END securitycenter_list_all_findings]
/**
* List filtered findings under a source.
*
* @param sourceName The source to list filtered findings for.
*/
// [START securitycenter_list_filtered_findings]
static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
// /*sourceId=*/"423432321");
// Create filter to category of MEDIUM_RISK_ONE
String filter = "category=\"MEDIUM_RISK_ONE\"";
ListFindingsRequest.Builder request = ListFindingsRequest.newBuilder().setParent(sourceName.toString()).setFilter(filter);
// Call the API.
ListFindingsPagedResponse response = client.listFindings(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 in incrementally
// by returning the Iterable returned response.iterateAll() directly.
ImmutableList<ListFindingsResult> 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);
}
}
Aggregations