Skip to content

Commit

Permalink
Change the SendTestMessage API to be a POST call (#506) (#523)
Browse files Browse the repository at this point in the history
* 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 1017971)

Co-authored-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>
  • Loading branch information
opensearch-trigger-bot[bot] and qreshi authored Sep 7, 2022
1 parent 554ec22 commit 1e6ed3d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function NotificationsPlugin(Client: any, config: any, components: any) {
},
},
},
method: 'GET',
method: 'POST',
});

notifications.getServerFeatures = clientAction({
Expand Down
2 changes: 1 addition & 1 deletion dashboards-notifications/server/routes/eventRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function eventRoutes(router: IRouter) {
}
);

router.get(
router.post(
{
path: `${NODE_API.SEND_TEST_MESSAGE}/{configId}`,
validate: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -39,15 +40,16 @@ internal class SendTestMessageRestHandler : PluginBaseHandler() {
/**
* {@inheritDoc}
*/
override fun routes(): List<Route> {
override fun replacedRoutes(): List<ReplacedRoute> {
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}")
)
}

Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1e6ed3d

Please sign in to comment.