From 1e6ed3d122294c7e2050210e01b183fac3f2a480 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 7 Sep 2022 12:09:05 -0700 Subject: [PATCH] Change the SendTestMessage API to be a POST call (#506) (#523) * Change the SendTestMessage API to be a POST call Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> * Include GET send test message path as a depricated option until next major version Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> * Update documentation comment for SendTestMessage replaced route Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> (cherry picked from commit 10179715af4836395eb2ed7c1a78883cdd345fd3) Co-authored-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> --- .../public/services/NotificationService.ts | 2 +- .../server/clusters/notificationsPlugin.ts | 2 +- .../server/routes/eventRoutes.ts | 2 +- .../resthandler/SendTestMessageRestHandler.kt | 13 ++++++++----- .../integtest/send/SendTestMessageRestHandlerIT.kt | 8 ++++---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/dashboards-notifications/public/services/NotificationService.ts b/dashboards-notifications/public/services/NotificationService.ts index 09308026..f9e166da 100644 --- a/dashboards-notifications/public/services/NotificationService.ts +++ b/dashboards-notifications/public/services/NotificationService.ts @@ -246,7 +246,7 @@ export default class NotificationService { sendTestMessage = async ( configId: string ) => { - const response = await this.httpClient.get( + const response = await this.httpClient.post( `${NODE_API.SEND_TEST_MESSAGE}/${configId}` ); if (response.status_list[0].delivery_status.status_code != 200) { diff --git a/dashboards-notifications/server/clusters/notificationsPlugin.ts b/dashboards-notifications/server/clusters/notificationsPlugin.ts index 89c1b1a4..8ccecf7c 100644 --- a/dashboards-notifications/server/clusters/notificationsPlugin.ts +++ b/dashboards-notifications/server/clusters/notificationsPlugin.ts @@ -89,7 +89,7 @@ export function NotificationsPlugin(Client: any, config: any, components: any) { }, }, }, - method: 'GET', + method: 'POST', }); notifications.getServerFeatures = clientAction({ diff --git a/dashboards-notifications/server/routes/eventRoutes.ts b/dashboards-notifications/server/routes/eventRoutes.ts index d99f805a..fd7400f2 100644 --- a/dashboards-notifications/server/routes/eventRoutes.ts +++ b/dashboards-notifications/server/routes/eventRoutes.ts @@ -40,7 +40,7 @@ export function eventRoutes(router: IRouter) { } ); - router.get( + router.post( { path: `${NODE_API.SEND_TEST_MESSAGE}/{configId}`, validate: { diff --git a/notifications/notifications/src/main/kotlin/org/opensearch/notifications/resthandler/SendTestMessageRestHandler.kt b/notifications/notifications/src/main/kotlin/org/opensearch/notifications/resthandler/SendTestMessageRestHandler.kt index 1720bc87..5963d6b5 100644 --- a/notifications/notifications/src/main/kotlin/org/opensearch/notifications/resthandler/SendTestMessageRestHandler.kt +++ b/notifications/notifications/src/main/kotlin/org/opensearch/notifications/resthandler/SendTestMessageRestHandler.kt @@ -13,9 +13,10 @@ import org.opensearch.notifications.metrics.Metrics import org.opensearch.notifications.model.SendTestNotificationRequest import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse -import org.opensearch.rest.RestHandler.Route +import org.opensearch.rest.RestHandler.ReplacedRoute import org.opensearch.rest.RestRequest import org.opensearch.rest.RestRequest.Method.GET +import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.RestStatus /** @@ -39,15 +40,16 @@ internal class SendTestMessageRestHandler : PluginBaseHandler() { /** * {@inheritDoc} */ - override fun routes(): List { + override fun replacedRoutes(): List { return listOf( /** - * Get notification features - * Request URL: GET [REQUEST_URL/CONFIG_ID_TAG] + * Send test notification message + * Request URL: POST [REQUEST_URL/CONFIG_ID_TAG] * Request body: Ref [org.opensearch.commons.notifications.action.SendNotificationRequest] * Response body: [org.opensearch.commons.notifications.action.SendNotificationResponse] */ - Route(GET, "$REQUEST_URL/{$CONFIG_ID_TAG}") + // Using GET with this API has been deprecated, it will be removed in favor of the POST equivalent in the next major version. + ReplacedRoute(POST, "$REQUEST_URL/{$CONFIG_ID_TAG}", GET, "$REQUEST_URL/{$CONFIG_ID_TAG}") ) } @@ -63,6 +65,7 @@ internal class SendTestMessageRestHandler : PluginBaseHandler() { */ override fun executeRequest(request: RestRequest, client: NodeClient): RestChannelConsumer { return when (request.method()) { + POST -> executeSendTestMessage(request, client) GET -> executeSendTestMessage(request, client) else -> RestChannelConsumer { it.sendResponse(BytesRestResponse(RestStatus.METHOD_NOT_ALLOWED, "${request.method()} is not allowed")) diff --git a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt index e7f01d1f..5545c6c3 100644 --- a/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt +++ b/notifications/notifications/src/test/kotlin/org/opensearch/integtest/send/SendTestMessageRestHandlerIT.kt @@ -42,7 +42,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { // send test message val sendResponse = executeRequest( - RestRequest.Method.GET.name, + RestRequest.Method.POST.name, "$PLUGIN_BASE_URI/feature/test/$configId", "", RestStatus.INTERNAL_SERVER_ERROR.status @@ -81,7 +81,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { // send test message val sendResponse = executeRequest( - RestRequest.Method.GET.name, + RestRequest.Method.POST.name, "$PLUGIN_BASE_URI/feature/test/$configId", "", RestStatus.INTERNAL_SERVER_ERROR.status @@ -123,7 +123,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { // send test message val sendResponse = executeRequest( - RestRequest.Method.GET.name, + RestRequest.Method.POST.name, "$PLUGIN_BASE_URI/feature/test/$configId", "", RestStatus.INTERNAL_SERVER_ERROR.status @@ -199,7 +199,7 @@ internal class SendTestMessageRestHandlerIT : PluginRestTestCase() { // send test message val sendResponse = executeRequest( - RestRequest.Method.GET.name, + RestRequest.Method.POST.name, "$PLUGIN_BASE_URI/feature/test/$emailConfigId", "", RestStatus.SERVICE_UNAVAILABLE.status