use of com.google.cloud.securitycenter.v1.OrganizationName 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.OrganizationName in project google-cloud-java by GoogleCloudPlatform.
the class OrganizationSnippets method getOrganizationSettings.
/**
* Gets current settings for an organization.
*
* @param organizationName The organization to get settings for.
*/
// [START securitycenter_get_org_settings]
static OrganizationSettings getOrganizationSettings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request to get OrganizationSettings for.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
GetOrganizationSettingsRequest.Builder request = GetOrganizationSettingsRequest.newBuilder().setName(organizationName.toString() + "/organizationSettings");
// Call the API.
OrganizationSettings response = client.getOrganizationSettings(request.build());
System.out.println("Organization Settings:");
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 GoogleCloudPlatform.
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 java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method listNotificationChannelDescriptorsTest2.
@Test
public void listNotificationChannelDescriptorsTest2() throws Exception {
NotificationChannelDescriptor responsesElement = NotificationChannelDescriptor.newBuilder().build();
ListNotificationChannelDescriptorsResponse expectedResponse = ListNotificationChannelDescriptorsResponse.newBuilder().setNextPageToken("").addAllChannelDescriptors(Arrays.asList(responsesElement)).build();
mockNotificationChannelService.addResponse(expectedResponse);
OrganizationName name = OrganizationName.of("[ORGANIZATION]");
ListNotificationChannelDescriptorsPagedResponse pagedListResponse = client.listNotificationChannelDescriptors(name);
List<NotificationChannelDescriptor> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getChannelDescriptorsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockNotificationChannelService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListNotificationChannelDescriptorsRequest actualRequest = ((ListNotificationChannelDescriptorsRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.securitycenter.v1.OrganizationName in project java-monitoring by googleapis.
the class NotificationChannelServiceClientTest method listNotificationChannelDescriptorsExceptionTest2.
@Test
public void listNotificationChannelDescriptorsExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockNotificationChannelService.addException(exception);
try {
OrganizationName name = OrganizationName.of("[ORGANIZATION]");
client.listNotificationChannelDescriptors(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations