Remove string as a valid registry var type value (#94174)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jen Huang 2021-03-16 12:32:02 -07:00 committed by GitHub
parent 21587dc79e
commit 2374af3011
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 19 deletions

View file

@ -274,6 +274,7 @@ export interface RegistryElasticsearch {
'index_template.mappings'?: object;
}
export type RegistryVarType = 'integer' | 'bool' | 'password' | 'text' | 'yaml' | 'string';
export enum RegistryVarsEntryKeys {
name = 'name',
title = 'title',
@ -286,7 +287,6 @@ export enum RegistryVarsEntryKeys {
os = 'os',
}
export type RegistryVarType = 'integer' | 'bool' | 'password' | 'text' | 'yaml' | 'string';
// EPR types this as `[]map[string]interface{}`
// which means the official/possible type is Record<string, any>
// but we effectively only see this shape

View file

@ -229,11 +229,7 @@ export const validatePackagePolicyConfig = (
})
);
}
if (
(varDef.type === 'text' || varDef.type === 'string') &&
parsedValue &&
Array.isArray(parsedValue)
) {
if (varDef.type === 'text' && parsedValue && Array.isArray(parsedValue)) {
const invalidStrings = parsedValue.filter((cand) => /^[*&]/.test(cand));
// only show one error if multiple strings in array are invalid
if (invalidStrings.length > 0) {
@ -247,11 +243,7 @@ export const validatePackagePolicyConfig = (
}
}
if (
(varDef.type === 'text' || varDef.type === 'string') &&
parsedValue &&
!Array.isArray(parsedValue)
) {
if (varDef.type === 'text' && parsedValue && !Array.isArray(parsedValue)) {
if (/^[*&]/.test(parsedValue)) {
errors.push(
i18n.translate('xpack.fleet.packagePolicyValidation.quoteStringErrorMessage', {

View file

@ -193,14 +193,14 @@ my-package:
{{{ search }}} | streamstats`;
const vars = {
asteriskOnly: { value: '"*"', type: 'string' },
startsWithAsterisk: { value: '"*lala"', type: 'string' },
numeric: { value: '100', type: 'string' },
mixed: { value: '1s', type: 'string' },
a: { value: '/opt/package/*', type: 'string' },
b: { value: '/logs/my.log*', type: 'string' },
c: { value: '/opt/*/package/', type: 'string' },
d: { value: 'logs/*my.log', type: 'string' },
asteriskOnly: { value: '"*"', type: 'text' },
startsWithAsterisk: { value: '"*lala"', type: 'text' },
numeric: { value: '100', type: 'text' },
mixed: { value: '1s', type: 'text' },
a: { value: '/opt/package/*', type: 'text' },
b: { value: '/logs/my.log*', type: 'text' },
c: { value: '/opt/*/package/', type: 'text' },
d: { value: 'logs/*my.log', type: 'text' },
search: { value: 'search sourcetype="access*"', type: 'text' },
};