Skip to content

Commit

Permalink
[Fleet] Fix preconfiguration inputs enablement (#126205) (#126246)
Browse files Browse the repository at this point in the history
(cherry picked from commit b1444ca)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
  • Loading branch information
kibanamachine and nchaulet authored Feb 23, 2022
1 parent bccd5f9 commit 3e97bfe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions x-pack/plugins/fleet/server/services/package_policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,8 +1654,8 @@ describe('Package policy service', () => {
});
});

describe('when an input or stream is disabled on the original policy object', () => {
it('remains disabled on the resulting policy object', () => {
describe('when an input or stream is disabled by default in the package', () => {
it('allow preconfiguration to enable it', () => {
const basePackagePolicy: NewPackagePolicy = {
name: 'base-package-policy',
description: 'Base Package Policy',
Expand Down Expand Up @@ -1864,13 +1864,13 @@ describe('Package policy service', () => {
expect(template2Inputs).toHaveLength(1);

const logsInput = template1Inputs?.find((input) => input.type === 'logs');
expect(logsInput?.enabled).toBe(false);
expect(logsInput?.enabled).toBe(true);

const logfileStream = logsInput?.streams.find(
(stream) => stream.data_stream.type === 'logfile'
);

expect(logfileStream?.enabled).toBe(false);
expect(logfileStream?.enabled).toBe(true);
});
});

Expand Down
9 changes: 3 additions & 6 deletions x-pack/plugins/fleet/server/services/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1292,14 +1292,11 @@ export function preconfigurePackageInputs(
continue;
}

// For flags like this, we only want to override the original value if it was set
// as `undefined` in the original object. An explicit true/false value should be
// persisted from the original object to the result after the override process is complete.
if (originalInput.enabled === undefined && preconfiguredInput.enabled !== undefined) {
if (preconfiguredInput.enabled !== undefined) {
originalInput.enabled = preconfiguredInput.enabled;
}

if (originalInput.keep_enabled === undefined && preconfiguredInput.keep_enabled !== undefined) {
if (preconfiguredInput.keep_enabled !== undefined) {
originalInput.keep_enabled = preconfiguredInput.keep_enabled;
}

Expand All @@ -1322,7 +1319,7 @@ export function preconfigurePackageInputs(
continue;
}

if (originalStream?.enabled === undefined) {
if (stream.enabled !== undefined) {
originalStream.enabled = stream.enabled;
}

Expand Down

0 comments on commit 3e97bfe

Please sign in to comment.