Skip to content

Commit

Permalink
[SIEM] [Detections] Import rules (#56389)
Browse files Browse the repository at this point in the history
* refactor import rules to do it by batch

* fix error msg on api to match with json contract

* review I

* fix export
  • Loading branch information
XavierM authored Jan 31, 2020
1 parent 8d54fa8 commit c72e8e0
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 184 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export const ImportRuleModalComponent = ({
}
}, [selectedFiles, overwrite]);

const handleCloseModal = useCallback(() => {
setSelectedFiles(null);
closeModal();
}, [closeModal]);

return (
<>
{showModal && (
Expand Down Expand Up @@ -125,7 +130,7 @@ export const ImportRuleModalComponent = ({
</EuiModalBody>

<EuiModalFooter>
<EuiButtonEmpty onClick={closeModal}>{i18n.CANCEL_BUTTON}</EuiButtonEmpty>
<EuiButtonEmpty onClick={handleCloseModal}>{i18n.CANCEL_BUTTON}</EuiButtonEmpty>
<EuiButton
onClick={importRulesCallback}
disabled={selectedFiles == null || isImporting}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,32 @@ export const createExportRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
return headers.response().code(404);
}

const exportSizeLimit = server.config().get<number>('savedObjects.maxImportExportSize');
if (request.payload?.objects != null && request.payload.objects.length > exportSizeLimit) {
return Boom.badRequest(`Can't export more than ${exportSizeLimit} rules`);
} else {
const nonPackagedRulesCount = await getNonPackagedRulesCount({ alertsClient });
if (nonPackagedRulesCount > exportSizeLimit) {
try {
const exportSizeLimit = server.config().get<number>('savedObjects.maxImportExportSize');
if (request.payload?.objects != null && request.payload.objects.length > exportSizeLimit) {
return Boom.badRequest(`Can't export more than ${exportSizeLimit} rules`);
} else {
const nonPackagedRulesCount = await getNonPackagedRulesCount({ alertsClient });
if (nonPackagedRulesCount > exportSizeLimit) {
return Boom.badRequest(`Can't export more than ${exportSizeLimit} rules`);
}
}
}

const exported =
request.payload?.objects != null
? await getExportByObjectIds(alertsClient, request.payload.objects)
: await getExportAll(alertsClient);
const exported =
request.payload?.objects != null
? await getExportByObjectIds(alertsClient, request.payload.objects)
: await getExportAll(alertsClient);

const response = request.query.exclude_export_details
? headers.response(exported.rulesNdjson)
: headers.response(`${exported.rulesNdjson}${exported.exportDetails}`);
const response = request.query.exclude_export_details
? headers.response(exported.rulesNdjson)
: headers.response(`${exported.rulesNdjson}${exported.exportDetails}`);

return response
.header('Content-Disposition', `attachment; filename="${request.query.file_name}"`)
.header('Content-Type', 'application/ndjson');
return response
.header('Content-Disposition', `attachment; filename="${request.query.file_name}"`)
.header('Content-Type', 'application/ndjson');
} catch {
return Boom.badRequest(`Sorry, something went wrong to export rules`);
}
},
};
};
Expand Down
Loading

0 comments on commit c72e8e0

Please sign in to comment.