From defeb5eec63f15944946fd1d97d3a2f9f18d6fcd Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Fri, 14 May 2021 13:31:20 +0200 Subject: [PATCH] remove joi usage from x-pack (#99401) (#100110) * remove unused helper * remove joi usage from Security Solutions Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../server/lib/helpers/input_validation.ts | 23 ------------------- .../lib/detection_engine/routes/utils.ts | 8 +++++-- 2 files changed, 6 insertions(+), 25 deletions(-) delete mode 100644 x-pack/plugins/apm/server/lib/helpers/input_validation.ts diff --git a/x-pack/plugins/apm/server/lib/helpers/input_validation.ts b/x-pack/plugins/apm/server/lib/helpers/input_validation.ts deleted file mode 100644 index 0a34711b9b40db..00000000000000 --- a/x-pack/plugins/apm/server/lib/helpers/input_validation.ts +++ /dev/null @@ -1,23 +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 Joi, { Schema } from 'joi'; -export const dateValidation = Joi.alternatives() - .try(Joi.date().iso(), Joi.number()) - .required(); - -export const withDefaultValidators = ( - validators: { [key: string]: Schema } = {} -) => { - return Joi.object().keys({ - _inspect: Joi.bool(), - start: dateValidation, - end: dateValidation, - uiFilters: Joi.string(), - ...validators, - }); -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts index a6a8cb8dbde0af..c2acbf9c5cc0a3 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts @@ -6,7 +6,6 @@ */ import Boom from '@hapi/boom'; -import Joi from 'joi'; import { errors } from '@elastic/elasticsearch'; import { has, snakeCase } from 'lodash/fp'; import { SanitizedAlert } from '../../../../../alerting/common'; @@ -236,7 +235,12 @@ export const transformBulkError = ( } }; -export const buildRouteValidation = (schema: Joi.Schema): RouteValidationFunction => ( +interface Schema { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + validate: (input: any) => { value: any; error?: Error }; +} + +export const buildRouteValidation = (schema: Schema): RouteValidationFunction => ( payload: T, { ok, badRequest } ) => {