diff --git a/x-pack/plugins/alerting/server/routes/aggregate.ts b/x-pack/plugins/alerting/server/routes/aggregate.ts deleted file mode 100644 index 3538175a7296c..0000000000000 --- a/x-pack/plugins/alerting/server/routes/aggregate.ts +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { renameKeys } from './lib/rename_keys'; -import { FindOptions } from '../alerts_client'; - -// config definition -const querySchema = schema.object({ - search: schema.maybe(schema.string()), - default_search_operator: schema.oneOf([schema.literal('OR'), schema.literal('AND')], { - defaultValue: 'OR', - }), - search_fields: schema.maybe(schema.oneOf([schema.arrayOf(schema.string()), schema.string()])), - has_reference: schema.maybe( - // use nullable as maybe is currently broken - // in config-schema - schema.nullable( - schema.object({ - type: schema.string(), - id: schema.string(), - }) - ) - ), - filter: schema.maybe(schema.string()), -}); - -export const aggregateAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.get( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/_aggregate`, - validate: { - query: querySchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - 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 renameMap = { - default_search_operator: 'defaultSearchOperator', - has_reference: 'hasReference', - search: 'search', - filter: 'filter', - }; - - const options = renameKeys>(renameMap, query); - - if (query.search_fields) { - options.searchFields = Array.isArray(query.search_fields) - ? query.search_fields - : [query.search_fields]; - } - - const aggregateResult = await alertsClient.aggregate({ options }); - return res.ok({ - body: aggregateResult, - }); - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/create.ts b/x-pack/plugins/alerting/server/routes/create.ts deleted file mode 100644 index 660b5389d8f25..0000000000000 --- a/x-pack/plugins/alerting/server/routes/create.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { validateDurationSchema } from '../lib'; -import { handleDisabledApiKeysError } from './lib/error_handler'; -import { - Alert, - AlertNotifyWhenType, - AlertTypeParams, - LEGACY_BASE_ALERT_API_PATH, - validateNotifyWhenType, -} from '../types'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -export const bodySchema = schema.object({ - name: schema.string(), - alertTypeId: schema.string(), - enabled: schema.boolean({ defaultValue: true }), - consumer: schema.string(), - tags: schema.arrayOf(schema.string(), { defaultValue: [] }), - throttle: schema.nullable(schema.string({ validate: validateDurationSchema })), - params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), - schedule: schema.object({ - interval: schema.string({ validate: validateDurationSchema }), - }), - actions: schema.arrayOf( - schema.object({ - group: schema.string(), - id: schema.string(), - actionTypeId: schema.maybe(schema.string()), - params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), - }), - { defaultValue: [] } - ), - notifyWhen: schema.nullable(schema.string({ validate: validateNotifyWhenType })), -}); - -export const createAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.post( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id?}`, - validate: { - params: schema.maybe( - schema.object({ - id: schema.maybe(schema.string()), - }) - ), - body: bodySchema, - }, - }, - handleDisabledApiKeysError( - router.handleLegacyErrors(async function (context, req, res) { - 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 params = req.params; - const notifyWhen = alert?.notifyWhen ? (alert.notifyWhen as AlertNotifyWhenType) : null; - try { - const alertRes: Alert = await alertsClient.create({ - data: { ...alert, notifyWhen }, - options: { id: params?.id }, - }); - return res.ok({ - body: alertRes, - }); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/delete.ts b/x-pack/plugins/alerting/server/routes/delete.ts deleted file mode 100644 index 6302a9cafd0db..0000000000000 --- a/x-pack/plugins/alerting/server/routes/delete.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -export const deleteAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.delete( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}`, - validate: { - params: paramSchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - 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 }); - return res.noContent(); - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/disable.ts b/x-pack/plugins/alerting/server/routes/disable.ts deleted file mode 100644 index 0a596afe55478..0000000000000 --- a/x-pack/plugins/alerting/server/routes/disable.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -export const disableAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.post( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}/_disable`, - validate: { - params: paramSchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } - const alertsClient = context.alerting.getAlertsClient(); - const { id } = req.params; - try { - await alertsClient.disable({ id }); - return res.noContent(); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/enable.ts b/x-pack/plugins/alerting/server/routes/enable.ts deleted file mode 100644 index c1b3724813e4c..0000000000000 --- a/x-pack/plugins/alerting/server/routes/enable.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { handleDisabledApiKeysError } from './lib/error_handler'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -export const enableAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.post( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}/_enable`, - validate: { - params: paramSchema, - }, - }, - handleDisabledApiKeysError( - router.handleLegacyErrors(async function (context, req, res) { - verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } - const alertsClient = context.alerting.getAlertsClient(); - const { id } = req.params; - try { - await alertsClient.enable({ id }); - return res.noContent(); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/find.ts b/x-pack/plugins/alerting/server/routes/find.ts deleted file mode 100644 index 88b168a956efa..0000000000000 --- a/x-pack/plugins/alerting/server/routes/find.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; - -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { renameKeys } from './lib/rename_keys'; -import { FindOptions } from '../alerts_client'; - -// config definition -const querySchema = schema.object({ - per_page: schema.number({ defaultValue: 10, min: 0 }), - page: schema.number({ defaultValue: 1, min: 1 }), - search: schema.maybe(schema.string()), - default_search_operator: schema.oneOf([schema.literal('OR'), schema.literal('AND')], { - defaultValue: 'OR', - }), - search_fields: schema.maybe(schema.oneOf([schema.arrayOf(schema.string()), schema.string()])), - sort_field: schema.maybe(schema.string()), - sort_order: schema.maybe(schema.oneOf([schema.literal('asc'), schema.literal('desc')])), - has_reference: schema.maybe( - // use nullable as maybe is currently broken - // in config-schema - schema.nullable( - schema.object({ - type: schema.string(), - id: schema.string(), - }) - ) - ), - fields: schema.maybe(schema.arrayOf(schema.string())), - filter: schema.maybe(schema.string()), -}); - -export const findAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.get( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/_find`, - validate: { - query: querySchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - 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 renameMap = { - default_search_operator: 'defaultSearchOperator', - fields: 'fields', - has_reference: 'hasReference', - page: 'page', - per_page: 'perPage', - search: 'search', - sort_field: 'sortField', - sort_order: 'sortOrder', - filter: 'filter', - }; - - const options = renameKeys>(renameMap, query); - - if (query.search_fields) { - options.searchFields = Array.isArray(query.search_fields) - ? query.search_fields - : [query.search_fields]; - } - - const findResult = await alertsClient.find({ options }); - return res.ok({ - body: findResult, - }); - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/get.ts b/x-pack/plugins/alerting/server/routes/get.ts deleted file mode 100644 index 107e537228e35..0000000000000 --- a/x-pack/plugins/alerting/server/routes/get.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import type { AlertingRouter } from '../types'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -export const getAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.get( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}`, - validate: { - params: paramSchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - 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({ - body: await alertsClient.get({ id }), - }); - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/get_alert_instance_summary.ts b/x-pack/plugins/alerting/server/routes/get_alert_instance_summary.ts deleted file mode 100644 index 9ae8774a6f809..0000000000000 --- a/x-pack/plugins/alerting/server/routes/get_alert_instance_summary.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -const querySchema = schema.object({ - dateStart: schema.maybe(schema.string()), -}); - -export const getAlertInstanceSummaryRoute = ( - router: AlertingRouter, - licenseState: ILicenseState -) => { - router.get( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}/_instance_summary`, - validate: { - params: paramSchema, - query: querySchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - 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 { dateStart } = req.query; - const summary = await alertsClient.getAlertInstanceSummary({ id, dateStart }); - return res.ok({ body: summary }); - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/get_alert_state.ts b/x-pack/plugins/alerting/server/routes/get_alert_state.ts deleted file mode 100644 index b3b2d1a5ae1ec..0000000000000 --- a/x-pack/plugins/alerting/server/routes/get_alert_state.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -export const getAlertStateRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.get( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}/state`, - validate: { - params: paramSchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - 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 }); - return state ? res.ok({ body: state }) : res.noContent(); - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/legacy/update.ts b/x-pack/plugins/alerting/server/routes/legacy/update.ts index 8e593a47e61a1..23a0719319e00 100644 --- a/x-pack/plugins/alerting/server/routes/legacy/update.ts +++ b/x-pack/plugins/alerting/server/routes/legacy/update.ts @@ -11,8 +11,12 @@ import { ILicenseState } from '../../lib/license_state'; import { verifyApiAccess } from '../../lib/license_api_access'; import { validateDurationSchema } from '../../lib'; import { handleDisabledApiKeysError } from './../lib/error_handler'; -import { AlertNotifyWhenType, LEGACY_BASE_ALERT_API_PATH, validateNotifyWhenType } from '../../../common'; import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled'; +import { + AlertNotifyWhenType, + LEGACY_BASE_ALERT_API_PATH, + validateNotifyWhenType, +} from '../../../common'; const paramSchema = schema.object({ id: schema.string(), diff --git a/x-pack/plugins/alerting/server/routes/list_alert_types.ts b/x-pack/plugins/alerting/server/routes/list_alert_types.ts deleted file mode 100644 index 31661cb481422..0000000000000 --- a/x-pack/plugins/alerting/server/routes/list_alert_types.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; - -export const listAlertTypesRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.get( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/list_alert_types`, - validate: {}, - }, - router.handleLegacyErrors(async function (context, req, res) { - verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } - return res.ok({ - body: Array.from(await context.alerting.getAlertsClient().listAlertTypes()), - }); - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/mute_all.ts b/x-pack/plugins/alerting/server/routes/mute_all.ts deleted file mode 100644 index 07b0f95aaf86e..0000000000000 --- a/x-pack/plugins/alerting/server/routes/mute_all.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -export const muteAllAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.post( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}/_mute_all`, - validate: { - params: paramSchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } - const alertsClient = context.alerting.getAlertsClient(); - const { id } = req.params; - try { - await alertsClient.muteAll({ id }); - return res.noContent(); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/mute_instance.ts b/x-pack/plugins/alerting/server/routes/mute_instance.ts deleted file mode 100644 index 4a69f8c6087f5..0000000000000 --- a/x-pack/plugins/alerting/server/routes/mute_instance.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { renameKeys } from './lib/rename_keys'; -import { MuteOptions } from '../alerts_client'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -const paramSchema = schema.object({ - alert_id: schema.string(), - alert_instance_id: schema.string(), -}); - -export const muteAlertInstanceRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.post( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{alert_id}/alert_instance/{alert_instance_id}/_mute`, - validate: { - params: paramSchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } - const alertsClient = context.alerting.getAlertsClient(); - - const renameMap = { - alert_id: 'alertId', - alert_instance_id: 'alertInstanceId', - }; - - const renamedQuery = renameKeys>(renameMap, req.params); - try { - await alertsClient.muteInstance(renamedQuery); - return res.noContent(); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/unmute_all.ts b/x-pack/plugins/alerting/server/routes/unmute_all.ts deleted file mode 100644 index 7a5168835127b..0000000000000 --- a/x-pack/plugins/alerting/server/routes/unmute_all.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -export const unmuteAllAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.post( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}/_unmute_all`, - validate: { - params: paramSchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } - const alertsClient = context.alerting.getAlertsClient(); - const { id } = req.params; - try { - await alertsClient.unmuteAll({ id }); - return res.noContent(); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/unmute_instance.ts b/x-pack/plugins/alerting/server/routes/unmute_instance.ts deleted file mode 100644 index 604e8576f10f4..0000000000000 --- a/x-pack/plugins/alerting/server/routes/unmute_instance.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -const paramSchema = schema.object({ - alertId: schema.string(), - alertInstanceId: schema.string(), -}); - -export const unmuteAlertInstanceRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.post( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{alertId}/alert_instance/{alertInstanceId}/_unmute`, - validate: { - params: paramSchema, - }, - }, - router.handleLegacyErrors(async function (context, req, res) { - 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; - try { - await alertsClient.unmuteInstance({ alertId, alertInstanceId }); - return res.noContent(); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/update.ts b/x-pack/plugins/alerting/server/routes/update.ts deleted file mode 100644 index 96b76b3c2f115..0000000000000 --- a/x-pack/plugins/alerting/server/routes/update.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { validateDurationSchema } from '../lib'; -import { handleDisabledApiKeysError } from './lib/error_handler'; -import { AlertNotifyWhenType, LEGACY_BASE_ALERT_API_PATH, validateNotifyWhenType } from '../../common'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -const bodySchema = schema.object({ - name: schema.string(), - tags: schema.arrayOf(schema.string(), { defaultValue: [] }), - schedule: schema.object({ - interval: schema.string({ validate: validateDurationSchema }), - }), - throttle: schema.nullable(schema.string({ validate: validateDurationSchema })), - params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), - actions: schema.arrayOf( - schema.object({ - group: schema.string(), - id: schema.string(), - params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), - actionTypeId: schema.maybe(schema.string()), - }), - { defaultValue: [] } - ), - notifyWhen: schema.nullable(schema.string({ validate: validateNotifyWhenType })), -}); - -export const updateAlertRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.put( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}`, - validate: { - body: bodySchema, - params: paramSchema, - }, - }, - handleDisabledApiKeysError( - router.handleLegacyErrors(async function (context, req, res) { - 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, throttle, notifyWhen } = req.body; - try { - const alertRes = await alertsClient.update({ - id, - data: { - name, - actions, - params, - schedule, - tags, - throttle, - notifyWhen: notifyWhen as AlertNotifyWhenType, - }, - }); - return res.ok({ - body: alertRes, - }); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ) - ); -}; diff --git a/x-pack/plugins/alerting/server/routes/update_api_key.ts b/x-pack/plugins/alerting/server/routes/update_api_key.ts deleted file mode 100644 index 7456fb0cb58ba..0000000000000 --- a/x-pack/plugins/alerting/server/routes/update_api_key.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import type { AlertingRouter } from '../types'; -import { ILicenseState } from '../lib/license_state'; -import { verifyApiAccess } from '../lib/license_api_access'; -import { LEGACY_BASE_ALERT_API_PATH } from '../../common'; -import { handleDisabledApiKeysError } from './lib/error_handler'; -import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled'; - -const paramSchema = schema.object({ - id: schema.string(), -}); - -export const updateApiKeyRoute = (router: AlertingRouter, licenseState: ILicenseState) => { - router.post( - { - path: `${LEGACY_BASE_ALERT_API_PATH}/alert/{id}/_update_api_key`, - validate: { - params: paramSchema, - }, - }, - handleDisabledApiKeysError( - router.handleLegacyErrors(async function (context, req, res) { - verifyApiAccess(licenseState); - if (!context.alerting) { - return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' }); - } - const alertsClient = context.alerting.getAlertsClient(); - const { id } = req.params; - try { - await alertsClient.updateApiKey({ id }); - return res.noContent(); - } catch (e) { - if (e instanceof AlertTypeDisabledError) { - return e.sendResponse(res); - } - throw e; - } - }) - ) - ); -};