44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- /* eslint-disable complexity */
8-
9- import uuid from 'uuid' ;
10- import { transformRuleToAlertAction } from '../../../../../common/detection_engine/transform_actions' ;
117import { validate } from '../../../../../common/validate' ;
128import { createRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/create_rules_type_dependents' ;
139import { createRulesBulkSchema } from '../../../../../common/detection_engine/schemas/request/create_rules_bulk_schema' ;
1410import { rulesBulkSchema } from '../../../../../common/detection_engine/schemas/response/rules_bulk_schema' ;
1511import { IRouter } from '../../../../../../../../src/core/server' ;
16- import {
17- DEFAULT_MAX_SIGNALS ,
18- DETECTION_ENGINE_RULES_URL ,
19- SERVER_APP_ID ,
20- SIGNALS_ID ,
21- } from '../../../../../common/constants' ;
12+ import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants' ;
2213import { SetupPlugins } from '../../../../plugin' ;
2314import { buildMlAuthz } from '../../../machine_learning/authz' ;
2415import { throwHttpError } from '../../../machine_learning/validation' ;
@@ -30,9 +21,7 @@ import { buildRouteValidation } from '../../../../utils/build_validation/route_v
3021
3122import { transformBulkError , createBulkErrorObject , buildSiemResponse } from '../utils' ;
3223import { updateRulesNotifications } from '../../rules/update_rules_notifications' ;
33- import { typeSpecificSnakeToCamel } from '../../schemas/rule_converters' ;
34- import { InternalRuleCreate } from '../../schemas/rule_schemas' ;
35- import { addTags } from '../../rules/add_tags' ;
24+ import { convertCreateAPIToInternalSchema } from '../../schemas/rule_converters' ;
3625
3726export const createRulesBulkRoute = ( router : IRouter , ml : SetupPlugins [ 'ml' ] ) => {
3827 router . post (
@@ -84,50 +73,7 @@ export const createRulesBulkRoute = (router: IRouter, ml: SetupPlugins['ml']) =>
8473 } ) ;
8574 }
8675 }
87- const typeSpecificParams = typeSpecificSnakeToCamel ( payloadRule ) ;
88- const newRuleId = payloadRule . rule_id ?? uuid . v4 ( ) ;
89- const throttle = payloadRule . throttle ?? null ;
90- const internalRule : InternalRuleCreate = {
91- name : payloadRule . name ,
92- tags : addTags ( payloadRule . tags ?? [ ] , newRuleId , false ) ,
93- alertTypeId : SIGNALS_ID ,
94- consumer : SERVER_APP_ID ,
95- params : {
96- author : payloadRule . author ?? [ ] ,
97- buildingBlockType : payloadRule . building_block_type ,
98- description : payloadRule . description ,
99- ruleId : newRuleId ,
100- falsePositives : payloadRule . false_positives ?? [ ] ,
101- from : payloadRule . from ?? 'now-6m' ,
102- immutable : false ,
103- license : payloadRule . license ,
104- outputIndex : payloadRule . output_index ?? siemClient . getSignalsIndex ( ) ,
105- timelineId : payloadRule . timeline_id ,
106- timelineTitle : payloadRule . timeline_title ,
107- meta : payloadRule . meta ,
108- maxSignals : payloadRule . max_signals ?? DEFAULT_MAX_SIGNALS ,
109- riskScore : payloadRule . risk_score ,
110- riskScoreMapping : payloadRule . risk_score_mapping ?? [ ] ,
111- ruleNameOverride : payloadRule . rule_name_override ,
112- severity : payloadRule . severity ,
113- severityMapping : payloadRule . severity_mapping ?? [ ] ,
114- threat : payloadRule . threat ?? [ ] ,
115- timestampOverride : payloadRule . timestamp_override ,
116- to : payloadRule . to ?? 'now' ,
117- references : payloadRule . references ?? [ ] ,
118- note : payloadRule . note ,
119- version : payloadRule . version ?? 1 ,
120- exceptionsList : payloadRule . exceptions_list ?? [ ] ,
121- ...typeSpecificParams ,
122- } ,
123- schedule : { interval : payloadRule . interval ?? '5m' } ,
124- enabled : payloadRule . enabled ?? true ,
125- actions :
126- throttle === 'rule'
127- ? ( payloadRule . actions ?? [ ] ) . map ( transformRuleToAlertAction )
128- : [ ] ,
129- throttle : null ,
130- } ;
76+ const internalRule = convertCreateAPIToInternalSchema ( payloadRule , siemClient ) ;
13177 try {
13278 const validationErrors = createRuleValidateTypeDependents ( payloadRule ) ;
13379 if ( validationErrors . length ) {
@@ -159,13 +105,17 @@ export const createRulesBulkRoute = (router: IRouter, ml: SetupPlugins['ml']) =>
159105 savedObjectsClient,
160106 enabled : createdRule . enabled ,
161107 actions : payloadRule . actions ,
162- throttle,
108+ throttle : payloadRule . throttle ?? null ,
163109 name : createdRule . name ,
164110 } ) ;
165111
166- return transformValidateBulkError ( newRuleId , createdRule , ruleActions ) ;
112+ return transformValidateBulkError (
113+ internalRule . params . ruleId ,
114+ createdRule ,
115+ ruleActions
116+ ) ;
167117 } catch ( err ) {
168- return transformBulkError ( newRuleId , err ) ;
118+ return transformBulkError ( internalRule . params . ruleId , err ) ;
169119 }
170120 } )
171121 ) ;
0 commit comments