Skip to content

Commit

Permalink
[Fleet] Support input variable for integrations package (elastic#202362)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Dec 2, 2024
1 parent 8f12d52 commit f21fdaf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
}

Expand Down

0 comments on commit f21fdaf

Please sign in to comment.