From 493e54a9e5992348c83f9e691c9e15836ff3df33 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 24 Nov 2020 11:15:12 -0800 Subject: [PATCH] Don't return empty streams in agent yaml when there aren't any --- .../package_policies_to_agent_inputs.test.ts | 1 - .../package_policies_to_agent_inputs.ts | 32 +++++++++++-------- .../fleet/common/types/models/agent_policy.ts | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.test.ts b/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.test.ts index 728e5d439a1e56..a370f92e97fe11 100644 --- a/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.test.ts +++ b/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.test.ts @@ -179,7 +179,6 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => { }, }, inputVar: 'input-value', - streams: [], }, ]); }); diff --git a/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.ts b/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.ts index 452b06cfa0e4ce..d780fb791aa8ea 100644 --- a/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.ts +++ b/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.ts @@ -34,20 +34,24 @@ export const storedPackagePoliciesToAgentInputs = ( return acc; }, {} as { [k: string]: any }), ...(input.compiled_input || {}), - streams: input.streams - .filter((stream) => stream.enabled) - .map((stream) => { - const fullStream: FullAgentPolicyInputStream = { - id: stream.id, - data_stream: stream.data_stream, - ...stream.compiled_stream, - ...Object.entries(stream.config || {}).reduce((acc, [key, { value }]) => { - acc[key] = value; - return acc; - }, {} as { [k: string]: any }), - }; - return fullStream; - }), + ...(input.streams.length + ? { + streams: input.streams + .filter((stream) => stream.enabled) + .map((stream) => { + const fullStream: FullAgentPolicyInputStream = { + id: stream.id, + data_stream: stream.data_stream, + ...stream.compiled_stream, + ...Object.entries(stream.config || {}).reduce((acc, [key, { value }]) => { + acc[key] = value; + return acc; + }, {} as { [k: string]: any }), + }; + return fullStream; + }), + } + : {}), }; if (packagePolicy.package) { diff --git a/x-pack/plugins/fleet/common/types/models/agent_policy.ts b/x-pack/plugins/fleet/common/types/models/agent_policy.ts index f43f65fb317f3b..75bb2998f2d920 100644 --- a/x-pack/plugins/fleet/common/types/models/agent_policy.ts +++ b/x-pack/plugins/fleet/common/types/models/agent_policy.ts @@ -49,7 +49,7 @@ export interface FullAgentPolicyInput { package?: Pick; [key: string]: unknown; }; - streams: FullAgentPolicyInputStream[]; + streams?: FullAgentPolicyInputStream[]; [key: string]: any; }