Skip to content

Commit

Permalink
Add compiled input to generated agent yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Nov 20, 2020
1 parent 6120f65 commit 62effd3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
).toEqual([]);
});

it('returns agent inputs', () => {
it('returns agent inputs with streams', () => {
expect(
storedPackagePoliciesToAgentInputs([
{
Expand Down Expand Up @@ -143,6 +143,47 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => {
]);
});

it('returns agent inputs without streams', () => {
expect(
storedPackagePoliciesToAgentInputs([
{
...mockPackagePolicy,
package: {
name: 'mock-package',
title: 'Mock package',
version: '0.0.0',
},
inputs: [
{
...mockInput,
compiled_input: {
inputVar: 'input-value',
},
streams: [],
},
],
},
])
).toEqual([
{
id: 'some-uuid',
name: 'mock-package-policy',
revision: 1,
type: 'test-logs',
data_stream: { namespace: 'default' },
use_output: 'default',
meta: {
package: {
name: 'mock-package',
version: '0.0.0',
},
},
inputVar: 'input-value',
streams: [],
},
]);
});

it('returns agent inputs without disabled streams', () => {
expect(
storedPackagePoliciesToAgentInputs([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const storedPackagePoliciesToAgentInputs = (
acc[key] = value;
return acc;
}, {} as { [k: string]: any }),
...(input.compiled_input || {}),
streams: input.streams
.filter((stream) => stream.enabled)
.map((stream) => {
Expand Down
8 changes: 0 additions & 8 deletions x-pack/plugins/fleet/server/services/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ async function _compilePackagePolicyInput(
pkgInfo: PackageInfo,
input: PackagePolicyInput
) {
console.log('jen in _compilePackagePolicyInput');
if (!input.enabled || !pkgInfo.policy_templates?.[0].inputs) {
return undefined;
}
Expand All @@ -419,12 +418,9 @@ async function _compilePackagePolicyInput(
}

if (!packageInput.template_path) {
console.log('jen in _compilePackagePolicyInput, no template path');
return undefined;
}

console.log('jen in _compilePackagePolicyInput, found input and template path');

const [pkgInputTemplate] = await getAssetsData(registryPkgInfo, (path: string) =>
path.endsWith(`/agent/input/${packageInput.template_path!}`)
);
Expand All @@ -433,10 +429,6 @@ async function _compilePackagePolicyInput(
throw new Error(`Unable to load input template at /agent/input/${packageInput.template_path!}`);
}

console.log(
'jen in _compilePackagePolicyInput, compiling input with',
pkgInputTemplate.buffer.toString()
);
return compileTemplate(
// Populate template variables from input vars
Object.assign({}, input.vars),
Expand Down

0 comments on commit 62effd3

Please sign in to comment.