mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Security Solutions] Removes circular dependencies and introduces kbn-security-solution-es-utils package (#99828)
## Summary Fixes the hopefully last circular dependency issues between security solutions and lists. * Adds a package of `@kbn/securitysolution-es-utils` and moves files from security solutions into that package. * Re-ingests that package back into lists Before this PR if you ran: ```ts node scripts/find_plugins_with_circular_deps.js --debug ``` Then you would get: ``` debg !!!!!!!!!!!!!! CIRCULAR DEPENDENCIES FOUND !!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Circular dependencies were found, you can find below ! ! all the paths involved. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! debg 01) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts 02) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/compose/kibana.ts -> x-pack/plugins/security_solution/server/lib/framework/kibana_framework_adapter.ts -> x-pack/plugins/security_solution/server/types.ts 03) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/compose/kibana.ts -> x-pack/plugins/security_solution/server/endpoint/types.ts -> x-pack/plugins/security_solution/server/endpoint/endpoint_app_context_services.ts 04) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/compose/kibana.ts -> x-pack/plugins/security_solution/server/endpoint/types.ts -> x-pack/plugins/security_solution/server/endpoint/endpoint_app_context_services.ts -> x-pack/plugins/security_solution/server/fleet_integration/fleet_integration.ts 05) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/compose/kibana.ts -> x-pack/plugins/security_solution/server/endpoint/types.ts -> x-pack/plugins/security_solution/server/endpoint/endpoint_app_context_services.ts -> x-pack/plugins/security_solution/server/fleet_integration/fleet_integration.ts -> x-pack/plugins/security_solution/server/endpoint/services/index.ts -> x-pack/plugins/security_solution/server/endpoint/services/artifacts/index.ts -> x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/index.ts -> x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.ts 06) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/compose/kibana.ts -> x-pack/plugins/security_solution/server/endpoint/types.ts -> x-pack/plugins/security_solution/server/endpoint/endpoint_app_context_services.ts -> x-pack/plugins/security_solution/server/fleet_integration/fleet_integration.ts -> x-pack/plugins/security_solution/server/endpoint/services/index.ts -> x-pack/plugins/security_solution/server/endpoint/services/artifacts/index.ts -> x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/index.ts -> x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.ts -> x-pack/plugins/security_solution/server/endpoint/lib/artifacts/index.ts -> x-pack/plugins/security_solution/server/endpoint/lib/artifacts/lists.ts 07) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/compose/kibana.ts -> x-pack/plugins/security_solution/server/endpoint/types.ts -> x-pack/plugins/security_solution/server/endpoint/endpoint_app_context_services.ts -> x-pack/plugins/security_solution/server/fleet_integration/fleet_integration.ts -> x-pack/plugins/security_solution/server/fleet_integration/handlers/install_prepackaged_rules.ts 08) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/compose/kibana.ts -> x-pack/plugins/security_solution/server/endpoint/types.ts -> x-pack/plugins/security_solution/server/endpoint/endpoint_app_context_services.ts -> x-pack/plugins/security_solution/server/fleet_integration/fleet_integration.ts -> x-pack/plugins/security_solution/server/fleet_integration/handlers/install_prepackaged_rules.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts 09) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/types.ts 10) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/utils.ts 11) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/query.ts 12) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/query.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/filters/filter_events_against_list.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/filters/types.ts 13) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/threat_match.ts 14) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/threat_match.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/create_threat_signals.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/get_threat_list.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/types.ts 15) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts -> x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/ml.ts 16) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/index.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/handlers.ts 17) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/index.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/handlers.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/service.ts 18) x-pack/plugins/lists/server/index.ts -> x-pack/plugins/lists/server/plugin.ts -> x-pack/plugins/lists/server/routes/init_routes.ts -> x-pack/plugins/lists/server/types.ts -> x-pack/plugins/lists/server/services/lists/list_client.ts -> x-pack/plugins/lists/server/siem_server_deps.ts -> x-pack/plugins/security_solution/server/index.ts -> x-pack/plugins/security_solution/server/plugin.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/index.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/handlers.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/service.ts -> x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/mapping.ts debg !!!!!!!!!!!!!!!!! UP TO DATE ALLOWED LIST !!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! The declared circular dependencies allowed list is up ! ! to date and includes every plugin listed in above paths. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! The allowed circular dependencies list is (#3): 'x-pack/plugins/lists -> x-pack/plugins/security_solution', succ None non allowed circular dependencies were found ``` Now you get: ``` debg !!!!!!!!!!!!!!!!! UP TO DATE ALLOWED LIST !!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! The declared circular dependencies allowed list is up ! ! to date and includes every plugin listed in above paths. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! The allowed circular dependencies list is (#1): 'x-pack/plugins/lists -> x-pack/plugins/security_solution', succ None non allowed circular dependencies were found ``` ### Checklist Delete any items that are not applicable to this PR. - [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:
parent
9b2e8c94d3
commit
6d80bf7a21
77 changed files with 1101 additions and 100 deletions
|
@ -82,6 +82,7 @@ yarn kbn watch-bazel
|
|||
- @kbn/logging
|
||||
- @kbn/securitysolution-constants
|
||||
- @kbn/securitysolution-utils
|
||||
- @kbn/securitysolution-es-utils
|
||||
- @kbn/securitysolution-io-ts-utils
|
||||
- @kbn/std
|
||||
- @kbn/telemetry-utils
|
||||
|
|
|
@ -137,6 +137,7 @@
|
|||
"@kbn/monaco": "link:packages/kbn-monaco",
|
||||
"@kbn/securitysolution-constants": "link:bazel-bin/packages/kbn-securitysolution-constants/npm_module",
|
||||
"@kbn/securitysolution-utils": "link:bazel-bin/packages/kbn-securitysolution-utils/npm_module",
|
||||
"@kbn/securitysolution-es-utils": "link:bazel-bin/packages/kbn-securitysolution-es-utils/npm_module",
|
||||
"@kbn/securitysolution-io-ts-utils": "link:bazel-bin/packages/kbn-securitysolution-io-ts-utils/npm_module",
|
||||
"@kbn/server-http-tools": "link:packages/kbn-server-http-tools",
|
||||
"@kbn/server-route-repository": "link:packages/kbn-server-route-repository",
|
||||
|
|
|
@ -26,6 +26,7 @@ filegroup(
|
|||
"//packages/kbn-securitysolution-constants:build",
|
||||
"//packages/kbn-securitysolution-io-ts-utils:build",
|
||||
"//packages/kbn-securitysolution-utils:build",
|
||||
"//packages/kbn-securitysolution-es-utils:build",
|
||||
"//packages/kbn-std:build",
|
||||
"//packages/kbn-telemetry-tools:build",
|
||||
"//packages/kbn-tinymath:build",
|
||||
|
|
86
packages/kbn-securitysolution-es-utils/BUILD.bazel
Normal file
86
packages/kbn-securitysolution-es-utils/BUILD.bazel
Normal file
|
@ -0,0 +1,86 @@
|
|||
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-es-utils"
|
||||
|
||||
PKG_REQUIRE_NAME = "@kbn/securitysolution-es-utils"
|
||||
|
||||
SOURCE_FILES = glob(
|
||||
[
|
||||
"src/**/*.ts",
|
||||
],
|
||||
exclude = [
|
||||
"**/*.test.*",
|
||||
"**/*.mock.*",
|
||||
],
|
||||
)
|
||||
|
||||
SRCS = SOURCE_FILES
|
||||
|
||||
filegroup(
|
||||
name = "srcs",
|
||||
srcs = SRCS,
|
||||
)
|
||||
|
||||
NPM_MODULE_EXTRA_FILES = [
|
||||
"package.json",
|
||||
"README.md",
|
||||
]
|
||||
|
||||
SRC_DEPS = [
|
||||
"@npm//@elastic/elasticsearch",
|
||||
"@npm//@hapi/hapi",
|
||||
"@npm//tslib",
|
||||
]
|
||||
|
||||
TYPES_DEPS = [
|
||||
"@npm//@types/jest",
|
||||
"@npm//@types/node",
|
||||
]
|
||||
|
||||
DEPS = SRC_DEPS + TYPES_DEPS
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
deps = [
|
||||
"//:tsconfig.base.json",
|
||||
],
|
||||
)
|
||||
|
||||
ts_project(
|
||||
name = "tsc",
|
||||
srcs = SRCS,
|
||||
args = ["--pretty"],
|
||||
declaration = True,
|
||||
declaration_map = True,
|
||||
incremental = True,
|
||||
out_dir = "target",
|
||||
root_dir = "src",
|
||||
source_map = True,
|
||||
tsconfig = ":tsconfig",
|
||||
deps = DEPS,
|
||||
)
|
||||
|
||||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":tsc"] + DEPS,
|
||||
)
|
||||
|
||||
pkg_npm(
|
||||
name = "npm_module",
|
||||
deps = [
|
||||
":%s" % PKG_BASE_NAME,
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "build",
|
||||
srcs = [
|
||||
":npm_module",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
6
packages/kbn-securitysolution-es-utils/README.md
Normal file
6
packages/kbn-securitysolution-es-utils/README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
# kbn-securitysolution-es-utils
|
||||
|
||||
This is the shared security solution elastic search utilities among plugins. This was originally created
|
||||
to remove the dependencies between security_solution and other projects such as lists. This should only be
|
||||
used within server side code and not client side code since it is all elastic search utilities and packages.
|
||||
|
13
packages/kbn-securitysolution-es-utils/jest.config.js
Normal file
13
packages/kbn-securitysolution-es-utils/jest.config.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
preset: '@kbn/test',
|
||||
rootDir: '../..',
|
||||
roots: ['<rootDir>/packages/kbn-securitysolution-es-utils'],
|
||||
};
|
9
packages/kbn-securitysolution-es-utils/package.json
Normal file
9
packages/kbn-securitysolution-es-utils/package.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@kbn/securitysolution-es-utils",
|
||||
"version": "1.0.0",
|
||||
"description": "security solution elastic search utilities 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
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export class BadRequestError extends Error {}
|
|
@ -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 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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
// See the reference(s) below on explanations about why -000001 was chosen and
|
||||
// why the is_write_index is true as well as the bootstrapping step which is needed.
|
||||
// Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/applying-policy-to-template.html
|
||||
export const createBootstrapIndex = async (
|
||||
esClient: ElasticsearchClient,
|
||||
index: string
|
||||
): Promise<unknown> => {
|
||||
return (
|
||||
await esClient.transport.request({
|
||||
path: `/${index}-000001`,
|
||||
method: 'PUT',
|
||||
body: {
|
||||
aliases: {
|
||||
[index]: {
|
||||
is_write_index: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
).body;
|
||||
};
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
export const deleteAllIndex = async (
|
||||
esClient: ElasticsearchClient,
|
||||
pattern: string,
|
||||
maxAttempts = 5
|
||||
): Promise<boolean> => {
|
||||
for (let attempt = 1; ; attempt++) {
|
||||
if (attempt > maxAttempts) {
|
||||
throw new Error(
|
||||
`Failed to delete indexes with pattern [${pattern}] after ${maxAttempts} attempts`
|
||||
);
|
||||
}
|
||||
|
||||
// resolve pattern to concrete index names
|
||||
const { body: resp } = await esClient.indices.getAlias(
|
||||
{
|
||||
index: pattern,
|
||||
},
|
||||
{ ignore: [404] }
|
||||
);
|
||||
|
||||
// @ts-expect-error status doesn't exist on response
|
||||
if (resp.status === 404) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const indices = Object.keys(resp) as string[];
|
||||
|
||||
// if no indexes exits then we're done with this pattern
|
||||
if (!indices.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// delete the concrete indexes we found and try again until this pattern resolves to no indexes
|
||||
await esClient.indices.delete({
|
||||
index: indices,
|
||||
ignore_unavailable: true,
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
export const deletePolicy = async (
|
||||
esClient: ElasticsearchClient,
|
||||
policy: string
|
||||
): Promise<unknown> => {
|
||||
return (
|
||||
await esClient.transport.request({
|
||||
path: `/_ilm/policy/${policy}`,
|
||||
method: 'DELETE',
|
||||
})
|
||||
).body;
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* 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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
export const deleteTemplate = async (
|
||||
esClient: ElasticsearchClient,
|
||||
name: string
|
||||
): Promise<unknown> => {
|
||||
return (
|
||||
await esClient.indices.deleteTemplate({
|
||||
name,
|
||||
})
|
||||
).body;
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Copied from src/core/server/elasticsearch/client/types.ts
|
||||
// as these types aren't part of any package yet. Once they are, remove this completely
|
||||
|
||||
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
|
||||
import type {
|
||||
ApiResponse,
|
||||
TransportRequestOptions,
|
||||
TransportRequestParams,
|
||||
TransportRequestPromise,
|
||||
} from '@elastic/elasticsearch/lib/Transport';
|
||||
|
||||
/**
|
||||
* Client used to query the elasticsearch cluster.
|
||||
* @deprecated At some point use the one from src/core/server/elasticsearch/client/types.ts when it is made into a package. If it never is, then keep using this one.
|
||||
* @public
|
||||
*/
|
||||
export type ElasticsearchClient = Omit<
|
||||
KibanaClient,
|
||||
'connectionPool' | 'transport' | 'serializer' | 'extend' | 'child' | 'close'
|
||||
> & {
|
||||
transport: {
|
||||
request(
|
||||
params: TransportRequestParams,
|
||||
options?: TransportRequestOptions
|
||||
): TransportRequestPromise<ApiResponse>;
|
||||
};
|
||||
};
|
|
@ -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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
export const getIndexExists = async (
|
||||
esClient: ElasticsearchClient,
|
||||
index: string
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const { body: response } = await esClient.search({
|
||||
index,
|
||||
size: 0,
|
||||
allow_no_indices: true,
|
||||
body: {
|
||||
terminate_after: 1,
|
||||
},
|
||||
});
|
||||
return response._shards.total > 0;
|
||||
} catch (err) {
|
||||
if (err.body != null && err.body.status === 404) {
|
||||
return false;
|
||||
} else {
|
||||
throw err.body ? err.body : err;
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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 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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
export const getPolicyExists = async (
|
||||
esClient: ElasticsearchClient,
|
||||
policy: string
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
await esClient.transport.request({
|
||||
path: `/_ilm/policy/${policy}`,
|
||||
method: 'GET',
|
||||
});
|
||||
// Return true that there exists a policy which is not 404 or some error
|
||||
// Since there is not a policy exists API, this is how we create one by calling
|
||||
// into the API to get it if it exists or rely on it to throw a 404
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err.statusCode === 404) {
|
||||
return false;
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* 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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
export const getTemplateExists = async (
|
||||
esClient: ElasticsearchClient,
|
||||
template: string
|
||||
): Promise<boolean> => {
|
||||
return (
|
||||
await esClient.indices.existsTemplate({
|
||||
name: template,
|
||||
})
|
||||
).body;
|
||||
};
|
21
packages/kbn-securitysolution-es-utils/src/index.ts
Normal file
21
packages/kbn-securitysolution-es-utils/src/index.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export * from './bad_request_error';
|
||||
export * from './create_boostrap_index';
|
||||
export * from './delete_all_index';
|
||||
export * from './delete_policy';
|
||||
export * from './delete_template';
|
||||
export * from './elasticsearch_client';
|
||||
export * from './get_index_exists';
|
||||
export * from './get_policy_exists';
|
||||
export * from './get_template_exists';
|
||||
export * from './read_privileges';
|
||||
export * from './set_policy';
|
||||
export * from './set_template';
|
||||
export * from './transform_error';
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copied from src/core/server/elasticsearch/legacy/api_types.ts including its deprecation mentioned below
|
||||
* TODO: Remove this and refactor the readPrivileges to utilize any newer client side ways rather than all this deprecated legacy stuff
|
||||
*/
|
||||
export interface LegacyCallAPIOptions {
|
||||
/**
|
||||
* Indicates whether `401 Unauthorized` errors returned from the Elasticsearch API
|
||||
* should be wrapped into `Boom` error instances with properly set `WWW-Authenticate`
|
||||
* header that could have been returned by the API itself. If API didn't specify that
|
||||
* then `Basic realm="Authorization Required"` is used as `WWW-Authenticate`.
|
||||
*/
|
||||
wrap401Errors?: boolean;
|
||||
/**
|
||||
* A signal object that allows you to abort the request via an AbortController object.
|
||||
*/
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
type CallWithRequest<T extends Record<string, any>, V> = (
|
||||
endpoint: string,
|
||||
params: T,
|
||||
options?: LegacyCallAPIOptions
|
||||
) => Promise<V>;
|
||||
|
||||
export const readPrivileges = async (
|
||||
callWithRequest: CallWithRequest<{}, unknown>,
|
||||
index: string
|
||||
): Promise<unknown> => {
|
||||
return callWithRequest('transport.request', {
|
||||
path: '/_security/user/_has_privileges',
|
||||
method: 'POST',
|
||||
body: {
|
||||
cluster: [
|
||||
'all',
|
||||
'create_snapshot',
|
||||
'manage',
|
||||
'manage_api_key',
|
||||
'manage_ccr',
|
||||
'manage_transform',
|
||||
'manage_ilm',
|
||||
'manage_index_templates',
|
||||
'manage_ingest_pipelines',
|
||||
'manage_ml',
|
||||
'manage_own_api_key',
|
||||
'manage_pipeline',
|
||||
'manage_rollup',
|
||||
'manage_saml',
|
||||
'manage_security',
|
||||
'manage_token',
|
||||
'manage_watcher',
|
||||
'monitor',
|
||||
'monitor_transform',
|
||||
'monitor_ml',
|
||||
'monitor_rollup',
|
||||
'monitor_watcher',
|
||||
'read_ccr',
|
||||
'read_ilm',
|
||||
'transport_client',
|
||||
],
|
||||
index: [
|
||||
{
|
||||
names: [index],
|
||||
privileges: [
|
||||
'all',
|
||||
'create',
|
||||
'create_doc',
|
||||
'create_index',
|
||||
'delete',
|
||||
'delete_index',
|
||||
'index',
|
||||
'manage',
|
||||
'maintenance',
|
||||
'manage_follow_index',
|
||||
'manage_ilm',
|
||||
'manage_leader_index',
|
||||
'monitor',
|
||||
'read',
|
||||
'read_cross_cluster',
|
||||
'view_index_metadata',
|
||||
'write',
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
};
|
|
@ -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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
export const setPolicy = async (
|
||||
esClient: ElasticsearchClient,
|
||||
policy: string,
|
||||
body: Record<string, unknown>
|
||||
): Promise<unknown> => {
|
||||
return (
|
||||
await esClient.transport.request({
|
||||
path: `/_ilm/policy/${policy}`,
|
||||
method: 'PUT',
|
||||
body,
|
||||
})
|
||||
).body;
|
||||
};
|
|
@ -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 { ElasticsearchClient } from '../elasticsearch_client';
|
||||
|
||||
export const setTemplate = async (
|
||||
esClient: ElasticsearchClient,
|
||||
name: string,
|
||||
body: Record<string, unknown>
|
||||
): Promise<unknown> => {
|
||||
return (
|
||||
await esClient.indices.putTemplate({
|
||||
name,
|
||||
body,
|
||||
})
|
||||
).body;
|
||||
};
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* 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 Boom from '@hapi/boom';
|
||||
import { transformError } from '.';
|
||||
import { BadRequestError } from '../bad_request_error';
|
||||
import { errors } from '@elastic/elasticsearch';
|
||||
|
||||
describe('transformError', () => {
|
||||
test('returns transformed output error from boom object with a 500 and payload of internal server error', () => {
|
||||
const boom = new Boom.Boom('some boom message');
|
||||
const transformed = transformError(boom);
|
||||
expect(transformed).toEqual({
|
||||
message: 'An internal server error occurred',
|
||||
statusCode: 500,
|
||||
});
|
||||
});
|
||||
|
||||
test('returns transformed output if it is some non boom object that has a statusCode', () => {
|
||||
const error: Error & { statusCode?: number } = {
|
||||
statusCode: 403,
|
||||
name: 'some name',
|
||||
message: 'some message',
|
||||
};
|
||||
const transformed = transformError(error);
|
||||
expect(transformed).toEqual({
|
||||
message: 'some message',
|
||||
statusCode: 403,
|
||||
});
|
||||
});
|
||||
|
||||
test('returns a transformed message with the message set and statusCode', () => {
|
||||
const error: Error & { statusCode?: number } = {
|
||||
statusCode: 403,
|
||||
name: 'some name',
|
||||
message: 'some message',
|
||||
};
|
||||
const transformed = transformError(error);
|
||||
expect(transformed).toEqual({
|
||||
message: 'some message',
|
||||
statusCode: 403,
|
||||
});
|
||||
});
|
||||
|
||||
test('transforms best it can if it is some non boom object but it does not have a status Code.', () => {
|
||||
const error: Error = {
|
||||
name: 'some name',
|
||||
message: 'some message',
|
||||
};
|
||||
const transformed = transformError(error);
|
||||
expect(transformed).toEqual({
|
||||
message: 'some message',
|
||||
statusCode: 500,
|
||||
});
|
||||
});
|
||||
|
||||
test('it detects a BadRequestError and returns a status code of 400 from that particular error type', () => {
|
||||
const error: BadRequestError = new BadRequestError('I have a type error');
|
||||
const transformed = transformError(error);
|
||||
expect(transformed).toEqual({
|
||||
message: 'I have a type error',
|
||||
statusCode: 400,
|
||||
});
|
||||
});
|
||||
|
||||
test('it detects a BadRequestError and returns a Boom status of 400', () => {
|
||||
const error: BadRequestError = new BadRequestError('I have a type error');
|
||||
const transformed = transformError(error);
|
||||
expect(transformed).toEqual({
|
||||
message: 'I have a type error',
|
||||
statusCode: 400,
|
||||
});
|
||||
});
|
||||
|
||||
it('transforms a ResponseError returned by the elasticsearch client', () => {
|
||||
const error: errors.ResponseError = {
|
||||
name: 'ResponseError',
|
||||
message: 'illegal_argument_exception',
|
||||
headers: {},
|
||||
body: {
|
||||
error: {
|
||||
type: 'illegal_argument_exception',
|
||||
reason: 'detailed explanation',
|
||||
},
|
||||
},
|
||||
meta: ({} as unknown) as errors.ResponseError['meta'],
|
||||
statusCode: 400,
|
||||
};
|
||||
const transformed = transformError(error);
|
||||
|
||||
expect(transformed).toEqual({
|
||||
message: 'illegal_argument_exception: detailed explanation',
|
||||
statusCode: 400,
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 Boom from '@hapi/boom';
|
||||
import { errors } from '@elastic/elasticsearch';
|
||||
import { BadRequestError } from '../bad_request_error';
|
||||
|
||||
export interface OutputError {
|
||||
message: string;
|
||||
statusCode: number;
|
||||
}
|
||||
|
||||
export const transformError = (err: Error & Partial<errors.ResponseError>): OutputError => {
|
||||
if (Boom.isBoom(err)) {
|
||||
return {
|
||||
message: err.output.payload.message,
|
||||
statusCode: err.output.statusCode,
|
||||
};
|
||||
} else {
|
||||
if (err.statusCode != null) {
|
||||
if (err.body != null && err.body.error != null) {
|
||||
return {
|
||||
statusCode: err.statusCode,
|
||||
message: `${err.body.error.type}: ${err.body.error.reason}`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
statusCode: err.statusCode,
|
||||
message: err.message,
|
||||
};
|
||||
}
|
||||
} else if (err instanceof BadRequestError) {
|
||||
// allows us to throw request validation errors in the absence of Boom
|
||||
return {
|
||||
message: err.message,
|
||||
statusCode: 400,
|
||||
};
|
||||
} else {
|
||||
// natively return the err and allow the regular framework
|
||||
// to deal with the error when it is a non Boom
|
||||
return {
|
||||
message: err.message != null ? err.message : '(unknown error message)',
|
||||
statusCode: 500,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
19
packages/kbn-securitysolution-es-utils/tsconfig.json
Normal file
19
packages/kbn-securitysolution-es-utils/tsconfig.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"incremental": true,
|
||||
"outDir": "target",
|
||||
"rootDir": "src",
|
||||
"sourceMap": true,
|
||||
"sourceRoot": "../../../../packages/kbn-securitysolution-es-utils/src",
|
||||
"types": [
|
||||
"jest",
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
|
@ -35,7 +35,7 @@ SRC_DEPS = [
|
|||
TYPES_DEPS = [
|
||||
"@npm//@types/jest",
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/uuid"
|
||||
"@npm//@types/uuid"
|
||||
]
|
||||
|
||||
DEPS = SRC_DEPS + TYPES_DEPS
|
||||
|
@ -83,4 +83,4 @@ filegroup(
|
|||
":npm_module",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
)
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { ENDPOINT_LIST_ID, ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
CreateEndpointListItemSchemaDecoded,
|
||||
createEndpointListItemSchema,
|
||||
exceptionListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getExceptionListClient } from './utils/get_exception_list_client';
|
||||
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';
|
||||
import { validateExceptionListSize } from './validate';
|
||||
|
||||
export const createEndpointListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { ENDPOINT_LIST_URL } from '../../common/constants';
|
||||
import { buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { createEndpointListSchema } from '../../common/schemas';
|
||||
|
||||
import { buildSiemResponse } from './utils';
|
||||
import { getExceptionListClient } from './utils/get_exception_list_client';
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,16 +6,17 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
CreateExceptionListItemSchemaDecoded,
|
||||
createExceptionListItemSchema,
|
||||
exceptionListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
import { getExceptionListClient } from './utils/get_exception_list_client';
|
||||
import { endpointDisallowedFields } from './endpoint_disallowed_fields';
|
||||
import { validateEndpointExceptionItemEntries, validateExceptionListSize } from './validate';
|
||||
|
|
|
@ -6,16 +6,17 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
CreateExceptionListSchemaDecoded,
|
||||
createExceptionListSchema,
|
||||
exceptionListSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
import { getExceptionListClient } from './utils/get_exception_list_client';
|
||||
|
||||
export const createExceptionListRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { LIST_INDEX } from '../../common/constants';
|
||||
import { acknowledgeSchema } from '../../common/schemas';
|
||||
|
||||
import { buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const createListIndexRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { createListItemSchema, listItemSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const createListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { CreateListSchemaDecoded, createListSchema, listSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const createListRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,17 +6,22 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
DeleteEndpointListItemSchemaDecoded,
|
||||
deleteEndpointListItemSchema,
|
||||
exceptionListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getErrorMessageExceptionListItem, getExceptionListClient } from './utils';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
getErrorMessageExceptionListItem,
|
||||
getExceptionListClient,
|
||||
} from './utils';
|
||||
|
||||
export const deleteEndpointListItemRoute = (router: ListsPluginRouter): void => {
|
||||
router.delete(
|
||||
|
|
|
@ -6,17 +6,22 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
DeleteExceptionListItemSchemaDecoded,
|
||||
deleteExceptionListItemSchema,
|
||||
exceptionListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getErrorMessageExceptionListItem, getExceptionListClient } from './utils';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
getErrorMessageExceptionListItem,
|
||||
getExceptionListClient,
|
||||
} from './utils';
|
||||
|
||||
export const deleteExceptionListItemRoute = (router: ListsPluginRouter): void => {
|
||||
router.delete(
|
||||
|
|
|
@ -6,17 +6,22 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
DeleteExceptionListSchemaDecoded,
|
||||
deleteExceptionListSchema,
|
||||
exceptionListSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getErrorMessageExceptionList, getExceptionListClient } from './utils';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
getErrorMessageExceptionList,
|
||||
getExceptionListClient,
|
||||
} from './utils';
|
||||
|
||||
export const deleteExceptionListRoute = (router: ListsPluginRouter): void => {
|
||||
router.delete(
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_INDEX } from '../../common/constants';
|
||||
import { buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { acknowledgeSchema } from '../../common/schemas';
|
||||
|
||||
import { buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { deleteListItemSchema, listItemArraySchema, listItemSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const deleteListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
*/
|
||||
|
||||
import { EntriesArray, validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
ExceptionListItemSchema,
|
||||
FoundExceptionListSchema,
|
||||
|
@ -21,6 +21,8 @@ import { getSavedObjectType } from '../services/exception_lists/utils';
|
|||
import { ExceptionListClient } from '../services/exception_lists/exception_list_client';
|
||||
import { escapeQuotes } from '../services/utils/escape_query';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getExceptionListClient, getListClient } from '.';
|
||||
|
||||
export const deleteListRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { exportExceptionListQuerySchema } from '../../common/schemas';
|
||||
|
||||
import { getExceptionListClient } from './utils';
|
||||
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';
|
||||
|
||||
export const exportExceptionListRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -7,11 +7,14 @@
|
|||
|
||||
import { Stream } from 'stream';
|
||||
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { exportListItemQuerySchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const exportListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { ENDPOINT_LIST_ID, ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
FindEndpointListItemSchemaDecoded,
|
||||
findEndpointListItemSchema,
|
||||
foundExceptionListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getExceptionListClient } from './utils';
|
||||
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';
|
||||
|
||||
export const findEndpointListItemRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
FindExceptionListItemSchemaDecoded,
|
||||
findExceptionListItemSchema,
|
||||
foundExceptionListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getExceptionListClient } from './utils';
|
||||
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';
|
||||
|
||||
export const findExceptionListItemRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
FindExceptionListSchemaDecoded,
|
||||
findExceptionListSchema,
|
||||
foundExceptionListSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getExceptionListClient } from './utils';
|
||||
import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils';
|
||||
|
||||
export const findExceptionListRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
FindListItemSchemaDecoded,
|
||||
findListItemSchema,
|
||||
|
@ -17,7 +17,7 @@ import {
|
|||
} from '../../common/schemas';
|
||||
import { decodeCursor } from '../services/utils';
|
||||
|
||||
import { getListClient } from './utils';
|
||||
import { buildRouteValidation, buildSiemResponse, getListClient } from './utils';
|
||||
|
||||
export const findListItemRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { findListSchema, foundListSchema } from '../../common/schemas';
|
||||
import { decodeCursor } from '../services/utils';
|
||||
|
||||
import { getListClient } from './utils';
|
||||
import { buildRouteValidation, buildSiemResponse, getListClient } from './utils';
|
||||
|
||||
export const findListRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { importListItemQuerySchema, listSchema } from '../../common/schemas';
|
||||
import { ConfigType } from '../config';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
import { createStreamFromBuffer } from './utils/create_stream_from_buffer';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { listItemSchema, patchListItemSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const patchListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { listSchema, patchListSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const patchListRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,17 +6,22 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
ReadEndpointListItemSchemaDecoded,
|
||||
exceptionListItemSchema,
|
||||
readEndpointListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getErrorMessageExceptionListItem, getExceptionListClient } from './utils';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
getErrorMessageExceptionListItem,
|
||||
getExceptionListClient,
|
||||
} from './utils';
|
||||
|
||||
export const readEndpointListItemRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -6,17 +6,22 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
ReadExceptionListItemSchemaDecoded,
|
||||
exceptionListItemSchema,
|
||||
readExceptionListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getErrorMessageExceptionListItem, getExceptionListClient } from './utils';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
getErrorMessageExceptionListItem,
|
||||
getExceptionListClient,
|
||||
} from './utils';
|
||||
|
||||
export const readExceptionListItemRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -6,17 +6,22 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
ReadExceptionListSchemaDecoded,
|
||||
exceptionListSchema,
|
||||
readExceptionListSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getErrorMessageExceptionList, getExceptionListClient } from './utils';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
getErrorMessageExceptionList,
|
||||
getExceptionListClient,
|
||||
} from './utils';
|
||||
|
||||
export const readExceptionListRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_INDEX } from '../../common/constants';
|
||||
import { buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { listItemIndexExistSchema } from '../../common/schemas';
|
||||
|
||||
import { buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const readListIndexRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { listItemArraySchema, listItemSchema, readListItemSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const readListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { listSchema, readListSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const readListRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { readPrivileges, transformError } from '@kbn/securitysolution-es-utils';
|
||||
import { merge } from 'lodash/fp';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_PRIVILEGES_URL } from '../../common/constants';
|
||||
import { buildSiemResponse, readPrivileges, transformError } from '../siem_server_deps';
|
||||
|
||||
import { getListClient } from './utils';
|
||||
import { buildSiemResponse, getListClient } from './utils';
|
||||
|
||||
export const readPrivilegesRoute = (router: ListsPluginRouter): void => {
|
||||
router.get(
|
||||
|
|
|
@ -6,16 +6,18 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { ENDPOINT_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
UpdateEndpointListItemSchemaDecoded,
|
||||
exceptionListItemSchema,
|
||||
updateEndpointListItemSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getExceptionListClient } from '.';
|
||||
|
||||
export const updateEndpointListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
UpdateExceptionListItemSchemaDecoded,
|
||||
exceptionListItemSchema,
|
||||
|
@ -17,6 +17,8 @@ import {
|
|||
} from '../../common/schemas';
|
||||
import { updateExceptionListItemValidate } from '../../common/schemas/request/update_exception_list_item_validation';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getExceptionListClient } from '.';
|
||||
|
||||
export const updateExceptionListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,17 +6,22 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { EXCEPTION_LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import {
|
||||
UpdateExceptionListSchemaDecoded,
|
||||
exceptionListSchema,
|
||||
updateExceptionListSchema,
|
||||
} from '../../common/schemas';
|
||||
|
||||
import { getErrorMessageExceptionList, getExceptionListClient } from './utils';
|
||||
import {
|
||||
buildRouteValidation,
|
||||
buildSiemResponse,
|
||||
getErrorMessageExceptionList,
|
||||
getExceptionListClient,
|
||||
} from './utils';
|
||||
|
||||
export const updateExceptionListRoute = (router: ListsPluginRouter): void => {
|
||||
router.put(
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_ITEM_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { listItemSchema, updateListItemSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const updateListItemRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
*/
|
||||
|
||||
import { validate } from '@kbn/securitysolution-io-ts-utils';
|
||||
import { transformError } from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import type { ListsPluginRouter } from '../types';
|
||||
import { LIST_URL } from '../../common/constants';
|
||||
import { buildRouteValidation, buildSiemResponse, transformError } from '../siem_server_deps';
|
||||
import { listSchema, updateListSchema } from '../../common/schemas';
|
||||
|
||||
import { buildRouteValidation, buildSiemResponse } from './utils';
|
||||
|
||||
import { getListClient } from '.';
|
||||
|
||||
export const updateListRoute = (router: ListsPluginRouter): void => {
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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 { CustomHttpResponseOptions, KibanaResponseFactory } from 'src/core/server';
|
||||
|
||||
/**
|
||||
* Copied from x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts
|
||||
* We cannot put this in kbn package just yet as the types from 'src/core/server' aren't a kbn package yet and this would pull in a lot of copied things.
|
||||
* TODO: Once more types are moved into kbn package we can move this into a kbn package.
|
||||
*/
|
||||
const statusToErrorMessage = (
|
||||
statusCode: number
|
||||
):
|
||||
| 'Bad Request'
|
||||
| 'Unauthorized'
|
||||
| 'Forbidden'
|
||||
| 'Not Found'
|
||||
| 'Conflict'
|
||||
| 'Internal Error'
|
||||
| '(unknown error)' => {
|
||||
switch (statusCode) {
|
||||
case 400:
|
||||
return 'Bad Request';
|
||||
case 401:
|
||||
return 'Unauthorized';
|
||||
case 403:
|
||||
return 'Forbidden';
|
||||
case 404:
|
||||
return 'Not Found';
|
||||
case 409:
|
||||
return 'Conflict';
|
||||
case 500:
|
||||
return 'Internal Error';
|
||||
default:
|
||||
return '(unknown error)';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Copied from x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts
|
||||
* We cannot put this in kbn package just yet as the types from 'src/core/server' aren't a kbn package yet and this would pull in a lot of copied things.
|
||||
* TODO: Once more types are moved into kbn package we can move this into a kbn package.
|
||||
*/
|
||||
export class SiemResponseFactory {
|
||||
constructor(private response: KibanaResponseFactory) {}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
error<T>({ statusCode, body, headers }: CustomHttpResponseOptions<T>) {
|
||||
// KibanaResponse is not exported so we cannot use a return type here and that is why the linter is turned off above
|
||||
const contentType: CustomHttpResponseOptions<T>['headers'] = {
|
||||
'content-type': 'application/json',
|
||||
};
|
||||
const defaultedHeaders: CustomHttpResponseOptions<T>['headers'] = {
|
||||
...contentType,
|
||||
...(headers ?? {}),
|
||||
};
|
||||
|
||||
return this.response.custom({
|
||||
body: Buffer.from(
|
||||
JSON.stringify({
|
||||
message: body ?? statusToErrorMessage(statusCode),
|
||||
status_code: statusCode,
|
||||
})
|
||||
),
|
||||
headers: defaultedHeaders,
|
||||
statusCode,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts
|
||||
* We cannot put this in kbn package just yet as the types from 'src/core/server' aren't a kbn package yet and this would pull in a lot of copied things.
|
||||
* TODO: Once more types are moved into kbn package we can move this into a kbn package.
|
||||
*/
|
||||
export const buildSiemResponse = (response: KibanaResponseFactory): SiemResponseFactory =>
|
||||
new SiemResponseFactory(response);
|
|
@ -9,3 +9,5 @@ export * from './get_error_message_exception_list_item';
|
|||
export * from './get_error_message_exception_list';
|
||||
export * from './get_list_client';
|
||||
export * from './get_exception_list_client';
|
||||
export * from './route_validation';
|
||||
export * from './build_siem_response';
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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 * as rt from 'io-ts';
|
||||
import { RouteValidationResultFactory } from 'src/core/server';
|
||||
|
||||
import { buildRouteValidation } from './route_validation';
|
||||
|
||||
/**
|
||||
* Copied from x-pack/plugins/security_solution/server/utils/build_validation/route_validation.test.ts
|
||||
* TODO: Once we can move this into a kbn package because the types such as RouteValidationResultFactory are in packages, then please do.
|
||||
*/
|
||||
describe('Route Validation with ', () => {
|
||||
describe('buildRouteValidation', () => {
|
||||
const schema = rt.exact(
|
||||
rt.type({
|
||||
ids: rt.array(rt.string),
|
||||
})
|
||||
);
|
||||
type Schema = rt.TypeOf<typeof schema>;
|
||||
|
||||
/**
|
||||
* If your schema is using exact all the way down then the validation will
|
||||
* catch any additional keys that should not be present within the validation
|
||||
* when the route_validation uses the exact check.
|
||||
*/
|
||||
const deepSchema = rt.exact(
|
||||
rt.type({
|
||||
topLevel: rt.exact(
|
||||
rt.type({
|
||||
secondLevel: rt.exact(
|
||||
rt.type({
|
||||
thirdLevel: rt.string,
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
})
|
||||
);
|
||||
type DeepSchema = rt.TypeOf<typeof deepSchema>;
|
||||
|
||||
const validationResult: RouteValidationResultFactory = {
|
||||
badRequest: jest.fn().mockImplementation((e) => e),
|
||||
ok: jest.fn().mockImplementation((validatedInput) => validatedInput),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('return validation error', () => {
|
||||
const input: Omit<Schema, 'ids'> & { id: string } = { id: 'someId' };
|
||||
const result = buildRouteValidation(schema)(input, validationResult);
|
||||
|
||||
expect(result).toEqual('Invalid value "undefined" supplied to "ids"');
|
||||
});
|
||||
|
||||
test('return validated input', () => {
|
||||
const input: Schema = { ids: ['someId'] };
|
||||
const result = buildRouteValidation(schema)(input, validationResult);
|
||||
|
||||
expect(result).toEqual(input);
|
||||
});
|
||||
|
||||
test('returns validation error if given extra keys on input for an array', () => {
|
||||
const input: Schema & { somethingExtra: string } = {
|
||||
ids: ['someId'],
|
||||
somethingExtra: 'hello',
|
||||
};
|
||||
const result = buildRouteValidation(schema)(input, validationResult);
|
||||
expect(result).toEqual('invalid keys "somethingExtra"');
|
||||
});
|
||||
|
||||
test('return validation input for a deep 3rd level object', () => {
|
||||
const input: DeepSchema = { topLevel: { secondLevel: { thirdLevel: 'hello' } } };
|
||||
const result = buildRouteValidation(deepSchema)(input, validationResult);
|
||||
expect(result).toEqual(input);
|
||||
});
|
||||
|
||||
test('return validation error for a deep 3rd level object that has an extra key value of "somethingElse"', () => {
|
||||
const input: DeepSchema & {
|
||||
topLevel: { secondLevel: { thirdLevel: string; somethingElse: string } };
|
||||
} = {
|
||||
topLevel: { secondLevel: { somethingElse: 'extraKey', thirdLevel: 'hello' } },
|
||||
};
|
||||
const result = buildRouteValidation(deepSchema)(input, validationResult);
|
||||
expect(result).toEqual('invalid keys "somethingElse"');
|
||||
});
|
||||
});
|
||||
});
|
56
x-pack/plugins/lists/server/routes/utils/route_validation.ts
Normal file
56
x-pack/plugins/lists/server/routes/utils/route_validation.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* 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 { fold } from 'fp-ts/lib/Either';
|
||||
import { pipe } from 'fp-ts/lib/pipeable';
|
||||
import * as rt from 'io-ts';
|
||||
import { exactCheck, formatErrors } from '@kbn/securitysolution-io-ts-utils';
|
||||
|
||||
import {
|
||||
RouteValidationError,
|
||||
RouteValidationFunction,
|
||||
RouteValidationResultFactory,
|
||||
} from '../../../../../../src/core/server';
|
||||
|
||||
type RequestValidationResult<T> =
|
||||
| {
|
||||
value: T;
|
||||
error?: undefined;
|
||||
}
|
||||
| {
|
||||
value?: undefined;
|
||||
error: RouteValidationError;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copied from x-pack/plugins/security_solution/server/utils/build_validation/route_validation.ts
|
||||
* This really should be in @kbn/securitysolution-io-ts-utils rather than copied yet again, however, this has types
|
||||
* from a lot of places such as RouteValidationResultFactory from core/server which in turn can pull in @kbn/schema
|
||||
* which cannot work on the front end and @kbn/securitysolution-io-ts-utils works on both front and backend.
|
||||
*
|
||||
* TODO: Figure out a way to move this function into a package rather than copying it/forking it within plugins
|
||||
*/
|
||||
export const buildRouteValidation = <T extends rt.Mixed, A = rt.TypeOf<T>>(
|
||||
schema: T
|
||||
): RouteValidationFunction<A> => (
|
||||
inputValue: unknown,
|
||||
validationResult: RouteValidationResultFactory
|
||||
): RequestValidationResult<A> =>
|
||||
pipe(
|
||||
schema.decode(inputValue),
|
||||
(decoded) => exactCheck(inputValue, decoded),
|
||||
fold<rt.Errors, A, RequestValidationResult<A>>(
|
||||
(errors: rt.Errors) => validationResult.badRequest(formatErrors(errors).join()),
|
||||
(validatedInput: A) => validationResult.ok(validatedInput)
|
||||
)
|
||||
);
|
|
@ -6,6 +6,17 @@
|
|||
*/
|
||||
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
import {
|
||||
createBootstrapIndex,
|
||||
deleteAllIndex,
|
||||
deletePolicy,
|
||||
deleteTemplate,
|
||||
getIndexExists,
|
||||
getPolicyExists,
|
||||
getTemplateExists,
|
||||
setPolicy,
|
||||
setTemplate,
|
||||
} from '@kbn/securitysolution-es-utils';
|
||||
|
||||
import {
|
||||
FoundListItemSchema,
|
||||
|
@ -40,17 +51,6 @@ import {
|
|||
searchListItemByValues,
|
||||
updateListItem,
|
||||
} from '../../services/items';
|
||||
import {
|
||||
createBootstrapIndex,
|
||||
deleteAllIndex,
|
||||
deletePolicy,
|
||||
deleteTemplate,
|
||||
getIndexExists,
|
||||
getPolicyExists,
|
||||
getTemplateExists,
|
||||
setPolicy,
|
||||
setTemplate,
|
||||
} from '../../siem_server_deps';
|
||||
import listsItemsPolicy from '../items/list_item_policy.json';
|
||||
|
||||
import listPolicy from './list_policy.json';
|
||||
|
|
|
@ -1,24 +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 {
|
||||
transformError,
|
||||
deleteTemplate,
|
||||
deletePolicy,
|
||||
deleteAllIndex,
|
||||
setPolicy,
|
||||
setTemplate,
|
||||
buildSiemResponse,
|
||||
getTemplateExists,
|
||||
getPolicyExists,
|
||||
createBootstrapIndex,
|
||||
getIndexExists,
|
||||
buildRouteValidation,
|
||||
readPrivileges,
|
||||
} from '../../security_solution/server';
|
||||
|
||||
export { formatErrors } from '../../security_solution/common';
|
|
@ -48,17 +48,4 @@ export const config: PluginConfigDescriptor<ConfigType> = {
|
|||
export { ConfigType, Plugin, PluginSetup, PluginStart };
|
||||
export { AppClient };
|
||||
|
||||
// Exports to be shared with plugins such as x-pack/lists plugin
|
||||
export { deleteTemplate } from './lib/detection_engine/index/delete_template';
|
||||
export { deletePolicy } from './lib/detection_engine/index/delete_policy';
|
||||
export { deleteAllIndex } from './lib/detection_engine/index/delete_all_index';
|
||||
export { setPolicy } from './lib/detection_engine/index/set_policy';
|
||||
export { setTemplate } from './lib/detection_engine/index/set_template';
|
||||
export { getTemplateExists } from './lib/detection_engine/index/get_template_exists';
|
||||
export { getPolicyExists } from './lib/detection_engine/index/get_policy_exists';
|
||||
export { createBootstrapIndex } from './lib/detection_engine/index/create_bootstrap_index';
|
||||
export { getIndexExists } from './lib/detection_engine/index/get_index_exists';
|
||||
export { buildRouteValidation } from './utils/build_validation/route_validation';
|
||||
export { transformError, buildSiemResponse } from './lib/detection_engine/routes/utils';
|
||||
export { readPrivileges } from './lib/detection_engine/privileges/read_privileges';
|
||||
export type { AppRequestContext } from './types';
|
||||
|
|
|
@ -10,6 +10,10 @@ import { ElasticsearchClient } from 'kibana/server';
|
|||
// See the reference(s) below on explanations about why -000001 was chosen and
|
||||
// why the is_write_index is true as well as the bootstrapping step which is needed.
|
||||
// Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/applying-policy-to-template.html
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const createBootstrapIndex = async (
|
||||
esClient: ElasticsearchClient,
|
||||
index: string
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const deleteAllIndex = async (
|
||||
esClient: ElasticsearchClient,
|
||||
pattern: string,
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const deletePolicy = async (
|
||||
esClient: ElasticsearchClient,
|
||||
policy: string
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
*/
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const deleteTemplate = async (
|
||||
esClient: ElasticsearchClient,
|
||||
name: string
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const getIndexExists = async (
|
||||
esClient: ElasticsearchClient,
|
||||
index: string
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const getPolicyExists = async (
|
||||
esClient: ElasticsearchClient,
|
||||
policy: string
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const getTemplateExists = async (
|
||||
esClient: ElasticsearchClient,
|
||||
template: string
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const setPolicy = async (
|
||||
esClient: ElasticsearchClient,
|
||||
policy: string,
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
import { ElasticsearchClient } from 'kibana/server';
|
||||
|
||||
/**
|
||||
* @deprecated Use the one from kbn-securitysolution-es-utils
|
||||
*/
|
||||
export const setTemplate = async (
|
||||
esClient: ElasticsearchClient,
|
||||
name: string,
|
||||
|
|
|
@ -25,6 +25,9 @@ export interface OutputError {
|
|||
statusCode: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use kbn-securitysolution-es-utils version
|
||||
*/
|
||||
export const transformError = (err: Error & Partial<errors.ResponseError>): OutputError => {
|
||||
if (Boom.isBoom(err)) {
|
||||
return {
|
||||
|
|
|
@ -2702,6 +2702,10 @@
|
|||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/securitysolution-es-utils@link:bazel-bin/packages/kbn-securitysolution-es-utils/npm_module":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/securitysolution-io-ts-utils@link:bazel-bin/packages/kbn-securitysolution-io-ts-utils/npm_module":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue