Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] [Detections] Import rules #56389

Merged
merged 7 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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]);
XavierM marked this conversation as resolved.
Show resolved Hide resolved

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