Skip to content

Commit

Permalink
[Fleet] Fix root level yaml variables dollar escape (elastic#190615)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Aug 15, 2024
1 parent 444b8d0 commit 17b2be1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 19 additions & 0 deletions x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,25 @@ input: logs
});
});

it('should support $$$$ yaml values at root level', () => {
const streamTemplate = `
input: logs
{{custom}}
`;
const vars = {
custom: {
type: 'yaml',
value: 'test: $$$$',
},
};

const output = compileTemplate(vars, streamTemplate);
expect(output).toEqual({
input: 'logs',
test: '$$$$',
});
});

it('should suport !!str for string values', () => {
const stringTemplate = `
my-package:
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/fleet/server/services/epm/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ function replaceRootLevelYamlVariables(yamlVariables: { [k: string]: any }, yaml

let patchedTemplate = yamlTemplate;
Object.entries(yamlVariables).forEach(([key, val]) => {
patchedTemplate = patchedTemplate.replace(
new RegExp(`^"${key}"`, 'gm'),
patchedTemplate = patchedTemplate.replace(new RegExp(`^"${key}"`, 'gm'), () =>
val ? safeDump(val) : ''
);
});
Expand Down

0 comments on commit 17b2be1

Please sign in to comment.