From a8a4c46199b634787360f8c630fd68b944e3b7e6 Mon Sep 17 00:00:00 2001 From: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> Date: Tue, 16 Aug 2022 16:24:11 -0700 Subject: [PATCH 1/3] Change the SendTestMessage API to be a POST call Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> --- .../public/services/NotificationService.ts | 2 +- .../server/clusters/notificationsPlugin.ts | 2 +- dashboards-notifications/server/routes/eventRoutes.ts | 2 +- .../resthandler/SendTestMessageRestHandler.kt | 8 ++++---- .../integtest/send/SendTestMessageRestHandlerIT.kt | 8 ++++---- 5 files changed, 11 insertions(+), 11 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..f531b0d8 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 @@ -15,7 +15,7 @@ import org.opensearch.rest.BaseRestHandler.RestChannelConsumer import org.opensearch.rest.BytesRestResponse import org.opensearch.rest.RestHandler.Route import org.opensearch.rest.RestRequest -import org.opensearch.rest.RestRequest.Method.GET +import org.opensearch.rest.RestRequest.Method.POST import org.opensearch.rest.RestStatus /** @@ -43,11 +43,11 @@ internal class SendTestMessageRestHandler : PluginBaseHandler() { return listOf( /** * Get notification features - * Request URL: GET [REQUEST_URL/CONFIG_ID_TAG] + * 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}") + Route(POST, "$REQUEST_URL/{$CONFIG_ID_TAG}") ) } @@ -63,7 +63,7 @@ internal class SendTestMessageRestHandler : PluginBaseHandler() { */ override fun executeRequest(request: RestRequest, client: NodeClient): RestChannelConsumer { return when (request.method()) { - GET -> executeSendTestMessage(request, client) + POST -> 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 From 176ff1b07ad2bf721b4f01087b2881a58f52a63c Mon Sep 17 00:00:00 2001 From: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> Date: Mon, 22 Aug 2022 16:26:32 -0700 Subject: [PATCH 2/3] 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> --- .../resthandler/SendTestMessageRestHandler.kt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) 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 f531b0d8..26daa40a 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,8 +13,9 @@ 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,10 @@ internal class SendTestMessageRestHandler : PluginBaseHandler() { /** * {@inheritDoc} */ - override fun routes(): List { + override fun replacedRoutes(): List { return listOf( - /** - * Get notification features - * 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(POST, "$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}") ) } @@ -64,6 +60,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")) } From 64b6037f43533f7913593f092a290e3920ef08e7 Mon Sep 17 00:00:00 2001 From: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> Date: Tue, 6 Sep 2022 09:57:11 -0700 Subject: [PATCH 3/3] Update documentation comment for SendTestMessage replaced route Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> --- .../notifications/resthandler/SendTestMessageRestHandler.kt | 6 ++++++ 1 file changed, 6 insertions(+) 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 26daa40a..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 @@ -42,6 +42,12 @@ internal class SendTestMessageRestHandler : PluginBaseHandler() { */ override fun replacedRoutes(): List { return listOf( + /** + * 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] + */ // 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}") )