From f21fdaf563d9cfcbed2adb61f07346f96045136a Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Mon, 2 Dec 2024 08:12:42 -0500 Subject: [PATCH] [Fleet] Support input variable for integrations package (#202362) --- .../package_to_package_policy.test.ts | 39 +++++++++++++++++++ .../services/package_to_package_policy.ts | 4 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/fleet/common/services/package_to_package_policy.test.ts b/x-pack/plugins/fleet/common/services/package_to_package_policy.test.ts index 0918fcaa08d7f..8f96c3ffc197d 100644 --- a/x-pack/plugins/fleet/common/services/package_to_package_policy.test.ts +++ b/x-pack/plugins/fleet/common/services/package_to_package_policy.test.ts @@ -469,6 +469,45 @@ describe('Fleet - packageToPackagePolicy', () => { }); }); + it('returns package policy with inputs variables', () => { + const mockPackageWithPolicyTemplates = { + ...mockPackage, + policy_templates: [ + { inputs: [{ type: 'foo' }] }, + { inputs: [{ type: 'bar', vars: [{ default: 'bar-var-value', name: 'var-name' }] }] }, + ], + } as unknown as PackageInfo; + + expect( + packageToPackagePolicy( + mockPackageWithPolicyTemplates, + 'policy-id-1', + 'default', + 'pkgPolicy-1' + ) + ).toEqual({ + policy_id: 'policy-id-1', + policy_ids: ['policy-id-1'], + namespace: 'default', + enabled: true, + inputs: [ + { type: 'foo', enabled: true, streams: [] }, + { + type: 'bar', + enabled: true, + streams: [], + vars: { 'var-name': { value: 'bar-var-value' } }, + }, + ], + name: 'pkgPolicy-1', + package: { + name: 'mock-package', + title: 'Mock package', + version: '0.0.0', + }, + }); + }); + it('returns package policy with multiple policy templates (aka has integrations', () => { expect( packageToPackagePolicy( diff --git a/x-pack/plugins/fleet/common/services/package_to_package_policy.ts b/x-pack/plugins/fleet/common/services/package_to_package_policy.ts index a830cfd903007..6aed76b0a115b 100644 --- a/x-pack/plugins/fleet/common/services/package_to_package_policy.ts +++ b/x-pack/plugins/fleet/common/services/package_to_package_policy.ts @@ -147,9 +147,7 @@ export const packageToPackagePolicyInputs = ( return stream; }); - // If non-integration package, collect input-level vars, otherwise skip them, - // we do not support input-level vars for packages with integrations yet) - if (packageInput.vars?.length && !hasIntegrations) { + if (packageInput.vars?.length) { varsForInput = packageInput.vars.reduce(varsReducer, {}); }