use of com.google.cloud.securitycenter.v1.NotificationConfig in project java-securitycenter by googleapis.
the class SecurityCenterClientTest method listNotificationConfigsTest.
@Test
public void listNotificationConfigsTest() throws Exception {
NotificationConfig responsesElement = NotificationConfig.newBuilder().build();
ListNotificationConfigsResponse expectedResponse = ListNotificationConfigsResponse.newBuilder().setNextPageToken("").addAllNotificationConfigs(Arrays.asList(responsesElement)).build();
mockSecurityCenter.addResponse(expectedResponse);
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
ListNotificationConfigsPagedResponse pagedListResponse = client.listNotificationConfigs(parent);
List<NotificationConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getNotificationConfigsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSecurityCenter.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListNotificationConfigsRequest actualRequest = ((ListNotificationConfigsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.securitycenter.v1.NotificationConfig in project java-securitycenter by googleapis.
the class UpdateNotificationConfigSnippets method updateNotificationConfig.
// [START securitycenter_update_notification_config]
public static NotificationConfig updateNotificationConfig(String organizationId, String notificationConfigId, String projectId, String topicName) throws IOException {
// String organizationId = "{your-org-id}";
// String notificationConfigId = "{your-config-id}";
// String projectId = "{your-project}";
// String topicName = "{your-topic}";
String notificationConfigName = String.format("organizations/%s/notificationConfigs/%s", organizationId, notificationConfigId);
// Ensure this ServiceAccount has the "pubsub.topics.setIamPolicy" permission on the topic.
String pubsubTopic = String.format("projects/%s/topics/%s", projectId, topicName);
NotificationConfig configToUpdate = NotificationConfig.newBuilder().setName(notificationConfigName).setDescription("updated description").setPubsubTopic(pubsubTopic).setStreamingConfig(StreamingConfig.newBuilder().setFilter("state = \"ACTIVE\"")).build();
FieldMask fieldMask = FieldMask.newBuilder().addPaths("description").addPaths("pubsub_topic").addPaths("streaming_config.filter").build();
try (SecurityCenterClient client = SecurityCenterClient.create()) {
NotificationConfig updatedConfig = client.updateNotificationConfig(configToUpdate, fieldMask);
System.out.println(String.format("Notification config: %s", updatedConfig));
return updatedConfig;
}
}
use of com.google.cloud.securitycenter.v1.NotificationConfig in project java-securitycenter by googleapis.
the class ListNotificationConfigSnippets method listNotificationConfigs.
// [START securitycenter_list_notification_configs]
public static ImmutableList<NotificationConfig> listNotificationConfigs(String organizationId) throws IOException {
// String organizationId = "{your-org-id}";
OrganizationName orgName = OrganizationName.newBuilder().setOrganization(organizationId).build();
try (SecurityCenterClient client = SecurityCenterClient.create()) {
ListNotificationConfigsPagedResponse response = client.listNotificationConfigs(orgName);
ImmutableList<NotificationConfig> notificationConfigs = ImmutableList.copyOf(response.iterateAll());
System.out.println(String.format("List notifications response: %s", response.getPage().getValues()));
return notificationConfigs;
}
}
use of com.google.cloud.securitycenter.v1.NotificationConfig in project java-securitycenter by googleapis.
the class CreateNotificationConfigSnippets method createNotificationConfig.
// [START securitycenter_create_notification_config]
public static NotificationConfig createNotificationConfig(String organizationId, String notificationConfigId, String projectId, String topicName) throws IOException {
// String organizationId = "{your-org-id}";
// String notificationConfigId = {"your-unique-id"};
// String projectId = "{your-project}"";
// String topicName = "{your-topic}";
String orgName = String.format("organizations/%s", organizationId);
// Ensure this ServiceAccount has the "pubsub.topics.setIamPolicy" permission on the topic.
String pubsubTopic = String.format("projects/%s/topics/%s", projectId, topicName);
try (SecurityCenterClient client = SecurityCenterClient.create()) {
CreateNotificationConfigRequest request = CreateNotificationConfigRequest.newBuilder().setParent(orgName).setConfigId(notificationConfigId).setNotificationConfig(NotificationConfig.newBuilder().setDescription("Java notification config").setPubsubTopic(pubsubTopic).setStreamingConfig(StreamingConfig.newBuilder().setFilter("state = \"ACTIVE\"").build()).build()).build();
NotificationConfig response = client.createNotificationConfig(request);
System.out.println(String.format("Notification config was created: %s", response));
return response;
}
}
use of com.google.cloud.securitycenter.v1.NotificationConfig in project java-securitycenter by googleapis.
the class GetNotificationConfigSnippets method getNotificationConfig.
// [START securitycenter_get_notification_config]
public static NotificationConfig getNotificationConfig(String organizationId, String notificationConfigId) throws IOException {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
NotificationConfig response = client.getNotificationConfig(NotificationConfigName.newBuilder().setOrganization(organizationId).setNotificationConfig(notificationConfigId).build());
System.out.println(String.format("Notification config: %s", response));
return response;
}
}
Aggregations