Skip to content

Commit

Permalink
Remove string as a valid registry var type value (elastic#94174) (e…
Browse files Browse the repository at this point in the history
…lastic#94751)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Jen Huang <[email protected]>
  • Loading branch information
kibanamachine and jen-huang authored Mar 16, 2021
1 parent d52faa3 commit 9b1a579
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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<string, any>
// but we effectively only see this shape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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', {
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugins/fleet/server/services/epm/agent/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
};

Expand Down

0 comments on commit 9b1a579

Please sign in to comment.