From be6d79465031071b33cd1c174810889a4a310698 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Thu, 12 Mar 2020 15:01:01 -0700 Subject: [PATCH] Ensure we can never double assign same datasource ID to agent config --- .../ingest_manager/server/services/agent_config.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/services/agent_config.ts b/x-pack/plugins/ingest_manager/server/services/agent_config.ts index 93acca7cce01d..e5b20de3bf911 100644 --- a/x-pack/plugins/ingest_manager/server/services/agent_config.ts +++ b/x-pack/plugins/ingest_manager/server/services/agent_config.ts @@ -3,6 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { uniq } from 'lodash'; import { SavedObjectsClientContract } from 'kibana/server'; import { AuthenticatedUser } from '../../../security/server'; import { DEFAULT_AGENT_CONFIG, AGENT_CONFIG_SAVED_OBJECT_TYPE } from '../constants'; @@ -205,7 +206,9 @@ class AgentConfigService { id, { ...oldAgentConfig, - datasources: [...((oldAgentConfig.datasources || []) as string[])].concat(datasourceIds), + datasources: uniq( + [...((oldAgentConfig.datasources || []) as string[])].concat(datasourceIds) + ), }, options?.user ); @@ -228,8 +231,10 @@ class AgentConfigService { id, { ...oldAgentConfig, - datasources: [...((oldAgentConfig.datasources || []) as string[])].filter( - dsId => !datasourceIds.includes(dsId) + datasources: uniq( + [...((oldAgentConfig.datasources || []) as string[])].filter( + dsId => !datasourceIds.includes(dsId) + ) ), }, options?.user