Skip to content

Commit

Permalink
Fix error for duplicate fields to correctly mention the field at fault
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed Oct 7, 2020
1 parent 0e89431 commit 0d4d820
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { schema } from '@kbn/config-schema';
import { TrustedApp } from '../types';

const hashLengths: readonly number[] = [
32, // MD5
Expand All @@ -13,6 +14,12 @@ const hashLengths: readonly number[] = [
];
const hasInvalidCharacters = /[^0-9a-f]/i;

const entryFieldLabels: { [k in TrustedApp['entries'][0]['field']]: string } = {
'process.hash.*': 'Hash',
'process.executable.caseless': 'Path',
'process.code_signature': 'Signer',
};

export const DeleteTrustedAppsRequestSchema = {
params: schema.object({
id: schema.string(),
Expand Down Expand Up @@ -47,7 +54,7 @@ export const PostTrustedAppCreateRequestSchema = {
const usedFields: string[] = [];
for (const { field, value } of entries) {
if (usedFields.includes(field)) {
return `[Hash] field can only be used once`;
return `[${entryFieldLabels[field]}] field can only be used once`;
}

usedFields.push(field);
Expand Down

0 comments on commit 0d4d820

Please sign in to comment.