Skip to content

Commit

Permalink
Ensure we can never double assign same datasource ID to agent config
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Mar 12, 2020
1 parent 11518e3 commit be6d794
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions x-pack/plugins/ingest_manager/server/services/agent_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
);
Expand All @@ -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
Expand Down

0 comments on commit be6d794

Please sign in to comment.