use of com.google.cloud.securitycenter.v1.CreateNotificationConfigRequest 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;
}
}
Aggregations