use of com.google.cloud.securitycenter.v1.OrganizationName in project google-cloud-java by googleapis.
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);
}
}
use of com.google.cloud.securitycenter.v1.OrganizationName in project google-cloud-java by googleapis.
the class OrganizationSnippets method updateOrganizationSettings.
// [END securitycenter_get_org_settings]
/**
* Update Asset Discovery OrganizationSettings for an organization
*
* @param organizationName The organization to update settings for.
*/
// [START securitycenter_enable_asset_discovery]
static OrganizationSettings updateOrganizationSettings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request to update OrganizationSettings for.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
OrganizationSettings organizationSettings = OrganizationSettings.newBuilder().setName(organizationName.toString() + "/organizationSettings").setEnableAssetDiscovery(true).build();
FieldMask updateMask = FieldMask.newBuilder().addPaths("enable_asset_discovery").build();
UpdateOrganizationSettingsRequest.Builder request = UpdateOrganizationSettingsRequest.newBuilder().setOrganizationSettings(organizationSettings).setUpdateMask(updateMask);
// Call the API.
OrganizationSettings response = client.updateOrganizationSettings(request.build());
System.out.println("Organization Settings have been updated:");
System.out.println(response);
return response;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.securitycenter.v1.OrganizationName in project google-cloud-java by googleapis.
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.OrganizationName in project google-cloud-java by googleapis.
the class SourceSnippets method createSource.
/**
* Create a source under an organization.
*
* @param organizationName The organization for the source.
*/
// [START securitycenter_create_source]
static Source createSource(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request to create a source in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
Source source = Source.newBuilder().setDisplayName("Customized Display Name").setDescription("A new custom source that does X").build();
CreateSourceRequest.Builder request = CreateSourceRequest.newBuilder().setParent(organizationName.toString()).setSource(source);
// Call the API.
Source response = client.createSource(request.build());
System.out.println("Created Source: " + response);
return response;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
Aggregations