diff --git a/x-pack/plugins/actions/server/routes/create.ts b/x-pack/plugins/actions/server/routes/create.ts index 2150dc4076449..f8f9aff9323a0 100644 --- a/x-pack/plugins/actions/server/routes/create.ts +++ b/x-pack/plugins/actions/server/routes/create.ts @@ -41,9 +41,6 @@ export const createActionRoute = (router: IRouter, licenseState: LicenseState) = ): Promise> { verifyApiAccess(licenseState); - if (!context.actions) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' }); - } const actionsClient = context.actions.getActionsClient(); const action = req.body; const actionRes: ActionResult = await actionsClient.create({ action }); diff --git a/x-pack/plugins/actions/server/routes/delete.ts b/x-pack/plugins/actions/server/routes/delete.ts index 8508137b97750..d96523997ad34 100644 --- a/x-pack/plugins/actions/server/routes/delete.ts +++ b/x-pack/plugins/actions/server/routes/delete.ts @@ -41,9 +41,6 @@ export const deleteActionRoute = (router: IRouter, licenseState: LicenseState) = res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.actions) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' }); - } const actionsClient = context.actions.getActionsClient(); const { id } = req.params; await actionsClient.delete({ id }); diff --git a/x-pack/plugins/actions/server/routes/find.ts b/x-pack/plugins/actions/server/routes/find.ts index 71d4274980fcc..e791aff4fb598 100644 --- a/x-pack/plugins/actions/server/routes/find.ts +++ b/x-pack/plugins/actions/server/routes/find.ts @@ -57,9 +57,6 @@ export const findActionRoute = (router: IRouter, licenseState: LicenseState) => res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.actions) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' }); - } const actionsClient = context.actions.getActionsClient(); const query = req.query; const options: FindOptions['options'] = { diff --git a/x-pack/plugins/actions/server/routes/get.ts b/x-pack/plugins/actions/server/routes/get.ts index 836f46bfe55fd..26aa74da5d36b 100644 --- a/x-pack/plugins/actions/server/routes/get.ts +++ b/x-pack/plugins/actions/server/routes/get.ts @@ -36,9 +36,6 @@ export const getActionRoute = (router: IRouter, licenseState: LicenseState) => { res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.actions) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' }); - } const actionsClient = context.actions.getActionsClient(); const { id } = req.params; return res.ok({ diff --git a/x-pack/plugins/actions/server/routes/list_action_types.test.ts b/x-pack/plugins/actions/server/routes/list_action_types.test.ts index e983b8d1f2f84..87cc4dfee5336 100644 --- a/x-pack/plugins/actions/server/routes/list_action_types.test.ts +++ b/x-pack/plugins/actions/server/routes/list_action_types.test.ts @@ -58,7 +58,7 @@ describe('listActionTypesRoute', () => { } `); - expect(context.actions!.listTypes).toHaveBeenCalledTimes(1); + expect(context.actions.listTypes).toHaveBeenCalledTimes(1); expect(res.ok).toHaveBeenCalledWith({ body: listTypes, diff --git a/x-pack/plugins/actions/server/routes/list_action_types.ts b/x-pack/plugins/actions/server/routes/list_action_types.ts index 46f62e3a9c8bb..0b9791eedb39c 100644 --- a/x-pack/plugins/actions/server/routes/list_action_types.ts +++ b/x-pack/plugins/actions/server/routes/list_action_types.ts @@ -29,9 +29,6 @@ export const listActionTypesRoute = (router: IRouter, licenseState: LicenseState res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.actions) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' }); - } return res.ok({ body: context.actions.listTypes(), }); diff --git a/x-pack/plugins/actions/server/routes/update.ts b/x-pack/plugins/actions/server/routes/update.ts index 315695382b2d9..9c5f32e8b9119 100644 --- a/x-pack/plugins/actions/server/routes/update.ts +++ b/x-pack/plugins/actions/server/routes/update.ts @@ -43,9 +43,6 @@ export const updateActionRoute = (router: IRouter, licenseState: LicenseState) = res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.actions) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' }); - } const actionsClient = context.actions.getActionsClient(); const { id } = req.params; const { name, config, secrets } = req.body; diff --git a/x-pack/plugins/actions/server/types.ts b/x-pack/plugins/actions/server/types.ts index 635c0829e02c3..2358f499c9f98 100644 --- a/x-pack/plugins/actions/server/types.ts +++ b/x-pack/plugins/actions/server/types.ts @@ -22,7 +22,7 @@ export interface Services { declare module 'src/core/server' { interface RequestHandlerContext { - actions?: { + actions: { getActionsClient: () => ActionsClient; listTypes: ActionTypeRegistry['list']; }; diff --git a/x-pack/plugins/alerting/server/routes/create.ts b/x-pack/plugins/alerting/server/routes/create.ts index af518499a9abb..8d854e0df8467 100644 --- a/x-pack/plugins/alerting/server/routes/create.ts +++ b/x-pack/plugins/alerting/server/routes/create.ts @@ -57,9 +57,6 @@ export const createAlertRoute = (router: IRouter, licenseState: LicenseState) => ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const alert = req.body; const alertRes: Alert = await alertsClient.create({ data: alert }); diff --git a/x-pack/plugins/alerting/server/routes/delete.ts b/x-pack/plugins/alerting/server/routes/delete.ts index fc36cf91fdad2..0556ef3d66982 100644 --- a/x-pack/plugins/alerting/server/routes/delete.ts +++ b/x-pack/plugins/alerting/server/routes/delete.ts @@ -36,9 +36,6 @@ export const deleteAlertRoute = (router: IRouter, licenseState: LicenseState) => res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; await alertsClient.delete({ id }); diff --git a/x-pack/plugins/alerting/server/routes/disable.ts b/x-pack/plugins/alerting/server/routes/disable.ts index da6562fb82af1..5c6d977e62c38 100644 --- a/x-pack/plugins/alerting/server/routes/disable.ts +++ b/x-pack/plugins/alerting/server/routes/disable.ts @@ -36,9 +36,6 @@ export const disableAlertRoute = (router: IRouter, licenseState: LicenseState) = res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; await alertsClient.disable({ id }); diff --git a/x-pack/plugins/alerting/server/routes/enable.ts b/x-pack/plugins/alerting/server/routes/enable.ts index 1b995b7eb79b3..f75344ad85998 100644 --- a/x-pack/plugins/alerting/server/routes/enable.ts +++ b/x-pack/plugins/alerting/server/routes/enable.ts @@ -36,9 +36,6 @@ export const enableAlertRoute = (router: IRouter, licenseState: LicenseState) => res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; await alertsClient.enable({ id }); diff --git a/x-pack/plugins/alerting/server/routes/find.ts b/x-pack/plugins/alerting/server/routes/find.ts index efc5c3ea97183..16f53aa218895 100644 --- a/x-pack/plugins/alerting/server/routes/find.ts +++ b/x-pack/plugins/alerting/server/routes/find.ts @@ -57,9 +57,6 @@ export const findAlertRoute = (router: IRouter, licenseState: LicenseState) => { res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const query = req.query; const options: FindOptions['options'] = { diff --git a/x-pack/plugins/alerting/server/routes/get.ts b/x-pack/plugins/alerting/server/routes/get.ts index 3fa2040aabc1f..407d80b0f87ab 100644 --- a/x-pack/plugins/alerting/server/routes/get.ts +++ b/x-pack/plugins/alerting/server/routes/get.ts @@ -36,9 +36,6 @@ export const getAlertRoute = (router: IRouter, licenseState: LicenseState) => { res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; return res.ok({ diff --git a/x-pack/plugins/alerting/server/routes/get_alert_state.ts b/x-pack/plugins/alerting/server/routes/get_alert_state.ts index 725b9139b2837..b419889eea422 100644 --- a/x-pack/plugins/alerting/server/routes/get_alert_state.ts +++ b/x-pack/plugins/alerting/server/routes/get_alert_state.ts @@ -36,9 +36,6 @@ export const getAlertStateRoute = (router: IRouter, licenseState: LicenseState) res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; const state = await alertsClient.getAlertState({ id }); diff --git a/x-pack/plugins/alerting/server/routes/list_alert_types.test.ts b/x-pack/plugins/alerting/server/routes/list_alert_types.test.ts index 723fd86fca8b5..96ee8c5717453 100644 --- a/x-pack/plugins/alerting/server/routes/list_alert_types.test.ts +++ b/x-pack/plugins/alerting/server/routes/list_alert_types.test.ts @@ -70,7 +70,7 @@ describe('listAlertTypesRoute', () => { } `); - expect(context.alerting!.listTypes).toHaveBeenCalledTimes(1); + expect(context.alerting.listTypes).toHaveBeenCalledTimes(1); expect(res.ok).toHaveBeenCalledWith({ body: listTypes, diff --git a/x-pack/plugins/alerting/server/routes/list_alert_types.ts b/x-pack/plugins/alerting/server/routes/list_alert_types.ts index 6e2b7ebb9014c..e33bb9a010bf7 100644 --- a/x-pack/plugins/alerting/server/routes/list_alert_types.ts +++ b/x-pack/plugins/alerting/server/routes/list_alert_types.ts @@ -29,9 +29,6 @@ export const listAlertTypesRoute = (router: IRouter, licenseState: LicenseState) res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } return res.ok({ body: context.alerting.listTypes(), }); diff --git a/x-pack/plugins/alerting/server/routes/mute_all.ts b/x-pack/plugins/alerting/server/routes/mute_all.ts index 224c7e3bf7ea9..796efd457f478 100644 --- a/x-pack/plugins/alerting/server/routes/mute_all.ts +++ b/x-pack/plugins/alerting/server/routes/mute_all.ts @@ -36,9 +36,6 @@ export const muteAllAlertRoute = (router: IRouter, licenseState: LicenseState) = res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; await alertsClient.muteAll({ id }); diff --git a/x-pack/plugins/alerting/server/routes/mute_instance.ts b/x-pack/plugins/alerting/server/routes/mute_instance.ts index c0d9f01a99e23..bae7b00548a26 100644 --- a/x-pack/plugins/alerting/server/routes/mute_instance.ts +++ b/x-pack/plugins/alerting/server/routes/mute_instance.ts @@ -37,9 +37,6 @@ export const muteAlertInstanceRoute = (router: IRouter, licenseState: LicenseSta res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { alertId, alertInstanceId } = req.params; await alertsClient.muteInstance({ alertId, alertInstanceId }); diff --git a/x-pack/plugins/alerting/server/routes/unmute_all.ts b/x-pack/plugins/alerting/server/routes/unmute_all.ts index 4ab009b5722a9..5483f691b5462 100644 --- a/x-pack/plugins/alerting/server/routes/unmute_all.ts +++ b/x-pack/plugins/alerting/server/routes/unmute_all.ts @@ -36,9 +36,6 @@ export const unmuteAllAlertRoute = (router: IRouter, licenseState: LicenseState) res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; await alertsClient.unmuteAll({ id }); diff --git a/x-pack/plugins/alerting/server/routes/unmute_instance.ts b/x-pack/plugins/alerting/server/routes/unmute_instance.ts index 26439d47f430e..fc24ea88ddb67 100644 --- a/x-pack/plugins/alerting/server/routes/unmute_instance.ts +++ b/x-pack/plugins/alerting/server/routes/unmute_instance.ts @@ -37,9 +37,6 @@ export const unmuteAlertInstanceRoute = (router: IRouter, licenseState: LicenseS res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { alertId, alertInstanceId } = req.params; await alertsClient.unmuteInstance({ alertId, alertInstanceId }); diff --git a/x-pack/plugins/alerting/server/routes/update.ts b/x-pack/plugins/alerting/server/routes/update.ts index 76b864a51aec6..a402d13c5fbab 100644 --- a/x-pack/plugins/alerting/server/routes/update.ts +++ b/x-pack/plugins/alerting/server/routes/update.ts @@ -57,9 +57,6 @@ export const updateAlertRoute = (router: IRouter, licenseState: LicenseState) => res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; const { name, actions, params, schedule, tags } = req.body; diff --git a/x-pack/plugins/alerting/server/routes/update_api_key.ts b/x-pack/plugins/alerting/server/routes/update_api_key.ts index 3c8a7d911b158..0951b6c7b939e 100644 --- a/x-pack/plugins/alerting/server/routes/update_api_key.ts +++ b/x-pack/plugins/alerting/server/routes/update_api_key.ts @@ -36,9 +36,6 @@ export const updateApiKeyRoute = (router: IRouter, licenseState: LicenseState) = res: KibanaResponseFactory ): Promise> { verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } const alertsClient = context.alerting.getAlertsClient(); const { id } = req.params; await alertsClient.updateApiKey({ id }); diff --git a/x-pack/plugins/alerting/server/types.ts b/x-pack/plugins/alerting/server/types.ts index 635cf0cbd1371..90bc7996729a6 100644 --- a/x-pack/plugins/alerting/server/types.ts +++ b/x-pack/plugins/alerting/server/types.ts @@ -21,7 +21,7 @@ export type SpaceIdToNamespaceFunction = (spaceId?: string) => string | undefine declare module 'src/core/server' { interface RequestHandlerContext { - alerting?: { + alerting: { getAlertsClient: () => AlertsClient; listTypes: AlertTypeRegistry['list']; };