From 9df835f1a8f6ea4ce7b868eac628b298e004eac2 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 16 Mar 2021 12:32:02 -0700 Subject: [PATCH] Remove `string` as a valid registry var type value (#94174) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- x-pack/plugins/fleet/common/types/models/epm.ts | 2 +- .../services/validate_package_policy.ts | 12 ++---------- .../server/services/epm/agent/agent.test.ts | 16 ++++++++-------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/fleet/common/types/models/epm.ts b/x-pack/plugins/fleet/common/types/models/epm.ts index d75de985c0bf1..03c42dd54f832 100644 --- a/x-pack/plugins/fleet/common/types/models/epm.ts +++ b/x-pack/plugins/fleet/common/types/models/epm.ts @@ -272,6 +272,7 @@ export interface RegistryElasticsearch { 'index_template.mappings'?: object; } +export type RegistryVarType = 'integer' | 'bool' | 'password' | 'text' | 'yaml' | 'string'; export enum RegistryVarsEntryKeys { name = 'name', title = 'title', @@ -284,7 +285,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 // but we effectively only see this shape diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/services/validate_package_policy.ts b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/services/validate_package_policy.ts index 54fb4ee31b4ee..39d8ccfae0d70 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/services/validate_package_policy.ts +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/services/validate_package_policy.ts @@ -228,11 +228,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) { @@ -246,11 +242,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', { diff --git a/x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts b/x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts index a76a8b9672d21..dde9f1733dfe3 100644 --- a/x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts @@ -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' }, };