[Security Solution] Utilizes constants package and deletes duplicate code (#100513)

## Summary

Utilizes constants package and deletes duplicate code

* Renames the `securitysolution-constants` to be `securitysolution-list-constants` to be specific
* Deletes duplicated code found during cleanup
* Moves more tests into the packages found along the way with the duplicated code
* Moves `parseScheduleDates` from `@kbn/securitysolution-io-ts-types` to `@kbn/securitysolution-io-ts-utils`

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
This commit is contained in:
Frank Hassanabad 2021-05-24 18:38:14 -06:00 committed by GitHub
parent 676d40ebbe
commit aa2f5b535d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
168 changed files with 751 additions and 1356 deletions

View file

@ -82,13 +82,13 @@ yarn kbn watch-bazel
- @kbn/i18n
- @kbn/legacy-logging
- @kbn/logging
- @kbn/securitysolution-constants
- @kbn/securitysolution-es-utils
- kbn/securitysolution-io-ts-alerting-types
- kbn/securitysolution-io-ts-list-types
- kbn/securitysolution-io-ts-types
- @kbn/securitysolution-io-ts-utils
- @kbn/securitysolution-list-api
- @kbn/securitysolution-list-constants
- @kbn/securitysolution-list-hooks
- @kbn/securitysolution-list-utils
- @kbn/securitysolution-utils

View file

@ -136,7 +136,7 @@
"@kbn/legacy-logging": "link:bazel-bin/packages/kbn-legacy-logging/npm_module",
"@kbn/logging": "link:bazel-bin/packages/kbn-logging/npm_module",
"@kbn/monaco": "link:packages/kbn-monaco",
"@kbn/securitysolution-constants": "link:bazel-bin/packages/kbn-securitysolution-constants/npm_module",
"@kbn/securitysolution-list-constants": "link:bazel-bin/packages/kbn-securitysolution-list-constants/npm_module",
"@kbn/securitysolution-es-utils": "link:bazel-bin/packages/kbn-securitysolution-es-utils/npm_module",
"@kbn/securitysolution-io-ts-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-types/npm_module",
"@kbn/securitysolution-io-ts-alerting-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-alerting-types/npm_module",

View file

@ -25,7 +25,7 @@ filegroup(
"//packages/kbn-legacy-logging:build",
"//packages/kbn-logging:build",
"//packages/kbn-plugin-generator:build",
"//packages/kbn-securitysolution-constants:build",
"//packages/kbn-securitysolution-list-constants:build",
"//packages/kbn-securitysolution-io-ts-types:build",
"//packages/kbn-securitysolution-io-ts-alerting-types:build",
"//packages/kbn-securitysolution-io-ts-list-types:build",

View file

@ -1,6 +0,0 @@
# kbn-securitysolution-constants
This is where shared constants for security solution should go that are going to be shared among plugins.
This was originally created to remove the dependencies between security_solution and other projects such as lists.

View file

@ -1,9 +0,0 @@
{
"name": "@kbn/securitysolution-constants",
"version": "1.0.0",
"description": "security solution constants to use across plugins such lists, security_solution, cases, etc...",
"license": "SSPL-1.0 OR Elastic License 2.0",
"main": "./target/index.js",
"types": "./target/index.d.ts",
"private": true
}

View file

@ -7,15 +7,7 @@
*/
/**
* This ID is used for _both_ the Saved Object ID and for the list_id
* for the single global space agnostic endpoint list
* TODO: Create a kbn-securitysolution-constants and add this to it.
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_LIST_ID = 'endpoint_list';
/**
* TODO: Create a kbn-securitysolution-constants and add this to it.
* @deprecated Use the DEFAULT_MAX_SIGNALS from the kbn-securitysolution-constants.
* TODO: Create a kbn-alerting-constants and add this to it.
* @deprecated Use a DEFAULT_MAX_SIGNALS from a kbn-alerting-constants package.
*/
export const DEFAULT_MAX_SIGNALS = 100;

View file

@ -8,7 +8,7 @@
import { Either } from 'fp-ts/lib/Either';
import * as t from 'io-ts';
import { parseScheduleDates } from '@kbn/securitysolution-io-ts-types';
import { parseScheduleDates } from '@kbn/securitysolution-io-ts-utils';
const stringValidator = (input: unknown): input is string => typeof input === 'string';

View file

@ -7,7 +7,6 @@
*/
export * from './actions';
export * from './constants';
export * from './default_actions_array';
export * from './default_export_file_name';
export * from './default_from_string';

View file

@ -7,7 +7,7 @@
*/
import { List, ListArray } from '.';
import { ENDPOINT_LIST_ID } from '../../constants';
import { ENDPOINT_LIST_ID } from '@kbn/securitysolution-list-constants';
export const getListMock = (): List => ({
id: 'some_uuid',

View file

@ -1,34 +0,0 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/**
* This ID is used for _both_ the Saved Object ID and for the list_id
* for the single global space agnostic endpoint list.
*
* TODO: Create a kbn-securitysolution-constants and add this to it.
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_LIST_ID = 'endpoint_list';
/**
* Description of trusted apps agnostic list
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION = 'Endpoint Security Trusted Apps List';
/**
* ID of trusted apps agnostic list
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_TRUSTED_APPS_LIST_ID = 'endpoint_trusted_apps';
/**
* Name of trusted apps agnostic list
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_TRUSTED_APPS_LIST_NAME = 'Endpoint Security Trusted Apps List';

View file

@ -7,7 +7,6 @@
*/
export * from './common';
export * from './constants';
export * from './request';
export * from './response';
export * from './typescript_types';

View file

@ -25,7 +25,7 @@ import {
ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
ENDPOINT_TRUSTED_APPS_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_NAME,
} from '../..';
} from '@kbn/securitysolution-list-constants';
import { ExceptionListSchema } from '.';

View file

@ -22,7 +22,6 @@ export * from './non_empty_string';
export * from './non_empty_string_array';
export * from './operator';
export * from './only_false_allowed';
export * from './parse_schedule_dates';
export * from './positive_integer';
export * from './positive_integer_greater_than_zero';
export * from './string_to_positive_number';

View file

@ -7,6 +7,7 @@
*/
export * from './format_errors';
export * from './parse_schedule_dates';
export * from './exact_check';
export * from './format_errors';
export * from './test_utils';

View file

@ -0,0 +1,38 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import moment from 'moment';
import { parseScheduleDates } from '.';
describe('parseScheduleDates', () => {
test('it returns a moment when given an ISO string', () => {
const result = parseScheduleDates('2020-01-01T00:00:00.000Z');
expect(result).not.toBeNull();
expect(result).toEqual(moment('2020-01-01T00:00:00.000Z'));
});
test('it returns a moment when given `now`', () => {
const result = parseScheduleDates('now');
expect(result).not.toBeNull();
expect(moment.isMoment(result)).toBeTruthy();
});
test('it returns a moment when given `now-x`', () => {
const result = parseScheduleDates('now-6m');
expect(result).not.toBeNull();
expect(moment.isMoment(result)).toBeTruthy();
});
test('it returns null when given a string that is not an ISO string, `now` or `now-x`', () => {
const result = parseScheduleDates('invalid');
expect(result).toBeNull();
});
});

View file

@ -29,6 +29,7 @@ NPM_MODULE_EXTRA_FILES = [
SRC_DEPS = [
"//packages/kbn-securitysolution-io-ts-utils",
"//packages/kbn-securitysolution-list-constants",
"//packages/kbn-securitysolution-io-ts-list-types",
"@npm//fp-ts",
"@npm//io-ts",

View file

@ -31,14 +31,14 @@ import {
UpdateExceptionListProps,
} from '@kbn/securitysolution-io-ts-list-types';
import { toError, toPromise } from '../fp_utils';
import {
ENDPOINT_LIST_URL,
EXCEPTION_LIST_ITEM_URL,
EXCEPTION_LIST_NAMESPACE,
EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
EXCEPTION_LIST_URL,
} from '../constants';
} from '@kbn/securitysolution-list-constants';
import { toError, toPromise } from '../fp_utils';
/**
* Add new ExceptionList

View file

@ -1,39 +0,0 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
// TODO: These should be all replaced with constants from a shared kbn constants package
export const LIST_URL = '/api/lists';
export const LIST_INDEX = `${LIST_URL}/index`;
export const LIST_ITEM_URL = `${LIST_URL}/items`;
export const LIST_PRIVILEGES_URL = `${LIST_URL}/privileges`;
/**
* Exception list routes
*/
export const EXCEPTION_LIST_URL = '/api/exception_lists';
export const EXCEPTION_LIST_ITEM_URL = '/api/exception_lists/items';
/**
* Exception list spaces
*/
export const EXCEPTION_LIST_NAMESPACE_AGNOSTIC = 'exception-list-agnostic';
export const EXCEPTION_LIST_NAMESPACE = 'exception-list';
/**
* Specific routes for the single global space agnostic endpoint list
*/
export const ENDPOINT_LIST_URL = '/api/endpoint_list';
/**
* Specific routes for the single global space agnostic endpoint list. These are convenience
* routes where they are going to try and create the global space agnostic endpoint list if it
* does not exist yet or if it was deleted at some point and re-create it before adding items to
* the list
*/
export const ENDPOINT_LIST_ITEM_URL = '/api/endpoint_list/items';

View file

@ -30,10 +30,14 @@ import {
listItemIndexExistSchema,
listSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import {
LIST_INDEX,
LIST_ITEM_URL,
LIST_PRIVILEGES_URL,
LIST_URL,
} from '@kbn/securitysolution-list-constants';
import { toError, toPromise } from '../fp_utils';
import { LIST_INDEX, LIST_ITEM_URL, LIST_PRIVILEGES_URL, LIST_URL } from '../constants';
import {
ApiParams,
DeleteListParams,

View file

@ -1,9 +1,9 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")
PKG_BASE_NAME = "kbn-securitysolution-constants"
PKG_BASE_NAME = "kbn-securitysolution-list-constants"
PKG_REQUIRE_NAME = "@kbn/securitysolution-constants"
PKG_REQUIRE_NAME = "@kbn/securitysolution-list-constants"
SOURCE_FILES = glob(
[

View file

@ -0,0 +1,6 @@
# kbn-securitysolution-list-constants
This is where shared constants for security solution lists should go that are going to be shared among plugins.
This was originally created to remove the dependencies between security_solution and other projects.

View file

@ -9,5 +9,5 @@
module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-securitysolution-constants'],
roots: ['<rootDir>/packages/kbn-securitysolution-list-constants'],
};

View file

@ -0,0 +1,9 @@
{
"name": "@kbn/securitysolution-list-constants",
"version": "1.0.0",
"description": "security solution list constants to use across plugins such lists, security_solution, cases, etc...",
"license": "SSPL-1.0 OR Elastic License 2.0",
"main": "./target/index.js",
"types": "./target/index.d.ts",
"private": true
}

View file

@ -70,6 +70,3 @@ export const ENDPOINT_EVENT_FILTERS_LIST_NAME = 'Endpoint Security Event Filters
/** Description of event filters agnostic list */
export const ENDPOINT_EVENT_FILTERS_LIST_DESCRIPTION = 'Endpoint Security Event Filters List';
/** The default max signals without any additional configuration */
export const DEFAULT_MAX_SIGNALS = 100;

View file

@ -7,7 +7,7 @@
"outDir": "target",
"rootDir": "src",
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-securitysolution-constants/src",
"sourceRoot": "../../../../packages/kbn-securitysolution-list-constants/src",
"types": [
"jest",
"node"

View file

@ -30,6 +30,8 @@ NPM_MODULE_EXTRA_FILES = [
SRC_DEPS = [
"//packages/kbn-securitysolution-io-ts-list-types",
"//packages/kbn-securitysolution-list-api",
"//packages/kbn-securitysolution-list-constants",
"//packages/kbn-securitysolution-list-utils",
"//packages/kbn-securitysolution-utils",
"@npm//lodash",
"@npm//tslib",

View file

@ -1,34 +0,0 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/**
* This ID is used for _both_ the Saved Object ID and for the list_id
* for the single global space agnostic endpoint list.
*
* TODO: Create a kbn-securitysolution-constants and add this to it.
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_LIST_ID = 'endpoint_list';
/**
* Description of trusted apps agnostic list
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION = 'Endpoint Security Trusted Apps List';
/**
* ID of trusted apps agnostic list
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_TRUSTED_APPS_LIST_ID = 'endpoint_trusted_apps';
/**
* Name of trusted apps agnostic list
* @deprecated Use the ENDPOINT_LIST_ID from the kbn-securitysolution-constants.
*/
export const ENDPOINT_TRUSTED_APPS_LIST_NAME = 'Endpoint Security Trusted Apps List';

View file

@ -21,5 +21,4 @@ export * from './use_persist_exception_item';
export * from './use_persist_exception_list';
export * from './use_read_list_index';
export * from './use_read_list_privileges';
export * from './utils';
export * from './with_optional_signal';

View file

@ -25,7 +25,7 @@ interface HttpStart {
fetch: <T>(...args: any) => any;
}
import { getIdsAndNamespaces } from '../utils';
import { getIdsAndNamespaces } from '@kbn/securitysolution-list-utils';
import { transformInput, transformNewItemOutput, transformOutput } from '../transforms';
export interface ExceptionsApi {

View file

@ -15,7 +15,7 @@ import type {
} from '@kbn/securitysolution-io-ts-list-types';
import { fetchExceptionListsItemsByListIds } from '@kbn/securitysolution-list-api';
import { getIdsAndNamespaces } from '../utils';
import { getIdsAndNamespaces } from '@kbn/securitysolution-list-utils';
import { transformInput } from '../transforms';
type Func = () => void;

View file

@ -14,7 +14,7 @@ import type {
} from '@kbn/securitysolution-io-ts-list-types';
import { fetchExceptionLists } from '@kbn/securitysolution-list-api';
import { getFilters } from '../utils';
import { getFilters } from '@kbn/securitysolution-list-utils';
export type Func = () => void;
export type ReturnExceptionLists = [boolean, ExceptionListSchema[], Pagination, Func | null];

View file

@ -1,272 +0,0 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { getFilters, getGeneralFilters, getIdsAndNamespaces, getTrustedAppsFilter } from '.';
describe('Exceptions utils', () => {
describe('#getIdsAndNamespaces', () => {
test('it returns empty arrays if no lists found', async () => {
const output = getIdsAndNamespaces({
lists: [],
showDetection: false,
showEndpoint: false,
});
expect(output).toEqual({ ids: [], namespaces: [] });
});
test('it returns all lists if "showDetection" and "showEndpoint" are "false"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: false,
showEndpoint: false,
});
expect(output).toEqual({
ids: ['list_id', 'list_id_endpoint'],
namespaces: ['single', 'agnostic'],
});
});
test('it returns only detections lists if "showDetection" is "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: true,
showEndpoint: false,
});
expect(output).toEqual({
ids: ['list_id'],
namespaces: ['single'],
});
});
test('it returns only endpoint lists if "showEndpoint" is "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: false,
showEndpoint: true,
});
expect(output).toEqual({
ids: ['list_id_endpoint'],
namespaces: ['agnostic'],
});
});
test('it returns only detection lists if both "showEndpoint" and "showDetection" are "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: true,
showEndpoint: true,
});
expect(output).toEqual({
ids: ['list_id'],
namespaces: ['single'],
});
});
});
describe('getGeneralFilters', () => {
test('it returns empty string if no filters', () => {
const filters = getGeneralFilters({}, ['exception-list']);
expect(filters).toEqual('');
});
test('it properly formats filters when one namespace type passed in', () => {
const filters = getGeneralFilters({ created_by: 'moi', name: 'Sample' }, ['exception-list']);
expect(filters).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample)'
);
});
test('it properly formats filters when two namespace types passed in', () => {
const filters = getGeneralFilters({ created_by: 'moi', name: 'Sample' }, [
'exception-list',
'exception-list-agnostic',
]);
expect(filters).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample)'
);
});
});
describe('getTrustedAppsFilter', () => {
test('it returns filter to search for "exception-list" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(true, ['exception-list']);
expect(filter).toEqual('(exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it returns filter to search for "exception-list" and "agnostic" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(true, ['exception-list', 'exception-list-agnostic']);
expect(filter).toEqual(
'(exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it returns filter to exclude "exception-list" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(false, ['exception-list']);
expect(filter).toEqual('(not exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it returns filter to exclude "exception-list" and "agnostic" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(false, ['exception-list', 'exception-list-agnostic']);
expect(filter).toEqual(
'(not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
describe('getFilters', () => {
describe('single', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['single'], false);
expect(filter).toEqual('(not exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['single'], true);
expect(filter).toEqual('(exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['single'], false);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample) AND (not exception-list.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it if filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['single'], true);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample) AND (exception-list.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
describe('agnostic', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['agnostic'], false);
expect(filter).toEqual(
'(not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['agnostic'], true);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['agnostic'], false);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.created_by:moi) AND (exception-list-agnostic.attributes.name.text:Sample) AND (not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it if filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['agnostic'], true);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.created_by:moi) AND (exception-list-agnostic.attributes.name.text:Sample) AND (exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
describe('single, agnostic', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['single', 'agnostic'], false);
expect(filter).toEqual(
'(not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['single', 'agnostic'], true);
expect(filter).toEqual(
'(exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters(
{ created_by: 'moi', name: 'Sample' },
['single', 'agnostic'],
false
);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample) AND (not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is true', () => {
const filter = getFilters(
{ created_by: 'moi', name: 'Sample' },
['single', 'agnostic'],
true
);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample) AND (exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
});
});

View file

@ -1,118 +0,0 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type {
NamespaceType,
NamespaceTypeArray,
ExceptionListFilter,
ExceptionListIdentifiers,
} from '@kbn/securitysolution-io-ts-list-types';
import { get } from 'lodash/fp';
import { ENDPOINT_TRUSTED_APPS_LIST_ID } from '../constants';
export const exceptionListSavedObjectType = 'exception-list';
export const exceptionListAgnosticSavedObjectType = 'exception-list-agnostic';
export type SavedObjectType = 'exception-list' | 'exception-list-agnostic';
export const getSavedObjectType = ({
namespaceType,
}: {
namespaceType: NamespaceType;
}): SavedObjectType => {
if (namespaceType === 'agnostic') {
return exceptionListAgnosticSavedObjectType;
} else {
return exceptionListSavedObjectType;
}
};
export const getSavedObjectTypes = ({
namespaceType,
}: {
namespaceType: NamespaceTypeArray;
}): SavedObjectType[] => {
return namespaceType.map((singleNamespaceType) =>
getSavedObjectType({ namespaceType: singleNamespaceType })
);
};
export const getIdsAndNamespaces = ({
lists,
showDetection,
showEndpoint,
}: {
lists: ExceptionListIdentifiers[];
showDetection: boolean;
showEndpoint: boolean;
}): { ids: string[]; namespaces: NamespaceType[] } =>
lists
.filter((list) => {
if (showDetection) {
return list.type === 'detection';
} else if (showEndpoint) {
return list.type === 'endpoint';
} else {
return true;
}
})
.reduce<{ ids: string[]; namespaces: NamespaceType[] }>(
(acc, { listId, namespaceType }) => ({
ids: [...acc.ids, listId],
namespaces: [...acc.namespaces, namespaceType],
}),
{ ids: [], namespaces: [] }
);
export const getGeneralFilters = (
filters: ExceptionListFilter,
namespaceTypes: SavedObjectType[]
): string => {
return Object.keys(filters)
.map((filterKey) => {
const value = get(filterKey, filters);
if (value != null && value.trim() !== '') {
const filtersByNamespace = namespaceTypes
.map((namespace) => {
const fieldToSearch = filterKey === 'name' ? 'name.text' : filterKey;
return `${namespace}.attributes.${fieldToSearch}:${value}`;
})
.join(' OR ');
return `(${filtersByNamespace})`;
} else return null;
})
.filter((item) => item != null)
.join(' AND ');
};
export const getTrustedAppsFilter = (
showTrustedApps: boolean,
namespaceTypes: SavedObjectType[]
): string => {
if (showTrustedApps) {
const filters = namespaceTypes.map((namespace) => {
return `${namespace}.attributes.list_id: ${ENDPOINT_TRUSTED_APPS_LIST_ID}*`;
});
return `(${filters.join(' OR ')})`;
} else {
const filters = namespaceTypes.map((namespace) => {
return `not ${namespace}.attributes.list_id: ${ENDPOINT_TRUSTED_APPS_LIST_ID}*`;
});
return `(${filters.join(' AND ')})`;
}
};
export const getFilters = (
filters: ExceptionListFilter,
namespaceTypes: NamespaceType[],
showTrustedApps: boolean
): string => {
const namespaces = getSavedObjectTypes({ namespaceType: namespaceTypes });
const generalFilters = getGeneralFilters(filters, namespaces);
const trustedAppsFilter = getTrustedAppsFilter(showTrustedApps, namespaces);
return [generalFilters, trustedAppsFilter].filter((filter) => filter.trim() !== '').join(' AND ');
};

View file

@ -29,6 +29,7 @@ NPM_MODULE_EXTRA_FILES = [
SRC_DEPS = [
"//packages/kbn-i18n",
"//packages/kbn-securitysolution-list-constants",
"//packages/kbn-securitysolution-io-ts-list-types",
"//packages/kbn-securitysolution-utils",
"@npm//lodash",

View file

@ -0,0 +1,23 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { NamespaceType } from '@kbn/securitysolution-io-ts-list-types';
import { exceptionListAgnosticSavedObjectType } from '../types';
export const getExceptionListType = ({
savedObjectType,
}: {
savedObjectType: string;
}): NamespaceType => {
if (savedObjectType === exceptionListAgnosticSavedObjectType) {
return 'agnostic';
} else {
return 'single';
}
};

View file

@ -0,0 +1,117 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { getFilters } from '.';
describe('getFilters', () => {
describe('single', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['single'], false);
expect(filter).toEqual('(not exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['single'], true);
expect(filter).toEqual('(exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['single'], false);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample) AND (not exception-list.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it if filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['single'], true);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample) AND (exception-list.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
describe('agnostic', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['agnostic'], false);
expect(filter).toEqual(
'(not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['agnostic'], true);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['agnostic'], false);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.created_by:moi) AND (exception-list-agnostic.attributes.name.text:Sample) AND (not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it if filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['agnostic'], true);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.created_by:moi) AND (exception-list-agnostic.attributes.name.text:Sample) AND (exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
describe('single, agnostic', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['single', 'agnostic'], false);
expect(filter).toEqual(
'(not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['single', 'agnostic'], true);
expect(filter).toEqual(
'(exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters(
{ created_by: 'moi', name: 'Sample' },
['single', 'agnostic'],
false
);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample) AND (not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is true', () => {
const filter = getFilters(
{ created_by: 'moi', name: 'Sample' },
['single', 'agnostic'],
true
);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample) AND (exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
});

View file

@ -0,0 +1,23 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { ExceptionListFilter, NamespaceType } from '@kbn/securitysolution-io-ts-list-types';
import { getGeneralFilters } from '../get_general_filters';
import { getSavedObjectTypes } from '../get_saved_object_types';
import { getTrustedAppsFilter } from '../get_trusted_apps_filter';
export const getFilters = (
filters: ExceptionListFilter,
namespaceTypes: NamespaceType[],
showTrustedApps: boolean
): string => {
const namespaces = getSavedObjectTypes({ namespaceType: namespaceTypes });
const generalFilters = getGeneralFilters(filters, namespaces);
const trustedAppsFilter = getTrustedAppsFilter(showTrustedApps, namespaces);
return [generalFilters, trustedAppsFilter].filter((filter) => filter.trim() !== '').join(' AND ');
};

View file

@ -0,0 +1,36 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { getGeneralFilters } from '.';
describe('getGeneralFilters', () => {
test('it returns empty string if no filters', () => {
const filters = getGeneralFilters({}, ['exception-list']);
expect(filters).toEqual('');
});
test('it properly formats filters when one namespace type passed in', () => {
const filters = getGeneralFilters({ created_by: 'moi', name: 'Sample' }, ['exception-list']);
expect(filters).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample)'
);
});
test('it properly formats filters when two namespace types passed in', () => {
const filters = getGeneralFilters({ created_by: 'moi', name: 'Sample' }, [
'exception-list',
'exception-list-agnostic',
]);
expect(filters).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample)'
);
});
});

View file

@ -0,0 +1,32 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { ExceptionListFilter } from '@kbn/securitysolution-io-ts-list-types';
import { get } from 'lodash/fp';
import { SavedObjectType } from '../types';
export const getGeneralFilters = (
filters: ExceptionListFilter,
namespaceTypes: SavedObjectType[]
): string => {
return Object.keys(filters)
.map((filterKey) => {
const value = get(filterKey, filters);
if (value != null && value.trim() !== '') {
const filtersByNamespace = namespaceTypes
.map((namespace) => {
const fieldToSearch = filterKey === 'name' ? 'name.text' : filterKey;
return `${namespace}.attributes.${fieldToSearch}:${value}`;
})
.join(' OR ');
return `(${filtersByNamespace})`;
} else return null;
})
.filter((item) => item != null)
.join(' AND ');
};

View file

@ -0,0 +1,105 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { getIdsAndNamespaces } from '.';
describe('getIdsAndNamespaces', () => {
test('it returns empty arrays if no lists found', async () => {
const output = getIdsAndNamespaces({
lists: [],
showDetection: false,
showEndpoint: false,
});
expect(output).toEqual({ ids: [], namespaces: [] });
});
test('it returns all lists if "showDetection" and "showEndpoint" are "false"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: false,
showEndpoint: false,
});
expect(output).toEqual({
ids: ['list_id', 'list_id_endpoint'],
namespaces: ['single', 'agnostic'],
});
});
test('it returns only detections lists if "showDetection" is "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: true,
showEndpoint: false,
});
expect(output).toEqual({
ids: ['list_id'],
namespaces: ['single'],
});
});
test('it returns only endpoint lists if "showEndpoint" is "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: false,
showEndpoint: true,
});
expect(output).toEqual({
ids: ['list_id_endpoint'],
namespaces: ['agnostic'],
});
});
test('it returns only detection lists if both "showEndpoint" and "showDetection" are "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: true,
showEndpoint: true,
});
expect(output).toEqual({
ids: ['list_id'],
namespaces: ['single'],
});
});
});

View file

@ -0,0 +1,36 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { ExceptionListIdentifiers, NamespaceType } from '@kbn/securitysolution-io-ts-list-types';
export const getIdsAndNamespaces = ({
lists,
showDetection,
showEndpoint,
}: {
lists: ExceptionListIdentifiers[];
showDetection: boolean;
showEndpoint: boolean;
}): { ids: string[]; namespaces: NamespaceType[] } =>
lists
.filter((list) => {
if (showDetection) {
return list.type === 'detection';
} else if (showEndpoint) {
return list.type === 'endpoint';
} else {
return true;
}
})
.reduce<{ ids: string[]; namespaces: NamespaceType[] }>(
(acc, { listId, namespaceType }) => ({
ids: [...acc.ids, listId],
namespaces: [...acc.namespaces, namespaceType],
}),
{ ids: [], namespaces: [] }
);

View file

@ -0,0 +1,27 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { NamespaceType } from '@kbn/securitysolution-io-ts-list-types';
import {
exceptionListAgnosticSavedObjectType,
exceptionListSavedObjectType,
SavedObjectType,
} from '../types';
export const getSavedObjectType = ({
namespaceType,
}: {
namespaceType: NamespaceType;
}): SavedObjectType => {
if (namespaceType === 'agnostic') {
return exceptionListAgnosticSavedObjectType;
} else {
return exceptionListSavedObjectType;
}
};

View file

@ -0,0 +1,22 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { NamespaceTypeArray } from '@kbn/securitysolution-io-ts-list-types';
import { SavedObjectType } from '../types';
import { getSavedObjectType } from '../get_saved_object_type';
export const getSavedObjectTypes = ({
namespaceType,
}: {
namespaceType: NamespaceTypeArray;
}): SavedObjectType[] => {
return namespaceType.map((singleNamespaceType) =>
getSavedObjectType({ namespaceType: singleNamespaceType })
);
};

View file

@ -0,0 +1,39 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { getTrustedAppsFilter } from '.';
describe('getTrustedAppsFilter', () => {
test('it returns filter to search for "exception-list" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(true, ['exception-list']);
expect(filter).toEqual('(exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it returns filter to search for "exception-list" and "agnostic" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(true, ['exception-list', 'exception-list-agnostic']);
expect(filter).toEqual(
'(exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it returns filter to exclude "exception-list" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(false, ['exception-list']);
expect(filter).toEqual('(not exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it returns filter to exclude "exception-list" and "agnostic" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(false, ['exception-list', 'exception-list-agnostic']);
expect(filter).toEqual(
'(not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});

View file

@ -0,0 +1,27 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { ENDPOINT_TRUSTED_APPS_LIST_ID } from '@kbn/securitysolution-list-constants';
import { SavedObjectType } from '../types';
export const getTrustedAppsFilter = (
showTrustedApps: boolean,
namespaceTypes: SavedObjectType[]
): string => {
if (showTrustedApps) {
const filters = namespaceTypes.map((namespace) => {
return `${namespace}.attributes.list_id: ${ENDPOINT_TRUSTED_APPS_LIST_ID}*`;
});
return `(${filters.join(' OR ')})`;
} else {
const filters = namespaceTypes.map((namespace) => {
return `not ${namespace}.attributes.list_id: ${ENDPOINT_TRUSTED_APPS_LIST_ID}*`;
});
return `(${filters.join(' AND ')})`;
}
};

View file

@ -7,6 +7,13 @@
*/
export * from './autocomplete_operators';
export * from './build_exception_filter';
export * from './get_exception_list_type';
export * from './get_filters';
export * from './get_general_filters';
export * from './get_ids_and_namespaces';
export * from './get_saved_object_type';
export * from './get_saved_object_types';
export * from './get_trusted_apps_filter';
export * from './has_large_value_list';
export * from './helpers';
export * from './types';

View file

@ -18,6 +18,10 @@ import type {
ListOperatorEnum as OperatorEnum,
ListOperatorTypeEnum as OperatorTypeEnum,
} from '@kbn/securitysolution-io-ts-list-types';
import {
EXCEPTION_LIST_NAMESPACE,
EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
} from '@kbn/securitysolution-list-constants';
import type { OperatorOption } from '../autocomplete_operators/types';
@ -98,3 +102,9 @@ export type CreateExceptionListItemBuilderSchema = Omit<
export type ExceptionsBuilderExceptionItem =
| ExceptionListItemBuilderSchema
| CreateExceptionListItemBuilderSchema;
export const exceptionListSavedObjectType = EXCEPTION_LIST_NAMESPACE;
export const exceptionListAgnosticSavedObjectType = EXCEPTION_LIST_NAMESPACE_AGNOSTIC;
export type SavedObjectType =
| typeof EXCEPTION_LIST_NAMESPACE
| typeof EXCEPTION_LIST_NAMESPACE_AGNOSTIC;

View file

@ -1,71 +0,0 @@
/*
* 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.
*/
/**
* Value list routes
*/
export const LIST_URL = '/api/lists';
export const LIST_INDEX = `${LIST_URL}/index`;
export const LIST_ITEM_URL = `${LIST_URL}/items`;
export const LIST_PRIVILEGES_URL = `${LIST_URL}/privileges`;
/**
* Exception list routes
*/
export const EXCEPTION_LIST_URL = '/api/exception_lists';
export const EXCEPTION_LIST_ITEM_URL = '/api/exception_lists/items';
/**
* Exception list spaces
*/
export const EXCEPTION_LIST_NAMESPACE_AGNOSTIC = 'exception-list-agnostic';
export const EXCEPTION_LIST_NAMESPACE = 'exception-list';
/**
* Specific routes for the single global space agnostic endpoint list
*/
export const ENDPOINT_LIST_URL = '/api/endpoint_list';
/**
* Specific routes for the single global space agnostic endpoint list. These are convenience
* routes where they are going to try and create the global space agnostic endpoint list if it
* does not exist yet or if it was deleted at some point and re-create it before adding items to
* the list
*/
export const ENDPOINT_LIST_ITEM_URL = '/api/endpoint_list/items';
/**
* This ID is used for _both_ the Saved Object ID and for the list_id
* for the single global space agnostic endpoint list
*/
export const ENDPOINT_LIST_ID = 'endpoint_list';
/** The name of the single global space agnostic endpoint list */
export const ENDPOINT_LIST_NAME = 'Endpoint Security Exception List';
/** The description of the single global space agnostic endpoint list */
export const ENDPOINT_LIST_DESCRIPTION = 'Endpoint Security Exception List';
export const MAX_EXCEPTION_LIST_SIZE = 10000;
/** ID of trusted apps agnostic list */
export const ENDPOINT_TRUSTED_APPS_LIST_ID = 'endpoint_trusted_apps';
/** Name of trusted apps agnostic list */
export const ENDPOINT_TRUSTED_APPS_LIST_NAME = 'Endpoint Security Trusted Apps List';
/** Description of trusted apps agnostic list */
export const ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION = 'Endpoint Security Trusted Apps List';
/** ID of event filters agnostic list */
export const ENDPOINT_EVENT_FILTERS_LIST_ID = 'endpoint_event_filters';
/** Name of event filters agnostic list */
export const ENDPOINT_EVENT_FILTERS_LIST_NAME = 'Endpoint Security Event Filters List';
/** Description of event filters agnostic list */
export const ENDPOINT_EVENT_FILTERS_LIST_DESCRIPTION = 'Endpoint Security Event Filters List';

View file

@ -4,5 +4,3 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './shared_exports';

View file

@ -6,6 +6,12 @@
*/
import type { ExceptionListSchema } from '@kbn/securitysolution-io-ts-list-types';
import {
ENDPOINT_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
ENDPOINT_TRUSTED_APPS_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_NAME,
} from '@kbn/securitysolution-list-constants';
import {
DATE_NOW,
@ -21,12 +27,6 @@ import {
VERSION,
_VERSION,
} from '../../constants.mock';
import { ENDPOINT_LIST_ID } from '../..';
import {
ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
ENDPOINT_TRUSTED_APPS_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_NAME,
} from '../../constants';
export const getExceptionListSchemaMock = (): ExceptionListSchema => ({
_version: _VERSION,

View file

@ -1,19 +0,0 @@
/*
* 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.
*/
/** DEPRECATED, TRY NOT NOT TO ADD ANYTHING HERE. INSTEAD TRY TO USE/CREATE kibana packages @kbn/... */
// TODO: Move this into one of the kibana packages and remove it from here
export {
ENDPOINT_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_ID,
EXCEPTION_LIST_URL,
EXCEPTION_LIST_ITEM_URL,
ENDPOINT_EVENT_FILTERS_LIST_ID,
ENDPOINT_EVENT_FILTERS_LIST_NAME,
ENDPOINT_EVENT_FILTERS_LIST_DESCRIPTION,
} from './constants';

View file

@ -1,27 +0,0 @@
/*
* 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.
*/
export const exceptionListSavedObjectType = 'exception-list';
export const exceptionListAgnosticSavedObjectType = 'exception-list-agnostic';
export type SavedObjectType = 'exception-list' | 'exception-list-agnostic';
/**
* This makes any optional property the same as Required<T> would but also has the
* added benefit of keeping your undefined.
*
* For example:
* type A = RequiredKeepUndefined<{ a?: undefined; b: number }>;
*
* will yield a type of:
* type A = { a: undefined; b: number; }
* @deprecated This has no replacement. We should stop using/relying on this and just remove it.
*/
export type RequiredKeepUndefined<T> = { [K in keyof T]-?: [T[K]] } extends infer U
? U extends Record<keyof U, [unknown]>
? { [K in keyof U]: U[K][0] }
: never
: never;

View file

@ -1,271 +0,0 @@
/*
* 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 { getFilters, getGeneralFilters, getIdsAndNamespaces, getTrustedAppsFilter } from './utils';
describe('Exceptions utils', () => {
describe('#getIdsAndNamespaces', () => {
test('it returns empty arrays if no lists found', async () => {
const output = getIdsAndNamespaces({
lists: [],
showDetection: false,
showEndpoint: false,
});
expect(output).toEqual({ ids: [], namespaces: [] });
});
test('it returns all lists if "showDetection" and "showEndpoint" are "false"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: false,
showEndpoint: false,
});
expect(output).toEqual({
ids: ['list_id', 'list_id_endpoint'],
namespaces: ['single', 'agnostic'],
});
});
test('it returns only detections lists if "showDetection" is "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: true,
showEndpoint: false,
});
expect(output).toEqual({
ids: ['list_id'],
namespaces: ['single'],
});
});
test('it returns only endpoint lists if "showEndpoint" is "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: false,
showEndpoint: true,
});
expect(output).toEqual({
ids: ['list_id_endpoint'],
namespaces: ['agnostic'],
});
});
test('it returns only detection lists if both "showEndpoint" and "showDetection" are "true"', async () => {
const output = getIdsAndNamespaces({
lists: [
{ id: 'myListId', listId: 'list_id', namespaceType: 'single', type: 'detection' },
{
id: 'myListIdEndpoint',
listId: 'list_id_endpoint',
namespaceType: 'agnostic',
type: 'endpoint',
},
],
showDetection: true,
showEndpoint: true,
});
expect(output).toEqual({
ids: ['list_id'],
namespaces: ['single'],
});
});
});
describe('getGeneralFilters', () => {
test('it returns empty string if no filters', () => {
const filters = getGeneralFilters({}, ['exception-list']);
expect(filters).toEqual('');
});
test('it properly formats filters when one namespace type passed in', () => {
const filters = getGeneralFilters({ created_by: 'moi', name: 'Sample' }, ['exception-list']);
expect(filters).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample)'
);
});
test('it properly formats filters when two namespace types passed in', () => {
const filters = getGeneralFilters({ created_by: 'moi', name: 'Sample' }, [
'exception-list',
'exception-list-agnostic',
]);
expect(filters).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample)'
);
});
});
describe('getTrustedAppsFilter', () => {
test('it returns filter to search for "exception-list" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(true, ['exception-list']);
expect(filter).toEqual('(exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it returns filter to search for "exception-list" and "agnostic" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(true, ['exception-list', 'exception-list-agnostic']);
expect(filter).toEqual(
'(exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it returns filter to exclude "exception-list" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(false, ['exception-list']);
expect(filter).toEqual('(not exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it returns filter to exclude "exception-list" and "agnostic" namespace trusted apps', () => {
const filter = getTrustedAppsFilter(false, ['exception-list', 'exception-list-agnostic']);
expect(filter).toEqual(
'(not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
describe('getFilters', () => {
describe('single', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['single'], false);
expect(filter).toEqual('(not exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['single'], true);
expect(filter).toEqual('(exception-list.attributes.list_id: endpoint_trusted_apps*)');
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['single'], false);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample) AND (not exception-list.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it if filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['single'], true);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample) AND (exception-list.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
describe('agnostic', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['agnostic'], false);
expect(filter).toEqual(
'(not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['agnostic'], true);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['agnostic'], false);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.created_by:moi) AND (exception-list-agnostic.attributes.name.text:Sample) AND (not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it if filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({ created_by: 'moi', name: 'Sample' }, ['agnostic'], true);
expect(filter).toEqual(
'(exception-list-agnostic.attributes.created_by:moi) AND (exception-list-agnostic.attributes.name.text:Sample) AND (exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
describe('single, agnostic', () => {
test('it properly formats when no filters passed and "showTrustedApps" is false', () => {
const filter = getFilters({}, ['single', 'agnostic'], false);
expect(filter).toEqual(
'(not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when no filters passed and "showTrustedApps" is true', () => {
const filter = getFilters({}, ['single', 'agnostic'], true);
expect(filter).toEqual(
'(exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is false', () => {
const filter = getFilters(
{ created_by: 'moi', name: 'Sample' },
['single', 'agnostic'],
false
);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample) AND (not exception-list.attributes.list_id: endpoint_trusted_apps* AND not exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
test('it properly formats when filters passed and "showTrustedApps" is true', () => {
const filter = getFilters(
{ created_by: 'moi', name: 'Sample' },
['single', 'agnostic'],
true
);
expect(filter).toEqual(
'(exception-list.attributes.created_by:moi OR exception-list-agnostic.attributes.created_by:moi) AND (exception-list.attributes.name.text:Sample OR exception-list-agnostic.attributes.name.text:Sample) AND (exception-list.attributes.list_id: endpoint_trusted_apps* OR exception-list-agnostic.attributes.list_id: endpoint_trusted_apps*)'
);
});
});
});
});

View file

@ -1,119 +0,0 @@
/*
* 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 { get } from 'lodash/fp';
import type {
ExceptionListFilter,
ExceptionListIdentifiers,
NamespaceType,
NamespaceTypeArray,
} from '@kbn/securitysolution-io-ts-list-types';
import { ENDPOINT_TRUSTED_APPS_LIST_ID } from '../../common/constants';
import {
SavedObjectType,
exceptionListAgnosticSavedObjectType,
exceptionListSavedObjectType,
} from '../../common/types';
export const getSavedObjectType = ({
namespaceType,
}: {
namespaceType: NamespaceType;
}): SavedObjectType => {
if (namespaceType === 'agnostic') {
return exceptionListAgnosticSavedObjectType;
} else {
return exceptionListSavedObjectType;
}
};
export const getSavedObjectTypes = ({
namespaceType,
}: {
namespaceType: NamespaceTypeArray;
}): SavedObjectType[] => {
return namespaceType.map((singleNamespaceType) =>
getSavedObjectType({ namespaceType: singleNamespaceType })
);
};
export const getIdsAndNamespaces = ({
lists,
showDetection,
showEndpoint,
}: {
lists: ExceptionListIdentifiers[];
showDetection: boolean;
showEndpoint: boolean;
}): { ids: string[]; namespaces: NamespaceType[] } =>
lists
.filter((list) => {
if (showDetection) {
return list.type === 'detection';
} else if (showEndpoint) {
return list.type === 'endpoint';
} else {
return true;
}
})
.reduce<{ ids: string[]; namespaces: NamespaceType[] }>(
(acc, { listId, namespaceType }) => ({
ids: [...acc.ids, listId],
namespaces: [...acc.namespaces, namespaceType],
}),
{ ids: [], namespaces: [] }
);
export const getGeneralFilters = (
filters: ExceptionListFilter,
namespaceTypes: SavedObjectType[]
): string => {
return Object.keys(filters)
.map((filterKey) => {
const value = get(filterKey, filters);
if (value != null && value.trim() !== '') {
const filtersByNamespace = namespaceTypes
.map((namespace) => {
const fieldToSearch = filterKey === 'name' ? 'name.text' : filterKey;
return `${namespace}.attributes.${fieldToSearch}:${value}`;
})
.join(' OR ');
return `(${filtersByNamespace})`;
} else return null;
})
.filter((item) => item != null)
.join(' AND ');
};
export const getTrustedAppsFilter = (
showTrustedApps: boolean,
namespaceTypes: SavedObjectType[]
): string => {
if (showTrustedApps) {
const filters = namespaceTypes.map((namespace) => {
return `${namespace}.attributes.list_id: ${ENDPOINT_TRUSTED_APPS_LIST_ID}*`;
});
return `(${filters.join(' OR ')})`;
} else {
const filters = namespaceTypes.map((namespace) => {
return `not ${namespace}.attributes.list_id: ${ENDPOINT_TRUSTED_APPS_LIST_ID}*`;
});
return `(${filters.join(' AND ')})`;
}
};
export const getFilters = (
filters: ExceptionListFilter,
namespaceTypes: NamespaceType[],
showTrustedApps: boolean
): string => {
const namespaces = getSavedObjectTypes({ namespaceType: namespaceTypes });
const generalFilters = getGeneralFilters(filters, namespaces);
const trustedAppsFilter = getTrustedAppsFilter(showTrustedApps, namespaces);
return [generalFilters, trustedAppsFilter].filter((filter) => filter.trim() !== '').join(' AND ');
};

View file

@ -12,9 +12,9 @@ import {
createEndpointListItemSchema,
exceptionListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { ENDPOINT_LIST_ID, ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { ENDPOINT_LIST_ID, ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';
import { validateExceptionListSize } from './validate';

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { createEndpointListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { ENDPOINT_LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { ENDPOINT_LIST_URL } from '../../common/constants';
import { buildSiemResponse } from './utils';
import { getExceptionListClient } from './utils/get_exception_list_client';

View file

@ -12,9 +12,9 @@ import {
createExceptionListItemSchema,
exceptionListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';
import { getExceptionListClient } from './utils/get_exception_list_client';

View file

@ -12,9 +12,9 @@ import {
createExceptionListSchema,
exceptionListSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';
import { getExceptionListClient } from './utils/get_exception_list_client';

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { acknowledgeSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_INDEX } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_INDEX } from '../../common/constants';
import { buildSiemResponse } from './utils';

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { createListItemSchema, listItemSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -12,9 +12,9 @@ import {
createListSchema,
listSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -12,9 +12,9 @@ import {
deleteEndpointListItemSchema,
exceptionListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
import {
buildRouteValidation,

View file

@ -12,9 +12,9 @@ import {
deleteExceptionListItemSchema,
exceptionListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
import {
buildRouteValidation,

View file

@ -12,9 +12,9 @@ import {
deleteExceptionListSchema,
exceptionListSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_URL } from '../../common/constants';
import {
buildRouteValidation,

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { acknowledgeSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_INDEX } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_INDEX } from '../../common/constants';
import { buildSiemResponse } from './utils';

View file

@ -12,9 +12,9 @@ import {
listItemArraySchema,
listItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -15,10 +15,10 @@ import {
exceptionListItemSchema,
listSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import { LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_URL } from '../../common/constants';
import { getSavedObjectType } from '../services/exception_lists/utils';
import { ExceptionListClient } from '../services/exception_lists/exception_list_client';
import { escapeQuotes } from '../services/utils/escape_query';

View file

@ -7,9 +7,9 @@
import { transformError } from '@kbn/securitysolution-es-utils';
import { exportExceptionListQuerySchema } from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';

View file

@ -9,9 +9,9 @@ import { Stream } from 'stream';
import { transformError } from '@kbn/securitysolution-es-utils';
import { exportListItemQuerySchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -12,9 +12,9 @@ import {
findEndpointListItemSchema,
foundExceptionListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { ENDPOINT_LIST_ID, ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { ENDPOINT_LIST_ID, ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';

View file

@ -12,9 +12,9 @@ import {
findExceptionListItemSchema,
foundExceptionListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';

View file

@ -12,9 +12,9 @@ import {
findExceptionListSchema,
foundExceptionListSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';

View file

@ -12,9 +12,9 @@ import {
findListItemSchema,
foundListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_ITEM_URL } from '../../common/constants';
import { decodeCursor } from '../services/utils';
import { buildRouteValidation, buildSiemResponse, getListClient } from './utils';

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { findListSchema, foundListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_URL } from '../../common/constants';
import { decodeCursor } from '../services/utils';
import { buildRouteValidation, buildSiemResponse, getListClient } from './utils';

View file

@ -9,9 +9,9 @@ import { schema } from '@kbn/config-schema';
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { importListItemQuerySchema, listSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_ITEM_URL } from '../../common/constants';
import { ConfigType } from '../config';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { listItemSchema, patchListItemSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { listSchema, patchListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -12,9 +12,9 @@ import {
exceptionListItemSchema,
readEndpointListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
import {
buildRouteValidation,

View file

@ -12,9 +12,9 @@ import {
exceptionListItemSchema,
readExceptionListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
import {
buildRouteValidation,

View file

@ -12,9 +12,9 @@ import {
exceptionListSchema,
readExceptionListSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_URL } from '../../common/constants';
import {
buildRouteValidation,

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { listItemIndexExistSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_INDEX } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_INDEX } from '../../common/constants';
import { buildSiemResponse } from './utils';

View file

@ -12,9 +12,9 @@ import {
listItemSchema,
readListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { listSchema, readListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -7,9 +7,9 @@
import { readPrivileges, transformError } from '@kbn/securitysolution-es-utils';
import { merge } from 'lodash/fp';
import { LIST_PRIVILEGES_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_PRIVILEGES_URL } from '../../common/constants';
import { buildSiemResponse, getListClient } from './utils';

View file

@ -12,9 +12,9 @@ import {
exceptionListItemSchema,
updateEndpointListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { ENDPOINT_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -13,9 +13,9 @@ import {
updateExceptionListItemSchema,
updateExceptionListItemValidate,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -12,9 +12,9 @@ import {
exceptionListSchema,
updateExceptionListSchema,
} from '@kbn/securitysolution-io-ts-list-types';
import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { EXCEPTION_LIST_URL } from '../../common/constants';
import {
buildRouteValidation,

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { listItemSchema, updateListItemSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_ITEM_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -8,9 +8,9 @@
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { transformError } from '@kbn/securitysolution-es-utils';
import { listSchema, updateListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_URL } from '@kbn/securitysolution-list-constants';
import type { ListsPluginRouter } from '../types';
import { LIST_URL } from '../../common/constants';
import { buildRouteValidation, buildSiemResponse } from './utils';

View file

@ -15,9 +15,9 @@ import {
foundExceptionListItemSchema,
nonEmptyEndpointEntriesArray,
} from '@kbn/securitysolution-io-ts-list-types';
import { MAX_EXCEPTION_LIST_SIZE } from '@kbn/securitysolution-list-constants';
import { ExceptionListClient } from '../services/exception_lists/exception_list_client';
import { MAX_EXCEPTION_LIST_SIZE } from '../../common/constants';
export const validateExceptionListSize = async (
exceptionLists: ExceptionListClient,

View file

@ -6,11 +6,10 @@
*/
import { SavedObjectsType } from 'kibana/server';
import {
exceptionListAgnosticSavedObjectType,
exceptionListSavedObjectType,
} from '../../common/types';
} from '@kbn/securitysolution-list-utils';
import { migrations } from './migrations';

View file

@ -7,8 +7,11 @@
import { SavedObjectUnsanitizedDoc } from 'kibana/server';
import uuid from 'uuid';
import {
ENDPOINT_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_ID,
} from '@kbn/securitysolution-list-constants';
import { ENDPOINT_LIST_ID, ENDPOINT_TRUSTED_APPS_LIST_ID } from '../../common/constants';
import { ExceptionListSoSchema } from '../schemas/saved_objects';
import { OldExceptionListSoSchema, migrations } from './migrations';

View file

@ -14,8 +14,11 @@ import {
entriesNested,
entry,
} from '@kbn/securitysolution-io-ts-list-types';
import {
ENDPOINT_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_ID,
} from '@kbn/securitysolution-list-constants';
import { ENDPOINT_LIST_ID, ENDPOINT_TRUSTED_APPS_LIST_ID } from '../../common/constants';
import { ExceptionListSoSchema } from '../schemas/saved_objects';
const entryType = t.union([entry, entriesNested]);

View file

@ -9,15 +9,16 @@ import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';
import { Version } from '@kbn/securitysolution-io-ts-types';
import type { ExceptionListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import {
ENDPOINT_EVENT_FILTERS_LIST_DESCRIPTION,
ENDPOINT_EVENT_FILTERS_LIST_ID,
ENDPOINT_EVENT_FILTERS_LIST_NAME,
} from '../../../common/constants';
} from '@kbn/securitysolution-list-constants';
import { ExceptionListSoSchema } from '../../schemas/saved_objects';
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';
import { transformSavedObjectToExceptionList } from './utils';
interface CreateEndpointEventFiltersListOptions {
savedObjectsClient: SavedObjectsClientContract;

View file

@ -9,15 +9,16 @@ import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';
import { Version } from '@kbn/securitysolution-io-ts-types';
import type { ExceptionListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import {
ENDPOINT_LIST_DESCRIPTION,
ENDPOINT_LIST_ID,
ENDPOINT_LIST_NAME,
} from '../../../common/constants';
} from '@kbn/securitysolution-list-constants';
import { ExceptionListSoSchema } from '../../schemas/saved_objects';
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';
import { transformSavedObjectToExceptionList } from './utils';
interface CreateEndpointListOptions {
savedObjectsClient: SavedObjectsClientContract;

View file

@ -9,15 +9,16 @@ import { SavedObjectsClientContract } from 'kibana/server';
import uuid from 'uuid';
import type { Version } from '@kbn/securitysolution-io-ts-types';
import type { ExceptionListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import {
ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION,
ENDPOINT_TRUSTED_APPS_LIST_ID,
ENDPOINT_TRUSTED_APPS_LIST_NAME,
} from '../../../common/constants';
} from '@kbn/securitysolution-list-constants';
import { ExceptionListSoSchema } from '../../schemas/saved_objects';
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';
import { transformSavedObjectToExceptionList } from './utils';
interface CreateEndpointListOptions {
savedObjectsClient: SavedObjectsClientContract;

View file

@ -19,10 +19,11 @@ import type {
Tags,
} from '@kbn/securitysolution-io-ts-list-types';
import { Version } from '@kbn/securitysolution-io-ts-types';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import { ExceptionListSoSchema } from '../../schemas/saved_objects';
import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils';
import { transformSavedObjectToExceptionList } from './utils';
interface CreateExceptionListOptions {
listId: ListId;

View file

@ -21,11 +21,11 @@ import type {
OsTypeArray,
Tags,
} from '@kbn/securitysolution-io-ts-list-types';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import { ExceptionListSoSchema } from '../../schemas/saved_objects';
import {
getSavedObjectType,
transformCreateCommentsToComments,
transformSavedObjectToExceptionListItem,
} from './utils';

View file

@ -12,8 +12,8 @@ import type {
ListIdOrUndefined,
NamespaceType,
} from '@kbn/securitysolution-io-ts-list-types';
import { getSavedObjectType } from '@kbn/securitysolution-list-utils';
import { getSavedObjectType } from './utils';
import { getExceptionList } from './get_exception_list';
import { deleteExceptionListItemByList } from './delete_exception_list_items_by_list';

Some files were not shown because too many files have changed in this diff Show more