Skip to content

Commit f7739b5

Browse files
nchauletjen-huang
andauthored
[Ingest Manager] Fix agent stream to support optionnal yaml root values (#68272)
* [Ingest Manager] Fix agent stream to support optionnal yaml root values * Update x-pack/plugins/ingest_manager/server/services/epm/agent/agent.test.ts Co-authored-by: Jen Huang <its.jenetic@gmail.com> Co-authored-by: Jen Huang <its.jenetic@gmail.com>
1 parent 8fe1eb1 commit f7739b5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

x-pack/plugins/ingest_manager/server/services/epm/agent/agent.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,22 @@ foo: bar
8383
custom: { foo: 'bar' },
8484
});
8585
});
86+
87+
it('should support optional yaml values at root level', () => {
88+
const streamTemplate = `
89+
input: logs
90+
{{custom}}
91+
`;
92+
const vars = {
93+
custom: {
94+
type: 'yaml',
95+
value: null,
96+
},
97+
};
98+
99+
const output = createStream(vars, streamTemplate);
100+
expect(output).toEqual({
101+
input: 'logs',
102+
});
103+
});
86104
});

x-pack/plugins/ingest_manager/server/services/epm/agent/agent.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ function replaceRootLevelYamlVariables(yamlVariables: { [k: string]: any }, yaml
9494

9595
let patchedTemplate = yamlTemplate;
9696
Object.entries(yamlVariables).forEach(([key, val]) => {
97-
patchedTemplate = patchedTemplate.replace(new RegExp(`^"${key}"`, 'gm'), safeDump(val));
97+
patchedTemplate = patchedTemplate.replace(
98+
new RegExp(`^"${key}"`, 'gm'),
99+
val ? safeDump(val) : ''
100+
);
98101
});
99102

100103
return patchedTemplate;

0 commit comments

Comments
 (0)