Search in sources :

Example 1 with NotificationConfig

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()));
}
Also used : ListNotificationConfigsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListNotificationConfigsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 2 with NotificationConfig

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;
    }
}
Also used : NotificationConfig(com.google.cloud.securitycenter.v1.NotificationConfig) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) FieldMask(com.google.protobuf.FieldMask)

Example 3 with NotificationConfig

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;
    }
}
Also used : OrganizationName(com.google.cloud.securitycenter.v1.OrganizationName) ListNotificationConfigsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListNotificationConfigsPagedResponse) NotificationConfig(com.google.cloud.securitycenter.v1.NotificationConfig) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 4 with NotificationConfig

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;
    }
}
Also used : NotificationConfig(com.google.cloud.securitycenter.v1.NotificationConfig) CreateNotificationConfigRequest(com.google.cloud.securitycenter.v1.CreateNotificationConfigRequest) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 5 with NotificationConfig

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;
    }
}
Also used : NotificationConfig(com.google.cloud.securitycenter.v1.NotificationConfig) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Aggregations

NotificationConfig (com.google.cloud.securitycenter.v1.NotificationConfig)4 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)4 ListNotificationConfigsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListNotificationConfigsPagedResponse)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 CreateNotificationConfigRequest (com.google.cloud.securitycenter.v1.CreateNotificationConfigRequest)1 OrganizationName (com.google.cloud.securitycenter.v1.OrganizationName)1 ByteString (com.google.protobuf.ByteString)1 FieldMask (com.google.protobuf.FieldMask)1