Skip to content

Commit

Permalink
Allow a few more fields to be undefined in internal schema
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmain committed Nov 12, 2020
1 parent 6ffcbaa commit 9143785
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const patchRules = async ({
};
const [validated, errors] = validate(newRule, internalRuleUpdate);
if (errors != null || validated === null) {
throw new PatchError('Applying patch would create invalid rule', 400);
throw new PatchError(`Applying patch would create invalid rule: ${errors}`, 400);
}

const update = await alertsClient.update({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ export const internalRuleToAPIResponse = (
meta: rule.params.meta,
rule_name_override: rule.params.ruleNameOverride,
timestamp_override: rule.params.timestampOverride,
author: rule.params.author,
author: rule.params.author ?? [],
false_positives: rule.params.falsePositives,
from: rule.params.from,
rule_id: rule.params.ruleId,
max_signals: rule.params.maxSignals,
risk_score_mapping: rule.params.riskScoreMapping,
severity_mapping: rule.params.severityMapping,
risk_score_mapping: rule.params.riskScoreMapping ?? [],
severity_mapping: rule.params.severityMapping ?? [],
threat: rule.params.threat,
to: rule.params.to,
references: rule.params.references,
version: rule.params.version,
exceptions_list: rule.params.exceptionsList,
exceptions_list: rule.params.exceptionsList ?? [],
...typeSpecificCamelToSnake(rule.params),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import * as t from 'io-ts';

import { listArray } from '../../../../common/detection_engine/schemas/types/lists';
import { listArrayOrUndefined } from '../../../../common/detection_engine/schemas/types/lists';
import {
threat_mapping,
threat_index,
Expand All @@ -15,7 +15,7 @@ import {
itemsPerSearchOrUndefined,
} from '../../../../common/detection_engine/schemas/types/threat_mapping';
import {
author,
authorOrUndefined,
buildingBlockTypeOrUndefined,
description,
enabled,
Expand All @@ -37,10 +37,10 @@ import {
machine_learning_job_id,
max_signals,
risk_score,
risk_score_mapping,
riskScoreMappingOrUndefined,
ruleNameOverrideOrUndefined,
severity,
severity_mapping,
severityMappingOrUndefined,
tags,
timestampOverrideOrUndefined,
threat,
Expand All @@ -64,7 +64,7 @@ import { SIGNALS_ID, SERVER_APP_ID } from '../../../../common/constants';
const nonEqlLanguages = t.keyof({ kuery: null, lucene: null });
export const baseRuleParams = t.exact(
t.type({
author,
author: authorOrUndefined,
buildingBlockType: buildingBlockTypeOrUndefined,
description,
note: noteOrUndefined,
Expand All @@ -80,16 +80,16 @@ export const baseRuleParams = t.exact(
// maxSignals not used in ML rules but probably should be used
maxSignals: max_signals,
riskScore: risk_score,
riskScoreMapping: risk_score_mapping,
riskScoreMapping: riskScoreMappingOrUndefined,
ruleNameOverride: ruleNameOverrideOrUndefined,
severity,
severityMapping: severity_mapping,
severityMapping: severityMappingOrUndefined,
timestampOverride: timestampOverrideOrUndefined,
threat,
to,
references,
version,
exceptionsList: listArray,
exceptionsList: listArrayOrUndefined,
})
);
export type BaseRuleParams = t.TypeOf<typeof baseRuleParams>;
Expand Down

0 comments on commit 9143785

Please sign in to comment.