Skip to content

Commit

Permalink
[Fleet] Correctly parse falsy YAML fields in agent policy integrations (
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary authored Apr 1, 2021
1 parent a0fd8e2 commit f543e80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 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 @@ -65,6 +65,12 @@ custom: {{ custom }}
{{#if key.patterns}}
key.patterns: {{key.patterns}}
{{/if}}
{{#if emptyfield}}
emptyfield: {{emptyfield}}
{{/if}}
{{#if nullfield}}
nullfield: {{nullfield}}
{{/if}}
{{ testEmpty }}
`;
const vars = {
Expand All @@ -82,6 +88,8 @@ foo: bar
`,
},
password: { type: 'password', value: '' },
emptyfield: { type: 'yaml', value: '' },
nullfield: { type: 'yaml' },
};

const output = compileTemplate(vars, streamTemplate);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/services/epm/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function buildTemplateVariables(variables: PackagePolicyConfigRecord, templateSt

if (recordEntry.type && recordEntry.type === 'yaml') {
const yamlKeyPlaceholder = `##${key}##`;
varPart[lastKeyPart] = `"${yamlKeyPlaceholder}"`;
varPart[lastKeyPart] = recordEntry.value ? `"${yamlKeyPlaceholder}"` : null;
yamlValues[yamlKeyPlaceholder] = recordEntry.value ? safeLoad(recordEntry.value) : null;
} else if (
recordEntry.type &&
Expand Down

0 comments on commit f543e80

Please sign in to comment.