[Security Solution] Value list exceptions (#133254)

This commit is contained in:
Davis Plumlee 2022-09-19 22:41:28 +02:00 committed by GitHub
parent 672bdd25b4
commit 51699fa21a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
113 changed files with 4716 additions and 2727 deletions

View file

@ -29,10 +29,14 @@ import {
ExportExceptionListProps,
UpdateExceptionListItemProps,
UpdateExceptionListProps,
GetExceptionFilterFromExceptionListIdsProps,
GetExceptionFilterFromExceptionsProps,
ExceptionFilterResponse,
} from '@kbn/securitysolution-io-ts-list-types';
import {
ENDPOINT_LIST_URL,
EXCEPTION_FILTER,
EXCEPTION_LIST_ITEM_URL,
EXCEPTION_LIST_URL,
} from '@kbn/securitysolution-list-constants';
@ -547,3 +551,59 @@ export const exportExceptionList = async ({
query: { id, list_id: listId, namespace_type: namespaceType },
signal,
});
/**
* Create a Filter query from an exception list id
*
* @param exceptionListId The id of the exception list from which create a Filter query
* @param signal AbortSignal for cancelling request
*
* @throws An error if response is not OK
*/
export const getExceptionFilterFromExceptionListIds = async ({
alias,
chunkSize,
exceptionListIds,
excludeExceptions,
http,
signal,
}: GetExceptionFilterFromExceptionListIdsProps): Promise<ExceptionFilterResponse> =>
http.fetch(EXCEPTION_FILTER, {
method: 'POST',
body: JSON.stringify({
exception_list_ids: exceptionListIds,
type: 'exception_list_ids',
alias,
exclude_exceptions: excludeExceptions,
chunk_size: chunkSize,
}),
signal,
});
/**
* Create a Filter query from a list of exceptions
*
* @param exceptions Exception items to be made into a `Filter` query
* @param signal AbortSignal for cancelling request
*
* @throws An error if response is not OK
*/
export const getExceptionFilterFromExceptions = async ({
exceptions,
alias,
excludeExceptions,
http,
chunkSize,
signal,
}: GetExceptionFilterFromExceptionsProps): Promise<ExceptionFilterResponse> =>
http.fetch(EXCEPTION_FILTER, {
method: 'POST',
body: JSON.stringify({
exceptions,
type: 'exception_items',
alias,
exclude_exceptions: excludeExceptions,
chunk_size: chunkSize,
}),
signal,
});

View file

@ -29,12 +29,15 @@ import {
importListItemSchema,
listItemIndexExistSchema,
listSchema,
foundListsBySizeSchema,
FoundListsBySizeSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import {
LIST_INDEX,
LIST_ITEM_URL,
LIST_PRIVILEGES_URL,
LIST_URL,
FIND_LISTS_BY_SIZE,
} from '@kbn/securitysolution-list-constants';
import { toError, toPromise } from '../fp_utils';
@ -104,6 +107,46 @@ const findListsWithValidation = async ({
export { findListsWithValidation as findLists };
const findListsBySize = async ({
http,
cursor,
page,
// eslint-disable-next-line @typescript-eslint/naming-convention
per_page,
signal,
}: ApiParams & FindListSchemaEncoded): Promise<FoundListsBySizeSchema> => {
return http.fetch(`${FIND_LISTS_BY_SIZE}`, {
method: 'GET',
query: {
cursor,
page,
per_page,
},
signal,
});
};
const findListsBySizeWithValidation = async ({
cursor,
http,
pageIndex,
pageSize,
signal,
}: FindListsParams): Promise<FoundListsBySizeSchema> =>
pipe(
{
cursor: cursor != null ? cursor.toString() : undefined,
page: pageIndex != null ? pageIndex.toString() : undefined,
per_page: pageSize != null ? pageSize.toString() : undefined,
},
(payload) => fromEither(validateEither(findListSchema, payload)),
chain((payload) => tryCatch(() => findListsBySize({ http, signal, ...payload }), toError)),
chain((response) => fromEither(validateEither(foundListsBySizeSchema, response))),
flow(toPromise)
);
export { findListsBySizeWithValidation as findListsBySize };
const importList = async ({
file,
http,