Skip to content

Commit

Permalink
Fix deepmerge
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Nov 1, 2021
1 parent c641e87 commit d4e3cef
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions x-pack/plugins/fleet/server/services/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ export function overridePackageInputs(
for (const override of inputsOverride) {
// Preconfiguration does not currently support multiple policy templates, so overrides will have an undefined
// policy template, so we only match on `type` in that case.
const originalInput = override.policy_template
let originalInput = override.policy_template
? inputs.find(
(i) => i.type === override.type && i.policy_template === override.policy_template
)
Expand All @@ -1112,13 +1112,14 @@ export function overridePackageInputs(
}

if (override.vars) {
// deepMerge mutate the input
deepMergeVars(originalInput, override) as NewPackagePolicyInput;
const indexOfInput = inputs.indexOf(originalInput);
inputs[indexOfInput] = deepMergeVars(originalInput, override) as NewPackagePolicyInput;
originalInput = inputs[indexOfInput];
}

if (override.streams) {
for (const stream of override.streams) {
const originalStream = originalInput?.streams.find(
let originalStream = originalInput?.streams.find(
(s) => s.data_stream.dataset === stream.data_stream.dataset
);

Expand All @@ -1132,8 +1133,12 @@ export function overridePackageInputs(
}

if (stream.vars) {
// deepMerge mutate the stream
deepMergeVars(originalStream, stream as InputsOverride);
const indexOfStream = originalInput.streams.indexOf(originalStream);
originalInput.streams[indexOfStream] = deepMergeVars(
originalStream,
stream as InputsOverride
);
originalStream = originalInput.streams[indexOfStream];
}
}
}
Expand Down

0 comments on commit d4e3cef

Please sign in to comment.