From 4dec15183c0f1f1adf6f4daf107d8e0da75a9966 Mon Sep 17 00:00:00 2001 From: Justin Kambic Date: Wed, 20 Nov 2024 09:22:36 -0500 Subject: [PATCH] Revert changes to `find_rules_route`. --- .../routes/rule/apis/find/find_rules_route.ts | 116 ++---------------- 1 file changed, 11 insertions(+), 105 deletions(-) diff --git a/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.ts b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.ts index 7e3464c7aa9e..90afde8f2081 100644 --- a/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.ts +++ b/x-pack/plugins/alerting/server/routes/rule/apis/find/find_rules_route.ts @@ -7,40 +7,26 @@ import { IRouter } from '@kbn/core/server'; import { UsageCounter } from '@kbn/usage-collection-plugin/server'; -import { ILicenseState } from '../../../../lib'; -import { verifyAccessAndContext } from '../../../lib'; -import { findRulesRequestQuerySchemaV1 } from '../../../../../common/routes/rule/apis/find'; import type { FindRulesRequestQueryV1, FindRulesResponseV1, } from '../../../../../common/routes/rule/apis/find'; +import { findRulesRequestQuerySchemaV1 } from '../../../../../common/routes/rule/apis/find'; import { RuleParamsV1, ruleResponseSchemaV1 } from '../../../../../common/routes/rule/response'; -import { - AlertingRequestHandlerContext, - BASE_ALERTING_API_PATH, - INTERNAL_ALERTING_API_FIND_RULES_PATH, -} from '../../../../types'; +import { ILicenseState } from '../../../../lib'; +import { AlertingRequestHandlerContext, BASE_ALERTING_API_PATH } from '../../../../types'; +import { verifyAccessAndContext } from '../../../lib'; import { trackLegacyTerminology } from '../../../lib/track_legacy_terminology'; import { transformFindRulesBodyV1, transformFindRulesResponseV1 } from './transforms'; -interface BuildFindRulesRouteParams { - licenseState: ILicenseState; - path: string; - router: IRouter; - excludeFromPublicApi?: boolean; - usageCounter?: UsageCounter; -} - -const buildFindRulesRoute = ({ - licenseState, - path, - router, - excludeFromPublicApi = false, - usageCounter, -}: BuildFindRulesRouteParams) => { +export const findRulesRoute = ( + router: IRouter, + licenseState: ILicenseState, + usageCounter?: UsageCounter +) => { router.get( { - path, + path: `${BASE_ALERTING_API_PATH}/rules/_find`, options: { access: 'public', summary: 'Get information about rules', @@ -91,7 +77,7 @@ const buildFindRulesRoute = ({ const findResult = await rulesClient.find({ options, - excludeFromPublicApi, + excludeFromPublicApi: true, includeSnoozeData: true, }); @@ -104,86 +90,6 @@ const buildFindRulesRoute = ({ }) ) ); - if (path === INTERNAL_ALERTING_API_FIND_RULES_PATH) { - router.post( - { - path, - options: { access: 'internal' }, - validate: { - body: findRulesRequestQuerySchemaV1, - }, - }, - router.handleLegacyErrors( - verifyAccessAndContext(licenseState, async function (context, req, res) { - const rulesClient = (await context.alerting).getRulesClient(); - - const body: FindRulesRequestQueryV1 = req.body; - - trackLegacyTerminology( - [req.body.search, req.body.search_fields, req.body.sort_field].filter( - Boolean - ) as string[], - usageCounter - ); - - const options = transformFindRulesBodyV1({ - ...body, - has_reference: body.has_reference || undefined, - search_fields: searchFieldsAsArray(body.search_fields), - }); - - if (req.body.fields) { - usageCounter?.incrementCounter({ - counterName: `alertingFieldsUsage`, - counterType: 'alertingFieldsUsage', - incrementBy: 1, - }); - } - - const findResult = await rulesClient.find({ - options, - excludeFromPublicApi, - includeSnoozeData: true, - }); - - const responseBody: FindRulesResponseV1['body'] = - transformFindRulesResponseV1(findResult, options.fields); - - return res.ok({ - body: responseBody, - }); - }) - ) - ); - } -}; - -export const findRulesRoute = ( - router: IRouter, - licenseState: ILicenseState, - usageCounter?: UsageCounter -) => { - buildFindRulesRoute({ - excludeFromPublicApi: true, - licenseState, - path: `${BASE_ALERTING_API_PATH}/api/alerting/rules/_find`, - router, - usageCounter, - }); -}; - -export const findInternalRulesRoute = ( - router: IRouter, - licenseState: ILicenseState, - usageCounter?: UsageCounter -) => { - buildFindRulesRoute({ - excludeFromPublicApi: false, - licenseState, - path: INTERNAL_ALERTING_API_FIND_RULES_PATH, - router, - usageCounter, - }); }; function searchFieldsAsArray(searchFields: string | string[] | undefined): string[] | undefined {