Skip to content

Commit

Permalink
moved validation error to validatePackagePolicyConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Feb 2, 2022
1 parent 5713420 commit 2e9556e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ describe('Fleet - validatePackagePolicy()', () => {
},
},
vars: {
period: ['linux/metrics has no vars in policy template'],
period: ['period var definition does not exist'],
},
},
},
Expand Down
34 changes: 15 additions & 19 deletions x-pack/plugins/fleet/common/services/validate_package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,12 @@ export const validatePackagePolicy = (
if (inputVars.length) {
inputValidationResults.vars = inputVars.reduce((results, [name, configEntry]) => {
results[name] = input.enabled
? inputVarDefsByPolicyTemplateAndType[inputKey] === undefined
? [
i18n.translate('xpack.fleet.packagePolicyValidation.missingInputKeyMessage', {
defaultMessage: '{inputKey} has no vars in policy template',
values: {
inputKey,
},
}),
]
: validatePackagePolicyConfig(
configEntry,
inputVarDefsByPolicyTemplateAndType[inputKey][name],
name,
safeLoadYaml
)
? validatePackagePolicyConfig(
configEntry,
(inputVarDefsByPolicyTemplateAndType[inputKey] ?? {})[name],
name,
safeLoadYaml
)
: null;
return results;
}, {} as ValidationEntry);
Expand Down Expand Up @@ -219,10 +210,15 @@ export const validatePackagePolicyConfig = (
}

if (varDef === undefined) {
// eslint-disable-next-line no-console
console.debug(`No variable definition for ${varName} found`);

return null;
errors.push(
i18n.translate('xpack.fleet.packagePolicyValidation.nonExistentVarMessage', {
defaultMessage: '{varName} var definition does not exist',
values: {
varName,
},
})
);
return errors;
}

if (varDef.required) {
Expand Down

0 comments on commit 2e9556e

Please sign in to comment.