From 76d5445858d05a47778beaa157d4bdb41bc050af Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Tue, 18 May 2021 16:18:02 +0200 Subject: [PATCH] fix security solution schema --- .../common/endpoint/schema/trusted_apps.ts | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/security_solution/common/endpoint/schema/trusted_apps.ts b/x-pack/plugins/security_solution/common/endpoint/schema/trusted_apps.ts index 54d0becd2446e..d6f1307b5d1be 100644 --- a/x-pack/plugins/security_solution/common/endpoint/schema/trusted_apps.ts +++ b/x-pack/plugins/security_solution/common/endpoint/schema/trusted_apps.ts @@ -87,39 +87,37 @@ const MacEntrySchema = schema.object({ ...CommonEntrySchema, }); +const entriesSchemaOptions = { + minSize: 1, + validate(entries: ConditionEntry[]) { + return ( + getDuplicateFields(entries) + .map((field) => `duplicatedEntry.${field}`) + .join(', ') || undefined + ); + }, +}; + /* - * Entry Schema depending on Os type using schema.conditional. + * Entities array schema depending on Os type using schema.conditional. * If OS === WINDOWS then use Windows schema, * else if OS === LINUX then use Linux schema, * else use Mac schema + * + * The validate function checks there is no duplicated entry inside the array */ -const EntrySchemaDependingOnOS = schema.conditional( +const EntriesSchema = schema.conditional( schema.siblingRef('os'), OperatingSystem.WINDOWS, - WindowsEntrySchema, + schema.arrayOf(WindowsEntrySchema, entriesSchemaOptions), schema.conditional( schema.siblingRef('os'), OperatingSystem.LINUX, - LinuxEntrySchema, - MacEntrySchema + schema.arrayOf(LinuxEntrySchema, entriesSchemaOptions), + schema.arrayOf(MacEntrySchema, entriesSchemaOptions) ) ); -/* - * Entities array schema. - * The validate function checks there is no duplicated entry inside the array - */ -const EntriesSchema = schema.arrayOf(EntrySchemaDependingOnOS, { - minSize: 1, - validate(entries: ConditionEntry[]) { - return ( - getDuplicateFields(entries) - .map((field) => `duplicatedEntry.${field}`) - .join(', ') || undefined - ); - }, -}); - const getTrustedAppForOsScheme = (forUpdateFlow: boolean = false) => schema.object({ name: schema.string({ minLength: 1, maxLength: 256 }),