use of com.google.cloud.securitycenter.v1.SecurityCenterClient.ListAssetsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class SecurityMarkSnippets method listAssetsWithQueryMarks.
// [END securitycenter_add_finding_security_marks]
/**
* Lists all assets with a filter on security marks.
*
* @param organizationName The organization to list assets for.
*/
// [START securitycenter_list_assets_with_security_marks]
static ImmutableList<ListAssetsResult> listAssetsWithQueryMarks(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to list all assets filtered by a specific security mark.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(organizationName.toString()).setFilter("security_marks.marks.key_a = \"value_a\"").build();
// Call the API.
ListAssetsPagedResponse response = client.listAssets(request);
// 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<ListAssetsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Assets 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.ListAssetsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class AssetSnippets method listAssetAndStatusChanges.
// [END securitycenter_list_assets_at_time]
/**
* Returns Assets and metadata about assets activity (e.g. added, removed, no change) between
* between <code>asOf.minus(timespan)</code> and <code>asOf</code>.
*
* @param timeSpan The time-range to compare assets over.
* @param asOf The instant in time to query for. If null, current time is assumed.
*/
// [START securitycenter_list_assets_and_changes]
static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(OrganizationName organizationName, Duration timeSpan, Instant asOf) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
ListAssetsRequest.Builder request = ListAssetsRequest.newBuilder().setParent(organizationName.toString()).setFilter("security_center_properties.resource_type=\"google.cloud.resourcemanager.Project\"");
request.getCompareDurationBuilder().setSeconds(timeSpan.getSeconds()).setNanos(timeSpan.getNano());
// Set read time to either the instant passed in or now.
asOf = MoreObjects.firstNonNull(asOf, Instant.now());
request.getReadTimeBuilder().setSeconds(asOf.getEpochSecond()).setNanos(asOf.getNano());
// Call the API.
ListAssetsPagedResponse response = client.listAssets(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 incrementally by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<ListAssetsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Projects:");
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.ListAssetsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class AssetSnippets method listAssetsWithFilter.
// [END securitycenter_list_all_assets]
/**
* Lists all project assets for an organization.
*
* @param organizationName The organization to list assets for.
*/
// [START securitycenter_list_assets_with_filter]
static ImmutableList<ListAssetsResult> listAssetsWithFilter(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
ListAssetsRequest.Builder request = ListAssetsRequest.newBuilder().setParent(organizationName.toString()).setFilter("security_center_properties.resource_type=\"google.cloud.resourcemanager.Project\"");
// Call the API.
ListAssetsPagedResponse response = client.listAssets(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 incrementally by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<ListAssetsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Project assets:");
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.ListAssetsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class AssetSnippets method listAssets.
/**
* Lists all assets for an organization.
*
* @param organizationName The organization to list assets for.
*/
// [START securitycenter_list_all_assets]
static ImmutableList<ListAssetsResult> listAssets(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
ListAssetsRequest.Builder request = ListAssetsRequest.newBuilder().setParent(organizationName.toString());
// Call the API.
ListAssetsPagedResponse response = client.listAssets(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 incrementally by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<ListAssetsResult> 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);
}
}
use of com.google.cloud.securitycenter.v1.SecurityCenterClient.ListAssetsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class AssetSnippets method listAssetsAsOfYesterday.
// [END securitycenter_list_assets_with_filter]
/**
* Lists all project assets for an organization at a given point in time.
*
* @param organizationName The organization to list assets for.
* @param asOf The snapshot time to query for assets. If null defaults to one day ago.
*/
// [START securitycenter_list_assets_at_time]
static ImmutableList<ListAssetsResult> listAssetsAsOfYesterday(OrganizationName organizationName, Instant asOf) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
// Initialize the builder with the organization and filter
ListAssetsRequest.Builder request = ListAssetsRequest.newBuilder().setParent(organizationName.toString()).setFilter("security_center_properties.resource_type=\"google.cloud.resourcemanager.Project\"");
// Set read time to either the instant passed in or one day ago.
asOf = MoreObjects.firstNonNull(asOf, Instant.now().minus(Duration.ofDays(1)));
request.getReadTimeBuilder().setSeconds(asOf.getEpochSecond()).setNanos(asOf.getNano());
// Call the API.
ListAssetsPagedResponse response = client.listAssets(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 incrementally by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<ListAssetsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Projects:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
Aggregations