-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[EDR Workflows][Artifact transfer 3] Import API validator #248046
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
Changes from all commits
907fe03
fc30eee
f4a010b
8af0e08
82f7ea9
dd1252f
840dfd0
fcb7ab0
59ce503
68d7177
9fd319b
6ee3b86
cd0f023
f027f3a
21e2170
a61eede
ad15fc6
bc3f733
3b48928
367cb86
96445bd
52f1312
13d8244
5961bdf
6f61ea3
dc2537a
d17f996
a23499a
a3690bd
c5b277f
e5f8c38
92fd180
5f8668b
b01b020
0fe5817
5c09cfe
00115cb
a8743d6
58fcfb3
6458bbc
dbddf35
851bb4a
8fc93cc
36e8ea2
6043d03
ba330c4
89fbdeb
8ee1a8c
f16665b
5a64b4f
ed219a4
e1ba1ff
9b101bf
bdaca74
067fc20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { BulkErrorErrorSchema } from '@kbn/securitysolution-io-ts-list-types'; | ||
|
|
||
| import { ListsErrorWithStatusCode } from '.'; | ||
|
|
||
| export class ExceptionItemImportError extends Error implements BulkErrorErrorSchema { | ||
| public readonly status_code: number; | ||
|
|
||
| constructor(error: Error, public readonly listId: string, public readonly itemId: string) { | ||
| super(error.message); | ||
| this.status_code = error instanceof ListsErrorWithStatusCode ? error.getStatusCode() : 400; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { NamespaceType } from '@kbn/securitysolution-io-ts-list-types'; | ||
| import { getSavedObjectType } from '@kbn/securitysolution-list-utils'; | ||
| import type { SavedObjectsBulkDeleteObject, SavedObjectsClientContract } from '@kbn/core/server'; | ||
|
|
||
| interface BulkDeleteExceptionListItemsOptions { | ||
| ids: string[]; | ||
| namespaceType: NamespaceType; | ||
| savedObjectsClient: SavedObjectsClientContract; | ||
| } | ||
|
|
||
| export const bulkDeleteExceptionListItems = async ({ | ||
| ids, | ||
| namespaceType, | ||
| savedObjectsClient, | ||
| }: BulkDeleteExceptionListItemsOptions): Promise<void> => { | ||
| const savedObjectType = getSavedObjectType({ namespaceType }); | ||
|
|
||
| const bulkDeleteObjects = ids.map<SavedObjectsBulkDeleteObject>((id) => ({ | ||
| id, | ||
| type: savedObjectType, | ||
| })); | ||
|
|
||
| await savedObjectsClient.bulkDelete(bulkDeleteObjects); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import type { | |
| } from '../extension_points'; | ||
|
|
||
| import type { | ||
| BulkDeleteExceptionListItemsOptions, | ||
| ClosePointInTimeOptions, | ||
| ConstructorOptions, | ||
| CreateEndpointListItemOptions, | ||
|
|
@@ -100,6 +101,7 @@ import { findValueListExceptionListItemsPointInTimeFinder } from './find_value_l | |
| import { findExceptionListItemPointInTimeFinder } from './find_exception_list_item_point_in_time_finder'; | ||
| import { duplicateExceptionListAndItems } from './duplicate_exception_list'; | ||
| import { updateOverwriteExceptionListItem } from './update_overwrite_exception_list_item'; | ||
| import { bulkDeleteExceptionListItems } from './bulk_delete_exception_list_items'; | ||
|
|
||
| /** | ||
| * Class for use for exceptions that are with trusted applications or | ||
|
|
@@ -831,6 +833,33 @@ export class ExceptionListClient { | |
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Bulk delete exception list items by an `id` array | ||
| * @param options | ||
| * @param options.ids the array of ids of exception list items to delete | ||
| * @param options.namespaceType saved object namespace (single | agnostic) | ||
| */ | ||
| public bulkDeleteExceptionListItems = async ({ | ||
| ids, | ||
| namespaceType, | ||
| }: BulkDeleteExceptionListItemsOptions): Promise<void> => { | ||
| const { savedObjectsClient } = this; | ||
|
|
||
| if (this.enableServerExtensionPoints) { | ||
| // todo: this is not ideal, items will be checked one-by-one. we'd need an `exceptionsListPreBulkDeleteItems` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this isn't worse than the code it's replacing: is there a blocker to adding a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that's good question. I don't know about any blocker - I think this was the point where I intentionally lost momentum, and instead of going down the rabbit hole focused on getting this functionality ready |
||
| // callback, but then that also needs a bulkGet function in exceptionListClient, which we don't have yet. | ||
| for (const id of ids) { | ||
| await this.serverExtensionsClient.pipeRun( | ||
| 'exceptionsListPreDeleteItem', | ||
| { id, itemId: undefined, namespaceType }, | ||
| this.getServerExtensionCallbackContext() | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return bulkDeleteExceptionListItems({ ids, namespaceType, savedObjectsClient }); | ||
| }; | ||
|
|
||
| /** | ||
| * This is the same as "deleteExceptionListItem" except it applies specifically to the endpoint list. | ||
| * Either id or itemId has to be defined to delete but not both is required. If both are provided, the id | ||
|
|
@@ -1168,18 +1197,21 @@ export class ExceptionListClient { | |
| ...readStream, | ||
| ]); | ||
|
|
||
| let shouldListApiPerformOverwrite = overwrite; | ||
| if (this.enableServerExtensionPoints) { | ||
| await this.serverExtensionsClient.pipeRun( | ||
| const result = await this.serverExtensionsClient.pipeRun( | ||
| 'exceptionsListPreImport', | ||
| parsedObjects, | ||
| { data: parsedObjects, overwrite }, | ||
| this.getServerExtensionCallbackContext() | ||
| ); | ||
|
|
||
| shouldListApiPerformOverwrite = result.overwrite; | ||
| } | ||
|
|
||
| return importExceptions({ | ||
| exceptions: parsedObjects, | ||
| generateNewListId, | ||
| overwrite, | ||
| overwrite: shouldListApiPerformOverwrite, | ||
| savedObjectsClient, | ||
| user, | ||
| }); | ||
|
|
@@ -1203,18 +1235,21 @@ export class ExceptionListClient { | |
| // validation of import and sorting of lists and items | ||
| const parsedObjects = exceptionsChecksFromArray(exceptionsToImport, maxExceptionsImportSize); | ||
|
|
||
| let shouldListApiPerformOverwrite = overwrite; | ||
| if (this.enableServerExtensionPoints) { | ||
| await this.serverExtensionsClient.pipeRun( | ||
| const result = await this.serverExtensionsClient.pipeRun( | ||
| 'exceptionsListPreImport', | ||
| parsedObjects, | ||
| { data: parsedObjects, overwrite }, | ||
| this.getServerExtensionCallbackContext() | ||
| ); | ||
|
|
||
| shouldListApiPerformOverwrite = result.overwrite; | ||
| } | ||
|
|
||
| return importExceptions({ | ||
| exceptions: parsedObjects, | ||
| generateNewListId: false, | ||
| overwrite, | ||
| overwrite: shouldListApiPerformOverwrite, | ||
| savedObjectsClient, | ||
| user, | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.