From 77e6a9e6e4545d81517c8e55f2edb9a5f6ba17ae Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Thu, 20 Jun 2024 19:48:20 +0200 Subject: [PATCH 01/15] create kbn- securitysolution-exceptions-common package --- .github/CODEOWNERS | 1 + package.json | 1 + .../README.md | 20 +++++++++++++++++++ .../kibana.jsonc | 5 +++++ .../package.json | 10 ++++++++++ .../tsconfig.json | 14 +++++++++++++ tsconfig.base.json | 2 ++ yarn.lock | 4 ++++ 8 files changed, 57 insertions(+) create mode 100644 packages/kbn-securitysolution-exceptions-common/README.md create mode 100644 packages/kbn-securitysolution-exceptions-common/kibana.jsonc create mode 100644 packages/kbn-securitysolution-exceptions-common/package.json create mode 100644 packages/kbn-securitysolution-exceptions-common/tsconfig.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 07bede6066d76..c275ffce3e224 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -752,6 +752,7 @@ x-pack/packages/security-solution/data_table @elastic/security-threat-hunting-in packages/kbn-securitysolution-ecs @elastic/security-threat-hunting-explore packages/kbn-securitysolution-es-utils @elastic/security-detection-engine packages/kbn-securitysolution-exception-list-components @elastic/security-detection-engine +packages/kbn-securitysolution-exceptions-common @elastic/security-detection-engine packages/kbn-securitysolution-hook-utils @elastic/security-detection-engine packages/kbn-securitysolution-io-ts-alerting-types @elastic/security-detection-engine packages/kbn-securitysolution-io-ts-list-types @elastic/security-detection-engine diff --git a/package.json b/package.json index fc3c1183a2fa5..edd9325f9d6a3 100644 --- a/package.json +++ b/package.json @@ -762,6 +762,7 @@ "@kbn/securitysolution-ecs": "link:packages/kbn-securitysolution-ecs", "@kbn/securitysolution-es-utils": "link:packages/kbn-securitysolution-es-utils", "@kbn/securitysolution-exception-list-components": "link:packages/kbn-securitysolution-exception-list-components", + "@kbn/securitysolution-exceptions-common": "link:packages/kbn-securitysolution-exceptions-common", "@kbn/securitysolution-hook-utils": "link:packages/kbn-securitysolution-hook-utils", "@kbn/securitysolution-io-ts-alerting-types": "link:packages/kbn-securitysolution-io-ts-alerting-types", "@kbn/securitysolution-io-ts-list-types": "link:packages/kbn-securitysolution-io-ts-list-types", diff --git a/packages/kbn-securitysolution-exceptions-common/README.md b/packages/kbn-securitysolution-exceptions-common/README.md new file mode 100644 index 0000000000000..f29d982dbe665 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/README.md @@ -0,0 +1,20 @@ +# Security Solution Exceptions common package + +The package contains common files for the Exceptions feature. + +`common` in the name highlights that this package is intended to combine any common entities related to Exceptions in this package. E.g. the other `kbn-securitysolution-exception-list-*` packages +content should be moved here while `kbn-securitysolution-io-ts-list-types` package should be +gone eventually. + +## API folder + +`api` folder contains OpenAPI schemas for Security Solution Exceptions feature. There are automatically generated Zod schemas and TS types for each schemas located in corresponding +`*.gen.ts` files. + +**Please add any Exceptions feature related schemas to this package.** + +TS types and/or Zod schemas can be imported in a plugin or another package like + +```ts +import { CreateExceptionRequestBody } from '@kbn/securitysolution-exceptions-common/api'; +``` diff --git a/packages/kbn-securitysolution-exceptions-common/kibana.jsonc b/packages/kbn-securitysolution-exceptions-common/kibana.jsonc new file mode 100644 index 0000000000000..ff47bd8f5a585 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-common", + "id": "@kbn/securitysolution-exceptions-common", + "owner": "@elastic/security-detection-engine" +} diff --git a/packages/kbn-securitysolution-exceptions-common/package.json b/packages/kbn-securitysolution-exceptions-common/package.json new file mode 100644 index 0000000000000..083d081d501fa --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/package.json @@ -0,0 +1,10 @@ +{ + "description": "Security Solution Exceptions common package", + "license": "SSPL-1.0 OR Elastic License 2.0", + "name": "@kbn/securitysolution-exceptions-common", + "private": true, + "version": "1.0.0", + "scripts": { + "openapi:generate": "node scripts/openapi_generate" + } +} diff --git a/packages/kbn-securitysolution-exceptions-common/tsconfig.json b/packages/kbn-securitysolution-exceptions-common/tsconfig.json new file mode 100644 index 0000000000000..96bc2e233e73e --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "outDir": "target/types", + "types": ["jest", "node"] + }, + "exclude": ["target/**/*"], + "extends": "../../tsconfig.base.json", + "include": ["**/*.ts"], + "kbn_references": [ + "@kbn/openapi-common", + "@kbn/zod-helpers", + "@kbn/securitysolution-lists-common" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 6d4637281115e..bbd855176c35a 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1498,6 +1498,8 @@ "@kbn/securitysolution-es-utils/*": ["packages/kbn-securitysolution-es-utils/*"], "@kbn/securitysolution-exception-list-components": ["packages/kbn-securitysolution-exception-list-components"], "@kbn/securitysolution-exception-list-components/*": ["packages/kbn-securitysolution-exception-list-components/*"], + "@kbn/securitysolution-exceptions-common": ["packages/kbn-securitysolution-exceptions-common"], + "@kbn/securitysolution-exceptions-common/*": ["packages/kbn-securitysolution-exceptions-common/*"], "@kbn/securitysolution-hook-utils": ["packages/kbn-securitysolution-hook-utils"], "@kbn/securitysolution-hook-utils/*": ["packages/kbn-securitysolution-hook-utils/*"], "@kbn/securitysolution-io-ts-alerting-types": ["packages/kbn-securitysolution-io-ts-alerting-types"], diff --git a/yarn.lock b/yarn.lock index ff3df6c7684db..2e94eb47a02e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6208,6 +6208,10 @@ version "0.0.0" uid "" +"@kbn/securitysolution-exceptions-common@link:packages/kbn-securitysolution-exceptions-common": + version "0.0.0" + uid "" + "@kbn/securitysolution-hook-utils@link:packages/kbn-securitysolution-hook-utils": version "0.0.0" uid "" From b3a24cb1138135af1fd0b20a04db2d38fa982436 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Thu, 20 Jun 2024 19:51:54 +0200 Subject: [PATCH 02/15] add Exceptions API OpenAPI specs --- .../create_exception_list.gen.ts | 48 +++ .../create_exception_list.schema.yaml | 85 +++++ .../create_exception_list_item.gen.ts | 83 +++++ .../create_exception_list_item.schema.yaml | 150 +++++++++ .../create_rule_exceptions.gen.ts | 81 +++++ .../create_rule_exceptions.schema.yaml | 106 +++++++ .../create_shared_exceptions_list.gen.ts | 38 +++ .../create_shared_exceptions_list.schema.yaml | 66 ++++ .../delete_exception_list.gen.ts | 42 +++ .../delete_exception_list.schema.yaml | 71 +++++ .../delete_exception_list_item.gen.ts | 46 +++ .../delete_exception_list_item.schema.yaml | 71 +++++ .../duplicate_exception_list.gen.ts | 43 +++ .../duplicate_exception_list.schema.yaml | 71 +++++ .../export_exception_list.gen.ts | 42 +++ .../export_exception_list.schema.yaml | 80 +++++ .../find_exception_list.gen.ts | 70 ++++ .../find_exception_list.schema.yaml | 121 +++++++ .../find_exception_list_item.gen.ts | 78 +++++ .../find_exception_list_item.schema.yaml | 141 +++++++++ .../import_exceptions.gen.ts | 70 ++++ .../import_exceptions.schema.yaml | 141 +++++++++ .../api/index.ts | 26 ++ .../api/model/exception_list_common.gen.ts | 187 +++++++++++ .../model/exception_list_common.schema.yaml | 298 ++++++++++++++++++ .../model/exception_list_item_entry.gen.ts | 99 ++++++ .../exception_list_item_entry.schema.yaml | 147 +++++++++ .../read_exception_list.gen.ts | 42 +++ .../read_exception_list.schema.yaml | 71 +++++ .../read_exception_list_item.gen.ts | 44 +++ .../read_exception_list_item.schema.yaml | 73 +++++ .../summary_exception_list.gen.ts | 54 ++++ .../summary_exception_list.schema.yaml | 89 ++++++ .../update_exception_list.gen.ts | 51 +++ .../update_exception_list.schema.yaml | 88 ++++++ .../update_exception_list_item.gen.ts | 101 ++++++ .../update_exception_list_item.schema.yaml | 160 ++++++++++ .../scripts/openapi_generate.js | 22 ++ 38 files changed, 3296 insertions(+) create mode 100644 packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/index.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen.ts create mode 100644 packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.schema.yaml create mode 100644 packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen.ts new file mode 100644 index 0000000000000..3509b26499fc9 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen.ts @@ -0,0 +1,48 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create exception list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListHumanId, + ExceptionListName, + ExceptionListDescription, + ExceptionListType, + ExceptionNamespaceType, + ExceptionListOsTypeArray, + ExceptionListTags, + ExceptionListMeta, + ExceptionListVersion, + ExceptionList, +} from '../model/exception_list_common.gen'; + +export type CreateExceptionListRequestBody = z.infer; +export const CreateExceptionListRequestBody = z.object({ + list_id: ExceptionListHumanId.optional(), + name: ExceptionListName, + description: ExceptionListDescription, + type: ExceptionListType, + namespace_type: ExceptionNamespaceType.optional().default('single'), + os_types: ExceptionListOsTypeArray.optional(), + tags: ExceptionListTags.optional().default([]), + meta: ExceptionListMeta.optional(), + version: ExceptionListVersion.optional().default(1), +}); +export type CreateExceptionListRequestBodyInput = z.input; + +export type CreateExceptionListResponse = z.infer; +export const CreateExceptionListResponse = ExceptionList; diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.schema.yaml new file mode 100644 index 0000000000000..823ead2991330 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.schema.yaml @@ -0,0 +1,85 @@ +openapi: 3.0.0 +info: + title: Create exception list API endpoint + version: '2023-10-31' +paths: + /api/exception_lists: + post: + x-labels: [serverless, ess] + operationId: CreateExceptionList + x-codegen-enabled: true + summary: Creates an exception list + tags: + - Exceptions API + requestBody: + description: Exception list's properties + required: true + content: + application/json: + schema: + type: object + properties: + list_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + name: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListName' + description: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListDescription' + type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListType' + namespace_type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: 'single' + os_types: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListOsTypeArray' + tags: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListTags' + default: [] + meta: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListMeta' + version: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListVersion' + default: 1 + required: + - name + - description + - type + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 409: + description: Exception list already exists response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen.ts new file mode 100644 index 0000000000000..55c39811147d6 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen.ts @@ -0,0 +1,83 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create exception list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { + ExceptionListItemHumanId, + ExceptionListHumanId, + ExceptionListItemType, + ExceptionListItemName, + ExceptionListItemDescription, + ExceptionNamespaceType, + ExceptionListItemOsTypeArray, + ExceptionListItemTags, + ExceptionListItemMeta, + ExceptionListItem, +} from '../model/exception_list_common.gen'; +import { ExceptionListItemEntryArray } from '../model/exception_list_item_entry.gen'; + +export type CreateExceptionListItemComment = z.infer; +export const CreateExceptionListItemComment = z.object({ + comment: NonEmptyString, +}); + +export type CreateExceptionListItemCommentArray = z.infer< + typeof CreateExceptionListItemCommentArray +>; +export const CreateExceptionListItemCommentArray = z.array(CreateExceptionListItemComment); + +export type CreateExceptionListItemRequestBodyCamelCase = z.infer< + typeof CreateExceptionListItemRequestBodyCamelCase +>; +export const CreateExceptionListItemRequestBodyCamelCase = z.object({ + itemId: ExceptionListItemHumanId.optional(), + listId: ExceptionListHumanId, + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray, + namespaceType: ExceptionNamespaceType.optional().default('single'), + osTypes: ExceptionListItemOsTypeArray.optional().default([]), + tags: ExceptionListItemTags.optional().default([]), + meta: ExceptionListItemMeta.optional(), + expireTime: z.string().datetime().optional(), + comments: CreateExceptionListItemCommentArray.optional().default([]), +}); + +export type CreateExceptionListItemRequestBody = z.infer; +export const CreateExceptionListItemRequestBody = z.object({ + item_id: ExceptionListItemHumanId.optional(), + list_id: ExceptionListHumanId, + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray, + namespace_type: ExceptionNamespaceType.optional().default('single'), + os_types: ExceptionListItemOsTypeArray.optional().default([]), + tags: ExceptionListItemTags.optional().default([]), + meta: ExceptionListItemMeta.optional(), + expire_time: z.string().datetime().optional(), + comments: CreateExceptionListItemCommentArray.optional().default([]), +}); +export type CreateExceptionListItemRequestBodyInput = z.input< + typeof CreateExceptionListItemRequestBody +>; + +export type CreateExceptionListItemResponse = z.infer; +export const CreateExceptionListItemResponse = ExceptionListItem; diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.schema.yaml new file mode 100644 index 0000000000000..1832d3f7ddbbf --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.schema.yaml @@ -0,0 +1,150 @@ +openapi: 3.0.0 +info: + title: Create exception list item API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/items: + post: + x-labels: [serverless, ess] + operationId: CreateExceptionListItem + x-codegen-enabled: true + summary: Creates an exception list item + tags: + - Exceptions API + requestBody: + description: Exception list item's properties + required: true + content: + application/json: + schema: + type: object + properties: + item_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + list_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' + name: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' + description: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' + entries: + $ref: '../model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + namespace_type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: 'single' + os_types: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' + default: [] + tags: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' + default: [] + meta: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' + expire_time: + type: string + format: date-time + comments: + $ref: '#/components/schemas/CreateExceptionListItemCommentArray' + default: [] + required: + - list_id + - type + - name + - description + - entries + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 409: + description: Exception list item already exists response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + x-codegen-enabled: true + schemas: + CreateExceptionListItemComment: + type: object + properties: + comment: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + required: + - comment + + CreateExceptionListItemCommentArray: + type: array + items: + $ref: '#/components/schemas/CreateExceptionListItemComment' + + CreateExceptionListItemRequestBodyCamelCase: + type: object + properties: + itemId: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + listId: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' + name: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' + description: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' + entries: + $ref: '../model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + namespaceType: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: 'single' + osTypes: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' + default: [] + tags: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' + default: [] + meta: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' + expireTime: + type: string + format: date-time + comments: + $ref: '#/components/schemas/CreateExceptionListItemCommentArray' + default: [] + required: + - listId + - type + - name + - description + - entries diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen.ts new file mode 100644 index 0000000000000..7c86af9eefd7c --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen.ts @@ -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 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create rule exception list items API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { UUID } from '@kbn/openapi-common/schemas/primitives.gen'; +import { + ExceptionListItem, + ExceptionListItemHumanId, + ExceptionListHumanId, + ExceptionListItemType, + ExceptionListItemName, + ExceptionListItemDescription, + ExceptionNamespaceType, + ExceptionListItemOsTypeArray, + ExceptionListItemTags, + ExceptionListItemMeta, + ExceptionListItemCommentArray, +} from '../model/exception_list_common.gen'; +import { ExceptionListItemEntryArray } from '../model/exception_list_item_entry.gen'; + +export type RuleId = z.infer; +export const RuleId = UUID; + +export type CreateRuleExceptionListItemProps = z.infer; +export const CreateRuleExceptionListItemProps = z.object({ + item_id: ExceptionListItemHumanId.optional(), + list_id: ExceptionListHumanId.optional(), + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray, + namespace_type: ExceptionNamespaceType.optional().default('single'), + os_types: ExceptionListItemOsTypeArray.optional(), + tags: ExceptionListItemTags.optional(), + meta: ExceptionListItemMeta.optional(), + expire_time: z.string().datetime().optional(), + comments: ExceptionListItemCommentArray.optional(), +}); + +export type CreateRuleExceptionListItemsRequestParams = z.infer< + typeof CreateRuleExceptionListItemsRequestParams +>; +export const CreateRuleExceptionListItemsRequestParams = z.object({ + /** + * Detection rule's identifier + */ + id: RuleId, +}); +export type CreateRuleExceptionListItemsRequestParamsInput = z.input< + typeof CreateRuleExceptionListItemsRequestParams +>; + +export type CreateRuleExceptionListItemsRequestBody = z.infer< + typeof CreateRuleExceptionListItemsRequestBody +>; +export const CreateRuleExceptionListItemsRequestBody = z.object({ + items: z.array(CreateRuleExceptionListItemProps), +}); +export type CreateRuleExceptionListItemsRequestBodyInput = z.input< + typeof CreateRuleExceptionListItemsRequestBody +>; + +export type CreateRuleExceptionListItemsResponse = z.infer< + typeof CreateRuleExceptionListItemsResponse +>; +export const CreateRuleExceptionListItemsResponse = ExceptionListItem; diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.schema.yaml new file mode 100644 index 0000000000000..e8f6656bc655f --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.schema.yaml @@ -0,0 +1,106 @@ +openapi: 3.0.0 +info: + title: Create rule exception list items API endpoint + version: '2023-10-31' +paths: + /api/detection_engine/rules/{id}/exceptions: + post: + x-labels: [serverless, ess] + operationId: CreateRuleExceptionListItems + x-codegen-enabled: true + summary: Creates rule exception list items + tags: + - Exceptions API + parameters: + - name: id + in: path + required: true + description: Detection rule's identifier + schema: + $ref: '#/components/schemas/RuleId' + requestBody: + description: Rule exception list items + required: true + content: + application/json: + schema: + type: object + properties: + items: + type: array + items: + $ref: '#/components/schemas/CreateRuleExceptionListItemProps' + required: [items] + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + schemas: + RuleId: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/UUID' + + CreateRuleExceptionListItemProps: + type: object + properties: + item_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + list_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' + name: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' + description: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' + entries: + $ref: '../model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + namespace_type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: 'single' + os_types: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' + tags: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' + meta: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' + expire_time: + type: string + format: date-time + comments: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemCommentArray' + required: + - type + - name + - description + - entries diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen.ts new file mode 100644 index 0000000000000..e050c211e1513 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen.ts @@ -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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create shared exception list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListName, + ExceptionListDescription, + ExceptionList, +} from '../model/exception_list_common.gen'; + +export type CreateSharedExceptionListRequestBody = z.infer< + typeof CreateSharedExceptionListRequestBody +>; +export const CreateSharedExceptionListRequestBody = z.object({ + name: ExceptionListName, + description: ExceptionListDescription, +}); +export type CreateSharedExceptionListRequestBodyInput = z.input< + typeof CreateSharedExceptionListRequestBody +>; + +export type CreateSharedExceptionListResponse = z.infer; +export const CreateSharedExceptionListResponse = ExceptionList; diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.schema.yaml new file mode 100644 index 0000000000000..0a072e855f0d2 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.schema.yaml @@ -0,0 +1,66 @@ +openapi: 3.0.0 +info: + title: Create shared exception list API endpoint + version: '2023-10-31' +paths: + /api/exceptions/shared: + post: + x-labels: [serverless, ess] + operationId: CreateSharedExceptionList + x-codegen-enabled: true + summary: Creates a shared exception list + tags: + - Exceptions API + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + name: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListName' + description: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListDescription' + required: + - name + - description + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 409: + description: Exception list already exists response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen.ts new file mode 100644 index 0000000000000..0797b7e3b9b01 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen.ts @@ -0,0 +1,42 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Delete exception list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListId, + ExceptionListHumanId, + ExceptionNamespaceType, + ExceptionList, +} from '../model/exception_list_common.gen'; + +export type DeleteExceptionListRequestQuery = z.infer; +export const DeleteExceptionListRequestQuery = z.object({ + /** + * Either `id` or `list_id` must be specified + */ + id: ExceptionListId.optional(), + /** + * Either `id` or `list_id` must be specified + */ + list_id: ExceptionListHumanId.optional(), + namespace_type: ExceptionNamespaceType.optional().default('single'), +}); +export type DeleteExceptionListRequestQueryInput = z.input; + +export type DeleteExceptionListResponse = z.infer; +export const DeleteExceptionListResponse = ExceptionList; diff --git a/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.schema.yaml new file mode 100644 index 0000000000000..f8522ddf2de68 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.schema.yaml @@ -0,0 +1,71 @@ +openapi: 3.0.0 +info: + title: Delete exception list API endpoint + version: '2023-10-31' +paths: + /api/exception_lists: + delete: + x-labels: [serverless, ess] + operationId: DeleteExceptionList + x-codegen-enabled: true + summary: Deletes an exception list + tags: + - Exceptions API + parameters: + - name: id + in: query + required: false + description: Either `id` or `list_id` must be specified + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListId' + - name: list_id + in: query + required: false + description: Either `id` or `list_id` must be specified + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + - name: namespace_type + in: query + required: false + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: single + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen.ts new file mode 100644 index 0000000000000..d709fd5597b80 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen.ts @@ -0,0 +1,46 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Delete exception list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListItemId, + ExceptionListItemHumanId, + ExceptionNamespaceType, + ExceptionListItem, +} from '../model/exception_list_common.gen'; + +export type DeleteExceptionListItemRequestQuery = z.infer< + typeof DeleteExceptionListItemRequestQuery +>; +export const DeleteExceptionListItemRequestQuery = z.object({ + /** + * Either `id` or `item_id` must be specified + */ + id: ExceptionListItemId.optional(), + /** + * Either `id` or `item_id` must be specified + */ + item_id: ExceptionListItemHumanId.optional(), + namespace_type: ExceptionNamespaceType.optional().default('single'), +}); +export type DeleteExceptionListItemRequestQueryInput = z.input< + typeof DeleteExceptionListItemRequestQuery +>; + +export type DeleteExceptionListItemResponse = z.infer; +export const DeleteExceptionListItemResponse = ExceptionListItem; diff --git a/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.schema.yaml new file mode 100644 index 0000000000000..a34339e4f4c31 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.schema.yaml @@ -0,0 +1,71 @@ +openapi: 3.0.0 +info: + title: Delete exception list item API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/items: + delete: + x-labels: [serverless, ess] + operationId: DeleteExceptionListItem + x-codegen-enabled: true + summary: Deletes an exception list item + tags: + - Exceptions API + parameters: + - name: id + in: query + required: false + description: Either `id` or `item_id` must be specified + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemId' + - name: item_id + in: query + required: false + description: Either `id` or `item_id` must be specified + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + - name: namespace_type + in: query + required: false + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: single + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list item not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen.ts new file mode 100644 index 0000000000000..e5c3f19b28aa2 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen.ts @@ -0,0 +1,43 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Duplicate exception list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListHumanId, + ExceptionNamespaceType, + ExceptionList, +} from '../model/exception_list_common.gen'; + +export type DuplicateExceptionListRequestQuery = z.infer; +export const DuplicateExceptionListRequestQuery = z.object({ + /** + * Exception list's human identifier + */ + list_id: ExceptionListHumanId, + namespace_type: ExceptionNamespaceType, + /** + * Determines whether to include expired exceptions in the exported list + */ + include_expired_exceptions: z.enum(['true', 'false']).default('true'), +}); +export type DuplicateExceptionListRequestQueryInput = z.input< + typeof DuplicateExceptionListRequestQuery +>; + +export type DuplicateExceptionListResponse = z.infer; +export const DuplicateExceptionListResponse = ExceptionList; diff --git a/packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.schema.yaml new file mode 100644 index 0000000000000..2620d882087a7 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.schema.yaml @@ -0,0 +1,71 @@ +openapi: 3.0.0 +info: + title: Duplicate exception list API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/_duplicate: + post: + operationId: DuplicateExceptionList + x-codegen-enabled: true + summary: Duplicates an exception list + tags: + - Exceptions API + parameters: + - name: list_id + in: query + required: true + description: Exception list's human identifier + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + - name: namespace_type + in: query + required: true + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + - name: include_expired_exceptions + in: query + required: true + description: Determines whether to include expired exceptions in the exported list + schema: + type: string + enum: ['true', 'false'] + default: 'true' + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 405: + description: Exception list to duplicate not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen.ts new file mode 100644 index 0000000000000..bb62df2e43226 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen.ts @@ -0,0 +1,42 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Export exception list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListId, + ExceptionListHumanId, + ExceptionNamespaceType, +} from '../model/exception_list_common.gen'; + +export type ExportExceptionListRequestQuery = z.infer; +export const ExportExceptionListRequestQuery = z.object({ + /** + * Exception list's identifier + */ + id: ExceptionListId, + /** + * Exception list's human identifier + */ + list_id: ExceptionListHumanId, + namespace_type: ExceptionNamespaceType, + /** + * Determines whether to include expired exceptions in the exported list + */ + include_expired_exceptions: z.enum(['true', 'false']).default('true'), +}); +export type ExportExceptionListRequestQueryInput = z.input; diff --git a/packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.schema.yaml new file mode 100644 index 0000000000000..9d24b654625c2 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.schema.yaml @@ -0,0 +1,80 @@ +openapi: 3.0.0 +info: + title: Export exception list API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/_export: + post: + operationId: ExportExceptionList + x-codegen-enabled: true + summary: Exports an exception list + description: Exports an exception list and its associated items to an .ndjson file + tags: + - Exceptions API + parameters: + - name: id + in: query + required: true + description: Exception list's identifier + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListId' + - name: list_id + in: query + required: true + description: Exception list's human identifier + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + - name: namespace_type + in: query + required: true + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + - name: include_expired_exceptions + in: query + required: true + description: Determines whether to include expired exceptions in the exported list + schema: + type: string + enum: ['true', 'false'] + default: 'true' + responses: + 200: + description: Successful response + content: + application/ndjson: + schema: + type: string + format: binary + description: A `.ndjson` file containing specified exception list and its items + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts new file mode 100644 index 0000000000000..8fa1f31b835b6 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts @@ -0,0 +1,70 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Find exception lists API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; +import { ArrayFromString } from '@kbn/zod-helpers'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { ExceptionNamespaceType, ExceptionList } from '../model/exception_list_common.gen'; + +export type FindExceptionListsFilter = z.infer; +export const FindExceptionListsFilter = NonEmptyString; + +export type FindExceptionListsRequestQuery = z.infer; +export const FindExceptionListsRequestQuery = z.object({ + /** + * Filters the returned results according to the value of the specified field. + +Uses the `so type.field name:field` value syntax, where `so type` can be: + +- `exception-list`: Specify a space-aware exception list. +- `exception-list-agnostic`: Specify an exception list that is shared across spaces. + + */ + filter: FindExceptionListsFilter.optional(), + /** + * Determines whether the returned containers are Kibana associated with a Kibana space +or available in all spaces (`agnostic` or `single`) + + */ + namespace_type: ArrayFromString(ExceptionNamespaceType).optional().default([]), + /** + * The page number to return + */ + page: z.coerce.number().int().min(0).optional(), + /** + * The number of exception lists to return per page + */ + per_page: z.coerce.number().int().min(0).optional(), + /** + * Determines which field is used to sort the results + */ + sort_field: NonEmptyString.optional(), + /** + * Determines the sort order, which can be `desc` or `asc` + */ + sort_order: z.enum(['desc', 'asc']).optional(), +}); +export type FindExceptionListsRequestQueryInput = z.input; + +export type FindExceptionListsResponse = z.infer; +export const FindExceptionListsResponse = z.object({ + data: z.array(ExceptionList), + page: z.number().int().min(0), + per_page: z.number().int().min(0), + total: z.number().int().min(0), +}); diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml new file mode 100644 index 0000000000000..11e4faad12642 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml @@ -0,0 +1,121 @@ +openapi: 3.0.0 +info: + title: Find exception lists API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/items/_find: + get: + x-labels: [serverless, ess] + operationId: FindExceptionLists + x-codegen-enabled: true + summary: Finds exception lists + tags: + - Exceptions API + parameters: + - name: filter + in: query + required: false + description: | + Filters the returned results according to the value of the specified field. + + Uses the `so type.field name:field` value syntax, where `so type` can be: + + - `exception-list`: Specify a space-aware exception list. + - `exception-list-agnostic`: Specify an exception list that is shared across spaces. + schema: + $ref: '#/components/schemas/FindExceptionListsFilter' + - name: namespace_type + in: query + required: false + description: | + Determines whether the returned containers are Kibana associated with a Kibana space + or available in all spaces (`agnostic` or `single`) + schema: + type: array + items: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: [] + - name: page + in: query + required: false + description: The page number to return + schema: + type: integer + minimum: 0 + - name: per_page + in: query + required: false + description: The number of exception lists to return per page + schema: + type: integer + minimum: 0 + - name: sort_field + in: query + required: false + description: Determines which field is used to sort the results + schema: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + - name: sort_order + in: query + required: false + description: Determines the sort order, which can be `desc` or `asc` + schema: + type: string + enum: [desc, asc] + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + data: + type: array + items: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' + page: + type: integer + minimum: 0 + per_page: + type: integer + minimum: 0 + total: + type: integer + minimum: 0 + required: + - data + - page + - per_page + - total + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + schemas: + FindExceptionListsFilter: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts new file mode 100644 index 0000000000000..125bb23311385 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts @@ -0,0 +1,78 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Find exception list items API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; +import { ArrayFromString } from '@kbn/zod-helpers'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { + ExceptionListHumanId, + ExceptionNamespaceType, + ExceptionListItem, +} from '../model/exception_list_common.gen'; + +export type FindExceptionListItemsFilter = z.infer; +export const FindExceptionListItemsFilter = NonEmptyString; + +export type FindExceptionListItemsRequestQuery = z.infer; +export const FindExceptionListItemsRequestQuery = z.object({ + /** + * List's ide + */ + list_id: ArrayFromString(ExceptionListHumanId), + /** + * Filters the returned results according to the value of the specified field, +using the `:` syntax. + + */ + filter: ArrayFromString(FindExceptionListItemsFilter).optional().default([]), + /** + * Determines whether the returned containers are Kibana associated with a Kibana space +or available in all spaces (`agnostic` or `single`) + + */ + namespace_type: ArrayFromString(ExceptionNamespaceType).optional().default(['single']), + search: z.string().optional(), + /** + * The page number to return + */ + page: z.coerce.number().int().min(0).optional(), + /** + * The number of exception list items to return per page + */ + per_page: z.coerce.number().int().min(0).optional(), + /** + * Determines which field is used to sort the results + */ + sort_field: NonEmptyString.optional(), + /** + * Determines the sort order, which can be `desc` or `asc` + */ + sort_order: z.enum(['desc', 'asc']).optional(), +}); +export type FindExceptionListItemsRequestQueryInput = z.input< + typeof FindExceptionListItemsRequestQuery +>; + +export type FindExceptionListItemsResponse = z.infer; +export const FindExceptionListItemsResponse = z.object({ + data: z.array(ExceptionListItem), + page: z.number().int().min(0), + per_page: z.number().int().min(0), + total: z.number().int().min(0), + pit: z.string().optional(), +}); diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml new file mode 100644 index 0000000000000..c5b65bd27389c --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml @@ -0,0 +1,141 @@ +openapi: 3.0.0 +info: + title: Find exception list items API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/items/_find: + get: + x-labels: [serverless, ess] + operationId: FindExceptionListItems + x-codegen-enabled: true + summary: Finds exception list items + tags: + - Exceptions API + parameters: + - name: list_id + in: query + required: true + description: List's ide + schema: + type: array + items: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + - name: filter + in: query + required: false + description: | + Filters the returned results according to the value of the specified field, + using the `:` syntax. + schema: + type: array + items: + $ref: '#/components/schemas/FindExceptionListItemsFilter' + default: [] + - name: namespace_type + in: query + required: false + description: | + Determines whether the returned containers are Kibana associated with a Kibana space + or available in all spaces (`agnostic` or `single`) + schema: + type: array + items: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: [single] + - name: search + in: query + required: false + schema: + type: string + - name: page + in: query + required: false + description: The page number to return + schema: + type: integer + minimum: 0 + - name: per_page + in: query + required: false + description: The number of exception list items to return per page + schema: + type: integer + minimum: 0 + - name: sort_field + in: query + required: false + description: Determines which field is used to sort the results + schema: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + - name: sort_order + in: query + required: false + description: Determines the sort order, which can be `desc` or `asc` + schema: + type: string + enum: [desc, asc] + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + data: + type: array + items: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' + page: + type: integer + minimum: 0 + per_page: + type: integer + minimum: 0 + total: + type: integer + minimum: 0 + pit: + type: string + required: + - data + - page + - per_page + - total + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + schemas: + FindExceptionListItemsFilter: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' diff --git a/packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen.ts new file mode 100644 index 0000000000000..ec25576cc9dfe --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen.ts @@ -0,0 +1,70 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Import exception list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; +import { BooleanFromString } from '@kbn/zod-helpers'; + +import { + ExceptionListId, + ExceptionListHumanId, + ExceptionListItemHumanId, +} from '../model/exception_list_common.gen'; + +export type ExceptionListsImportBulkError = z.infer; +export const ExceptionListsImportBulkError = z.object({ + error: z.object({ + status_code: z.number().int(), + message: z.string(), + }), + id: ExceptionListId.optional(), + list_id: ExceptionListHumanId.optional(), + item_id: ExceptionListItemHumanId.optional(), +}); + +export type ExceptionListsImportBulkErrorArray = z.infer; +export const ExceptionListsImportBulkErrorArray = z.array(ExceptionListsImportBulkError); + +export type ImportExceptionListRequestQuery = z.infer; +export const ImportExceptionListRequestQuery = z.object({ + /** + * Determines whether existing exception lists with the same `list_id` are overwritten. +If any exception items have the same `item_id`, those are also overwritten. + + */ + overwrite: BooleanFromString.optional().default(false), + overwrite_exceptions: BooleanFromString.optional().default(false), + overwrite_action_connectors: BooleanFromString.optional().default(false), + /** + * Determines whether the list being imported will have a new `list_id` generated. +Additional `item_id`'s are generated for each exception item. Both the exception +list and its items are overwritten. + + */ + as_new_list: BooleanFromString.optional().default(false), +}); +export type ImportExceptionListRequestQueryInput = z.input; + +export type ImportExceptionListResponse = z.infer; +export const ImportExceptionListResponse = z.object({ + errors: ExceptionListsImportBulkErrorArray, + success: z.boolean(), + success_count: z.number().int().min(0), + success_exception_lists: z.boolean(), + success_count_exception_lists: z.number().int().min(0), + success_exception_list_items: z.boolean(), + success_count_exception_list_items: z.number().int().min(0), +}); diff --git a/packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.schema.yaml new file mode 100644 index 0000000000000..c1a04e7a38b8c --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.schema.yaml @@ -0,0 +1,141 @@ +openapi: 3.0.0 +info: + title: Import exception list API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/_import: + post: + operationId: ImportExceptionList + x-codegen-enabled: true + summary: Imports an exception list + description: Imports an exception list and associated items + tags: + - Exceptions API + requestBody: + required: true + content: + multipart/form-data: + schema: + type: object + properties: + file: + type: string + format: binary + description: A `.ndjson` file containing the exception list + parameters: + - name: overwrite + in: query + required: false + description: | + Determines whether existing exception lists with the same `list_id` are overwritten. + If any exception items have the same `item_id`, those are also overwritten. + schema: + type: boolean + default: false + - name: overwrite_exceptions + in: query + required: false + schema: + type: boolean + default: false + - name: overwrite_action_connectors + in: query + required: false + schema: + type: boolean + default: false + - name: as_new_list + in: query + required: false + description: | + Determines whether the list being imported will have a new `list_id` generated. + Additional `item_id`'s are generated for each exception item. Both the exception + list and its items are overwritten. + schema: + type: boolean + default: false + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + errors: + $ref: '#/components/schemas/ExceptionListsImportBulkErrorArray' + success: + type: boolean + success_count: + type: integer + minimum: 0 + success_exception_lists: + type: boolean + success_count_exception_lists: + type: integer + minimum: 0 + success_exception_list_items: + type: boolean + success_count_exception_list_items: + type: integer + minimum: 0 + required: + - errors + - success + - success_count + - success_exception_lists + - success_count_exception_lists + - success_exception_list_items + - success_count_exception_list_items + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + schemas: + ExceptionListsImportBulkError: + type: object + properties: + error: + type: object + properties: + status_code: + type: integer + message: + type: string + required: [status_code, message] + id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListId' + list_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + item_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + required: [error] + + ExceptionListsImportBulkErrorArray: + type: array + items: + $ref: '#/components/schemas/ExceptionListsImportBulkError' diff --git a/packages/kbn-securitysolution-exceptions-common/api/index.ts b/packages/kbn-securitysolution-exceptions-common/api/index.ts new file mode 100644 index 0000000000000..b9e866aeb6a12 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/index.ts @@ -0,0 +1,26 @@ +/* + * 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 './model/exception_list_common.gen'; +export * from './model/exception_list_item_entry.gen'; +export * from './create_exception_list_item/create_exception_list_item.gen'; +export * from './create_rule_exceptions/create_rule_exceptions.gen'; +export * from './create_shared_exceptions_list/create_shared_exceptions_list.gen'; +export * from './create_exception_list/create_exception_list.gen'; +export * from './delete_exception_list_item/delete_exception_list_item.gen'; +export * from './delete_exception_list/delete_exception_list.gen'; +export * from './duplicate_exception_list/duplicate_exception_list.gen'; +export * from './export_exception_list/export_exception_list.gen'; +export * from './find_exception_list_item/find_exception_list_item.gen'; +export * from './find_exception_list/find_exception_list.gen'; +export * from './import_exceptions/import_exceptions.gen'; +export * from './read_exception_list_item/read_exception_list_item.gen'; +export * from './read_exception_list/read_exception_list.gen'; +export * from './summary_exception_list/summary_exception_list.gen'; +export * from './update_exception_list_item/update_exception_list_item.gen'; +export * from './update_exception_list/update_exception_list.gen'; diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts new file mode 100644 index 0000000000000..67cd12c225071 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts @@ -0,0 +1,187 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Common Exception List Attributes + * version: not applicable + */ + +import { z } from 'zod'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { ExceptionListItemEntryArray } from './exception_list_item_entry.gen'; + +export type ExceptionListId = z.infer; +export const ExceptionListId = NonEmptyString; + +/** + * Human readable string identifier, e.g. `trusted-linux-processes` + */ +export type ExceptionListHumanId = z.infer; +export const ExceptionListHumanId = NonEmptyString; + +export type ExceptionListType = z.infer; +export const ExceptionListType = z.enum([ + 'detection', + 'rule_default', + 'endpoint', + 'endpoint_trusted_apps', + 'endpoint_events', + 'endpoint_host_isolation_exceptions', + 'endpoint_blocklists', +]); +export type ExceptionListTypeEnum = typeof ExceptionListType.enum; +export const ExceptionListTypeEnum = ExceptionListType.enum; + +export type ExceptionListName = z.infer; +export const ExceptionListName = NonEmptyString; + +export type ExceptionListDescription = z.infer; +export const ExceptionListDescription = NonEmptyString; + +export type ExceptionListMeta = z.infer; +export const ExceptionListMeta = z.object({}).catchall(z.unknown()); + +/** + * Determines whether the exception container is available in all Kibana spaces or just the space +in which it is created, where: + +- `single`: Only available in the Kibana space in which it is created. +- `agnostic`: Available in all Kibana spaces. + + */ +export type ExceptionNamespaceType = z.infer; +export const ExceptionNamespaceType = z.enum(['agnostic', 'single']); +export type ExceptionNamespaceTypeEnum = typeof ExceptionNamespaceType.enum; +export const ExceptionNamespaceTypeEnum = ExceptionNamespaceType.enum; + +export type ExceptionListTags = z.infer; +export const ExceptionListTags = z.array(NonEmptyString); + +export type ExceptionListOsType = z.infer; +export const ExceptionListOsType = z.enum(['linux', 'macos', 'windows']); +export type ExceptionListOsTypeEnum = typeof ExceptionListOsType.enum; +export const ExceptionListOsTypeEnum = ExceptionListOsType.enum; + +export type ExceptionListOsTypeArray = z.infer; +export const ExceptionListOsTypeArray = z.array(ExceptionListOsType); + +export type ExceptionListVersion = z.infer; +export const ExceptionListVersion = z.number().int().min(1); + +export type ExceptionList = z.infer; +export const ExceptionList = z.object({ + id: ExceptionListId, + list_id: ExceptionListHumanId.optional(), + type: ExceptionListType, + name: ExceptionListName, + description: ExceptionListDescription, + immutable: z.boolean(), + namespace_type: ExceptionNamespaceType.optional(), + os_types: ExceptionListOsTypeArray.optional(), + tags: ExceptionListTags.optional(), + meta: ExceptionListMeta.optional(), + version: ExceptionListVersion, + _version: z.string().optional(), + tie_breaker_id: z.string(), + created_at: z.string().datetime(), + created_by: z.string(), + updated_at: z.string().datetime(), + updated_by: z.string(), +}); + +export type ExceptionListItemId = z.infer; +export const ExceptionListItemId = NonEmptyString; + +export type ExceptionListItemHumanId = z.infer; +export const ExceptionListItemHumanId = NonEmptyString; + +export type ExceptionListItemType = z.infer; +export const ExceptionListItemType = z.literal('simple'); + +export type ExceptionListItemName = z.infer; +export const ExceptionListItemName = NonEmptyString; + +export type ExceptionListItemDescription = z.infer; +export const ExceptionListItemDescription = NonEmptyString; + +export type ExceptionListItemMeta = z.infer; +export const ExceptionListItemMeta = z.object({}).catchall(z.unknown()); + +export type ExceptionListItemTags = z.infer; +export const ExceptionListItemTags = z.array(NonEmptyString); + +export type ExceptionListItemOsType = z.infer; +export const ExceptionListItemOsType = z.enum(['linux', 'macos', 'windows']); +export type ExceptionListItemOsTypeEnum = typeof ExceptionListItemOsType.enum; +export const ExceptionListItemOsTypeEnum = ExceptionListItemOsType.enum; + +export type ExceptionListItemOsTypeArray = z.infer; +export const ExceptionListItemOsTypeArray = z.array(ExceptionListOsType); + +export type ExceptionListItemComment = z.infer; +export const ExceptionListItemComment = z.object({ + id: NonEmptyString, + comment: NonEmptyString, + created_at: z.string().datetime(), + created_by: NonEmptyString, + updated_at: z.string().datetime().optional(), + updated_by: NonEmptyString.optional(), +}); + +export type ExceptionListItemCommentArray = z.infer; +export const ExceptionListItemCommentArray = z.array(ExceptionListItemComment); + +export type ExceptionListItem = z.infer; +export const ExceptionListItem = z.object({ + id: ExceptionListItemId, + item_id: ExceptionListItemHumanId, + list_id: ExceptionListHumanId, + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray, + namespace_type: ExceptionNamespaceType.optional(), + os_types: ExceptionListItemOsTypeArray.optional(), + tags: ExceptionListItemTags.optional(), + meta: ExceptionListItemMeta.optional(), + expire_time: z.string().datetime().optional(), + comments: ExceptionListItemCommentArray, + _version: z.string().optional(), + tie_breaker_id: z.string(), + created_at: z.string().datetime(), + created_by: z.string(), + updated_at: z.string().datetime(), + updated_by: z.string(), +}); + +export type ExceptionListSO = z.infer; +export const ExceptionListSO = z.object({ + item_id: ExceptionListItemHumanId.optional(), + list_id: ExceptionListHumanId, + list_type: z.enum(['item', 'list']), + immutable: z.boolean().optional(), + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray.optional(), + os_types: ExceptionListItemOsTypeArray.optional(), + tags: ExceptionListItemTags.optional(), + meta: ExceptionListItemMeta.optional(), + expire_time: z.string().datetime().optional(), + comments: ExceptionListItemCommentArray.optional(), + version: NonEmptyString.optional(), + tie_breaker_id: z.string(), + created_at: z.string().datetime(), + created_by: z.string(), + updated_by: z.string(), +}); diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml new file mode 100644 index 0000000000000..1828742e50322 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml @@ -0,0 +1,298 @@ +openapi: 3.0.0 +info: + title: Common Exception List Attributes + version: 'not applicable' +paths: {} +components: + x-codegen-enabled: true + schemas: + ExceptionListId: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListHumanId: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + description: Human readable string identifier, e.g. `trusted-linux-processes` + + ExceptionListType: + type: string + enum: + - detection + - rule_default + - endpoint + - endpoint_trusted_apps + - endpoint_events + - endpoint_host_isolation_exceptions + - endpoint_blocklists + + ExceptionListName: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListDescription: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListMeta: + type: object + additionalProperties: true + + ExceptionNamespaceType: + type: string + enum: + - agnostic + - single + description: | + Determines whether the exception container is available in all Kibana spaces or just the space + in which it is created, where: + + - `single`: Only available in the Kibana space in which it is created. + - `agnostic`: Available in all Kibana spaces. + + ExceptionListTags: + type: array + items: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListOsType: + type: string + enum: + - linux + - macos + - windows + + ExceptionListOsTypeArray: + type: array + items: + $ref: '#/components/schemas/ExceptionListOsType' + + ExceptionListVersion: + type: integer + minimum: 1 + + ExceptionList: + type: object + properties: + id: + $ref: '#/components/schemas/ExceptionListId' + list_id: + $ref: '#/components/schemas/ExceptionListHumanId' + type: + $ref: '#/components/schemas/ExceptionListType' + name: + $ref: '#/components/schemas/ExceptionListName' + description: + $ref: '#/components/schemas/ExceptionListDescription' + immutable: + type: boolean + namespace_type: + $ref: '#/components/schemas/ExceptionNamespaceType' + os_types: + $ref: '#/components/schemas/ExceptionListOsTypeArray' + tags: + $ref: '#/components/schemas/ExceptionListTags' + meta: + $ref: '#/components/schemas/ExceptionListMeta' + version: + $ref: '#/components/schemas/ExceptionListVersion' + _version: + type: string + tie_breaker_id: + type: string + created_at: + type: string + format: date-time + created_by: + type: string + updated_at: + type: string + format: date-time + updated_by: + type: string + required: + - id + - type + - name + - description + - immutable + - version + - tie_breaker_id + - created_at + - created_by + - updated_at + - updated_by + + ExceptionListItemId: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListItemHumanId: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListItemType: + type: string + enum: [simple] + + ExceptionListItemName: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListItemDescription: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListItemMeta: + type: object + additionalProperties: true + + ExceptionListItemTags: + type: array + items: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ExceptionListItemOsType: + type: string + enum: + - linux + - macos + - windows + + ExceptionListItemOsTypeArray: + type: array + items: + $ref: '#/components/schemas/ExceptionListOsType' + + ExceptionListItemComment: + type: object + properties: + id: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + comment: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + created_at: + type: string + format: date-time + created_by: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + updated_at: + type: string + format: date-time + updated_by: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + required: + - id + - comment + - created_at + - created_by + + ExceptionListItemCommentArray: + type: array + items: + $ref: '#/components/schemas/ExceptionListItemComment' + + ExceptionListItem: + type: object + properties: + id: + $ref: '#/components/schemas/ExceptionListItemId' + item_id: + $ref: '#/components/schemas/ExceptionListItemHumanId' + list_id: + $ref: '#/components/schemas/ExceptionListHumanId' + type: + $ref: '#/components/schemas/ExceptionListItemType' + name: + $ref: '#/components/schemas/ExceptionListItemName' + description: + $ref: '#/components/schemas/ExceptionListItemDescription' + entries: + $ref: './exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + namespace_type: + $ref: '#/components/schemas/ExceptionNamespaceType' + os_types: + $ref: '#/components/schemas/ExceptionListItemOsTypeArray' + tags: + $ref: '#/components/schemas/ExceptionListItemTags' + meta: + $ref: '#/components/schemas/ExceptionListItemMeta' + expire_time: + type: string + format: date-time + comments: + $ref: '#/components/schemas/ExceptionListItemCommentArray' + _version: + type: string + tie_breaker_id: + type: string + created_at: + type: string + format: date-time + created_by: + type: string + updated_at: + type: string + format: date-time + updated_by: + type: string + required: + - id + - item_id + - list_id + - type + - name + - description + - entries + - comments + - tie_breaker_id + - created_at + - created_by + - updated_at + - updated_by + + ExceptionListSO: + type: object + properties: + item_id: + $ref: '#/components/schemas/ExceptionListItemHumanId' + list_id: + $ref: '#/components/schemas/ExceptionListHumanId' + list_type: + type: string + enum: [item, list] + immutable: + type: boolean + type: + $ref: '#/components/schemas/ExceptionListItemType' + name: + $ref: '#/components/schemas/ExceptionListItemName' + description: + $ref: '#/components/schemas/ExceptionListItemDescription' + entries: + $ref: './exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + os_types: + $ref: '#/components/schemas/ExceptionListItemOsTypeArray' + tags: + $ref: '#/components/schemas/ExceptionListItemTags' + meta: + $ref: '#/components/schemas/ExceptionListItemMeta' + expire_time: + type: string + format: date-time + comments: + $ref: '#/components/schemas/ExceptionListItemCommentArray' + version: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + tie_breaker_id: + type: string + created_at: + type: string + format: date-time + created_by: + type: string + updated_by: + type: string + required: + - list_id + - list_type + - type + - name + - description + - tie_breaker_id + - created_at + - created_by + - updated_at + - updated_by diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts new file mode 100644 index 0000000000000..c297388633429 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.gen.ts @@ -0,0 +1,99 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Common Exception List Item Entry Attributes + * version: not applicable + */ + +import { z } from 'zod'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { ListId, ListType } from '@kbn/securitysolution-lists-common/api/model/list_common.gen'; + +export type ExceptionListItemEntryOperator = z.infer; +export const ExceptionListItemEntryOperator = z.enum(['excluded', 'included']); +export type ExceptionListItemEntryOperatorEnum = typeof ExceptionListItemEntryOperator.enum; +export const ExceptionListItemEntryOperatorEnum = ExceptionListItemEntryOperator.enum; + +export type ExceptionListItemEntryMatch = z.infer; +export const ExceptionListItemEntryMatch = z.object({ + type: z.literal('match'), + field: NonEmptyString, + value: NonEmptyString, + operator: ExceptionListItemEntryOperator, +}); + +export type ExceptionListItemEntryMatchAny = z.infer; +export const ExceptionListItemEntryMatchAny = z.object({ + type: z.literal('match_any'), + field: NonEmptyString, + value: z.array(NonEmptyString).min(1), + operator: ExceptionListItemEntryOperator, +}); + +export type ExceptionListItemEntryList = z.infer; +export const ExceptionListItemEntryList = z.object({ + type: z.literal('list'), + field: NonEmptyString, + list: z.object({ + id: ListId, + type: ListType, + }), + operator: ExceptionListItemEntryOperator, +}); + +export type ExceptionListItemEntryExists = z.infer; +export const ExceptionListItemEntryExists = z.object({ + type: z.literal('exists'), + field: NonEmptyString, + operator: ExceptionListItemEntryOperator, +}); + +export type ExceptionListItemEntryNestedEntryItem = z.infer< + typeof ExceptionListItemEntryNestedEntryItem +>; +export const ExceptionListItemEntryNestedEntryItem = z.union([ + ExceptionListItemEntryMatch, + ExceptionListItemEntryMatchAny, + ExceptionListItemEntryExists, +]); + +export type ExceptionListItemEntryNested = z.infer; +export const ExceptionListItemEntryNested = z.object({ + type: z.literal('nested'), + field: NonEmptyString, + entries: z.array(ExceptionListItemEntryNestedEntryItem).min(1), +}); + +export type ExceptionListItemEntryMatchWildcard = z.infer< + typeof ExceptionListItemEntryMatchWildcard +>; +export const ExceptionListItemEntryMatchWildcard = z.object({ + type: z.literal('wildcard'), + field: NonEmptyString, + value: NonEmptyString, + operator: ExceptionListItemEntryOperator, +}); + +export type ExceptionListItemEntry = z.infer; +export const ExceptionListItemEntry = z.discriminatedUnion('type', [ + ExceptionListItemEntryMatch, + ExceptionListItemEntryMatchAny, + ExceptionListItemEntryList, + ExceptionListItemEntryExists, + ExceptionListItemEntryNested, + ExceptionListItemEntryMatchWildcard, +]); + +export type ExceptionListItemEntryArray = z.infer; +export const ExceptionListItemEntryArray = z.array(ExceptionListItemEntry); diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.schema.yaml new file mode 100644 index 0000000000000..883a62e5bbec5 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_item_entry.schema.yaml @@ -0,0 +1,147 @@ +openapi: 3.0.0 +info: + title: Common Exception List Item Entry Attributes + version: 'not applicable' +paths: {} +components: + x-codegen-enabled: true + schemas: + ExceptionListItemEntryOperator: + type: string + enum: [excluded, included] + + ExceptionListItemEntryMatch: + type: object + properties: + type: + type: string + enum: [match] + field: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + value: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + operator: + $ref: '#/components/schemas/ExceptionListItemEntryOperator' + required: + - type + - field + - value + - operator + + ExceptionListItemEntryMatchAny: + type: object + properties: + type: + type: string + enum: [match_any] + field: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + value: + type: array + items: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + minItems: 1 + operator: + $ref: '#/components/schemas/ExceptionListItemEntryOperator' + required: + - type + - field + - value + - operator + + ExceptionListItemEntryList: + type: object + properties: + type: + type: string + enum: [list] + field: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + list: + type: object + properties: + id: + $ref: '../../../kbn-securitysolution-lists-common/api/model/list_common.schema.yaml#/components/schemas/ListId' + type: + $ref: '../../../kbn-securitysolution-lists-common/api/model/list_common.schema.yaml#/components/schemas/ListType' + required: [id, type] + operator: + $ref: '#/components/schemas/ExceptionListItemEntryOperator' + required: + - type + - field + - list + - operator + + ExceptionListItemEntryExists: + type: object + properties: + type: + type: string + enum: [exists] + field: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + operator: + $ref: '#/components/schemas/ExceptionListItemEntryOperator' + required: + - type + - field + - operator + + ExceptionListItemEntryNestedEntryItem: + oneOf: + - $ref: '#/components/schemas/ExceptionListItemEntryMatch' + - $ref: '#/components/schemas/ExceptionListItemEntryMatchAny' + - $ref: '#/components/schemas/ExceptionListItemEntryExists' + + ExceptionListItemEntryNested: + type: object + properties: + type: + type: string + enum: [nested] + field: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + entries: + type: array + items: + $ref: '#/components/schemas/ExceptionListItemEntryNestedEntryItem' + minItems: 1 + required: + - type + - field + - entries + + ExceptionListItemEntryMatchWildcard: + type: object + properties: + type: + type: string + enum: [wildcard] + field: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + value: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + operator: + $ref: '#/components/schemas/ExceptionListItemEntryOperator' + required: + - type + - field + - value + - operator + + ExceptionListItemEntry: + discriminator: + propertyName: type + anyOf: + - $ref: '#/components/schemas/ExceptionListItemEntryMatch' + - $ref: '#/components/schemas/ExceptionListItemEntryMatchAny' + - $ref: '#/components/schemas/ExceptionListItemEntryList' + - $ref: '#/components/schemas/ExceptionListItemEntryExists' + - $ref: '#/components/schemas/ExceptionListItemEntryNested' + - $ref: '#/components/schemas/ExceptionListItemEntryMatchWildcard' + + ExceptionListItemEntryArray: + type: array + items: + $ref: '#/components/schemas/ExceptionListItemEntry' diff --git a/packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen.ts new file mode 100644 index 0000000000000..3fdb7c7473f08 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen.ts @@ -0,0 +1,42 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Get exception list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListId, + ExceptionListHumanId, + ExceptionNamespaceType, + ExceptionList, +} from '../model/exception_list_common.gen'; + +export type GetExceptionListRequestQuery = z.infer; +export const GetExceptionListRequestQuery = z.object({ + /** + * Either `id` or `list_id` must be specified + */ + id: ExceptionListId.optional(), + /** + * Either `id` or `list_id` must be specified + */ + list_id: ExceptionListHumanId.optional(), + namespace_type: ExceptionNamespaceType.optional().default('single'), +}); +export type GetExceptionListRequestQueryInput = z.input; + +export type GetExceptionListResponse = z.infer; +export const GetExceptionListResponse = ExceptionList; diff --git a/packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.schema.yaml new file mode 100644 index 0000000000000..f9dcf6ea51177 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.schema.yaml @@ -0,0 +1,71 @@ +openapi: 3.0.0 +info: + title: Get exception list API endpoint + version: '2023-10-31' +paths: + /api/exception_lists: + get: + x-labels: [serverless, ess] + operationId: GetExceptionList + x-codegen-enabled: true + summary: Retrieves an exception list using its `id` or `list_id` field + tags: + - Exceptions API + parameters: + - name: id + in: query + required: false + description: Either `id` or `list_id` must be specified + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListId' + - name: list_id + in: query + required: false + description: Either `id` or `list_id` must be specified + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + - name: namespace_type + in: query + required: false + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: single + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list item not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen.ts new file mode 100644 index 0000000000000..9ba39cd55d381 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen.ts @@ -0,0 +1,44 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Get exception list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListItemId, + ExceptionListItemHumanId, + ExceptionNamespaceType, + ExceptionListItem, +} from '../model/exception_list_common.gen'; + +export type GetExceptionListItemRequestQuery = z.infer; +export const GetExceptionListItemRequestQuery = z.object({ + /** + * Either `id` or `item_id` must be specified + */ + id: ExceptionListItemId.optional(), + /** + * Either `id` or `item_id` must be specified + */ + item_id: ExceptionListItemHumanId.optional(), + namespace_type: ExceptionNamespaceType.optional().default('single'), +}); +export type GetExceptionListItemRequestQueryInput = z.input< + typeof GetExceptionListItemRequestQuery +>; + +export type GetExceptionListItemResponse = z.infer; +export const GetExceptionListItemResponse = z.array(ExceptionListItem); diff --git a/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.schema.yaml new file mode 100644 index 0000000000000..421e77d51ffc0 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.schema.yaml @@ -0,0 +1,73 @@ +openapi: 3.0.0 +info: + title: Get exception list item API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/items: + get: + x-labels: [serverless, ess] + operationId: GetExceptionListItem + x-codegen-enabled: true + summary: Gets an exception list item + tags: + - Exceptions API + parameters: + - name: id + in: query + required: false + description: Either `id` or `item_id` must be specified + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemId' + - name: item_id + in: query + required: false + description: Either `id` or `item_id` must be specified + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + - name: namespace_type + in: query + required: false + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: single + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: array + items: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list item not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen.ts new file mode 100644 index 0000000000000..139ae1822a01a --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen.ts @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Get exception list summary API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListId, + ExceptionListHumanId, + ExceptionNamespaceType, +} from '../model/exception_list_common.gen'; + +export type GetExceptionListSummaryRequestQuery = z.infer< + typeof GetExceptionListSummaryRequestQuery +>; +export const GetExceptionListSummaryRequestQuery = z.object({ + /** + * Exception list's identifier generated upon creation + */ + id: ExceptionListId, + /** + * Exception list's human readable identifier + */ + list_id: ExceptionListHumanId, + namespace_type: ExceptionNamespaceType, + /** + * Search filter clause + */ + filter: z.string(), +}); +export type GetExceptionListSummaryRequestQueryInput = z.input< + typeof GetExceptionListSummaryRequestQuery +>; + +export type GetExceptionListSummaryResponse = z.infer; +export const GetExceptionListSummaryResponse = z.object({ + windows: z.number().int().min(0).optional(), + linux: z.number().int().min(0).optional(), + macos: z.number().int().min(0).optional(), + total: z.number().int().min(0).optional(), +}); diff --git a/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.schema.yaml new file mode 100644 index 0000000000000..17f0f7ed0eee9 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.schema.yaml @@ -0,0 +1,89 @@ +openapi: 3.0.0 +info: + title: Get exception list summary API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/summary: + get: + x-labels: [serverless, ess] + operationId: GetExceptionListSummary + x-codegen-enabled: true + summary: Retrieves an exception list summary + tags: + - Exceptions API + parameters: + - name: id + in: query + required: true + description: Exception list's identifier generated upon creation + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListId' + - name: list_id + in: query + required: true + description: Exception list's human readable identifier + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + - name: namespace_type + in: query + required: true + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + - name: filter + in: query + required: true + description: Search filter clause + schema: + type: string + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + windows: + type: integer + minimum: 0 + linux: + type: integer + minimum: 0 + macos: + type: integer + minimum: 0 + total: + type: integer + minimum: 0 + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen.ts new file mode 100644 index 0000000000000..8fb0760677873 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen.ts @@ -0,0 +1,51 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Update exception list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ExceptionListId, + ExceptionListHumanId, + ExceptionListName, + ExceptionListDescription, + ExceptionListType, + ExceptionNamespaceType, + ExceptionListOsTypeArray, + ExceptionListTags, + ExceptionListMeta, + ExceptionListVersion, + ExceptionList, +} from '../model/exception_list_common.gen'; + +export type UpdateExceptionListRequestBody = z.infer; +export const UpdateExceptionListRequestBody = z.object({ + id: ExceptionListId.optional(), + list_id: ExceptionListHumanId.optional(), + name: ExceptionListName, + description: ExceptionListDescription, + type: ExceptionListType, + namespace_type: ExceptionNamespaceType.optional().default('single'), + os_types: ExceptionListOsTypeArray.optional().default([]), + tags: ExceptionListTags.optional(), + meta: ExceptionListMeta.optional(), + version: ExceptionListVersion.optional(), + _version: z.string().optional(), +}); +export type UpdateExceptionListRequestBodyInput = z.input; + +export type UpdateExceptionListResponse = z.infer; +export const UpdateExceptionListResponse = ExceptionList; diff --git a/packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.schema.yaml new file mode 100644 index 0000000000000..af31f2af4273d --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.schema.yaml @@ -0,0 +1,88 @@ +openapi: 3.0.0 +info: + title: Update exception list API endpoint + version: '2023-10-31' +paths: + /api/exception_lists: + put: + x-labels: [serverless, ess] + operationId: UpdateExceptionList + x-codegen-enabled: true + summary: Updates an exception list + tags: + - Exceptions API + requestBody: + description: Exception list's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListId' + list_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + name: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListName' + description: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListDescription' + type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListType' + namespace_type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: 'single' + os_types: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListOsTypeArray' + default: [] + tags: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListTags' + meta: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListMeta' + version: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListVersion' + _version: + type: string + required: + - name + - description + - type + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen.ts new file mode 100644 index 0000000000000..dab1d3a14c616 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen.ts @@ -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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Update exception list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { + ExceptionListItemId, + ExceptionListItemHumanId, + ExceptionListHumanId, + ExceptionListItemType, + ExceptionListItemName, + ExceptionListItemDescription, + ExceptionNamespaceType, + ExceptionListItemOsTypeArray, + ExceptionListItemTags, + ExceptionListItemMeta, + ExceptionListItem, +} from '../model/exception_list_common.gen'; +import { ExceptionListItemEntryArray } from '../model/exception_list_item_entry.gen'; + +export type UpdateExceptionListItemComment = z.infer; +export const UpdateExceptionListItemComment = z.object({ + id: NonEmptyString.optional(), + comment: NonEmptyString, +}); + +export type UpdateExceptionListItemCommentArray = z.infer< + typeof UpdateExceptionListItemCommentArray +>; +export const UpdateExceptionListItemCommentArray = z.array(UpdateExceptionListItemComment); + +export type UpdateExceptionListItemRequestBodyCamelCase = z.infer< + typeof UpdateExceptionListItemRequestBodyCamelCase +>; +export const UpdateExceptionListItemRequestBodyCamelCase = z.object({ + /** + * Either `id` or `item_id` must be specified + */ + id: ExceptionListItemId.optional(), + /** + * Either `id` or `item_id` must be specified + */ + itemId: ExceptionListItemHumanId.optional(), + listId: ExceptionListHumanId.optional(), + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray, + namespaceType: ExceptionNamespaceType.optional().default('single'), + osTypes: ExceptionListItemOsTypeArray.optional().default([]), + tags: ExceptionListItemTags.optional(), + meta: ExceptionListItemMeta.optional(), + expireTime: z.string().datetime().optional(), + comments: UpdateExceptionListItemCommentArray.optional().default([]), + _version: z.string().optional(), +}); + +export type UpdateExceptionListItemRequestBody = z.infer; +export const UpdateExceptionListItemRequestBody = z.object({ + /** + * Either `id` or `item_id` must be specified + */ + id: ExceptionListItemId.optional(), + /** + * Either `id` or `item_id` must be specified + */ + item_id: ExceptionListItemHumanId.optional(), + list_id: ExceptionListHumanId.optional(), + type: ExceptionListItemType, + name: ExceptionListItemName, + description: ExceptionListItemDescription, + entries: ExceptionListItemEntryArray, + namespace_type: ExceptionNamespaceType.optional().default('single'), + os_types: ExceptionListItemOsTypeArray.optional().default([]), + tags: ExceptionListItemTags.optional(), + meta: ExceptionListItemMeta.optional(), + expire_time: z.string().datetime().optional(), + comments: UpdateExceptionListItemCommentArray.optional().default([]), + _version: z.string().optional(), +}); +export type UpdateExceptionListItemRequestBodyInput = z.input< + typeof UpdateExceptionListItemRequestBody +>; + +export type UpdateExceptionListItemResponse = z.infer; +export const UpdateExceptionListItemResponse = ExceptionListItem; diff --git a/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.schema.yaml new file mode 100644 index 0000000000000..549bbabdf08b1 --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.schema.yaml @@ -0,0 +1,160 @@ +openapi: 3.0.0 +info: + title: Update exception list item API endpoint + version: '2023-10-31' +paths: + /api/exception_lists/items: + put: + x-labels: [serverless, ess] + operationId: UpdateExceptionListItem + x-codegen-enabled: true + summary: Updates an exception list item + tags: + - Exceptions API + requestBody: + description: Exception list item's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemId' + description: Either `id` or `item_id` must be specified + item_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + description: Either `id` or `item_id` must be specified + list_id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' + name: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' + description: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' + entries: + $ref: '../model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + namespace_type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: 'single' + os_types: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' + default: [] + tags: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' + meta: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' + expire_time: + type: string + format: date-time + comments: + $ref: '#/components/schemas/UpdateExceptionListItemCommentArray' + default: [] + _version: + type: string + required: + - type + - name + - description + - entries + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: Exception list item not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + x-codegen-enabled: true + schemas: + UpdateExceptionListItemComment: + type: object + properties: + id: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + comment: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + required: + - comment + + UpdateExceptionListItemCommentArray: + type: array + items: + $ref: '#/components/schemas/UpdateExceptionListItemComment' + + UpdateExceptionListItemRequestBodyCamelCase: + type: object + properties: + id: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemId' + description: Either `id` or `item_id` must be specified + itemId: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' + description: Either `id` or `item_id` must be specified + listId: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' + type: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' + name: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' + description: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' + entries: + $ref: '../model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' + namespaceType: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: 'single' + osTypes: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' + default: [] + tags: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' + meta: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' + expireTime: + type: string + format: date-time + comments: + $ref: '#/components/schemas/UpdateExceptionListItemCommentArray' + default: [] + _version: + type: string + required: + - type + - name + - description + - entries diff --git a/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js b/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js new file mode 100644 index 0000000000000..8d6e8b0bc5aba --- /dev/null +++ b/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js @@ -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. + */ + +require('../../../src/setup_node_env'); +const { resolve } = require('path'); +const { generate } = require('@kbn/openapi-generator'); + +const ROOT = resolve(__dirname, '..'); + +(async () => { + await generate({ + title: 'OpenAPI Exceptions API Schemas', + rootDir: ROOT, + sourceGlob: './**/*.schema.yaml', + templateName: 'zod_operation_schema', + }); +})(); From 88bf6d100db8946c60cac695fd7bd6863d1f952f Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Thu, 20 Jun 2024 22:48:15 +0200 Subject: [PATCH 03/15] apply generated Zod schemas to Exceptions API routes --- .../create_rule_exceptions.gen.ts | 23 +-- .../create_rule_exceptions.schema.yaml | 24 +++- .../find_exception_list.gen.ts | 2 +- .../find_exception_list.schema.yaml | 2 +- .../api/model/exception_list_common.gen.ts | 10 +- .../model/exception_list_common.schema.yaml | 7 +- .../read_exception_list_item.gen.ts | 2 +- .../read_exception_list_item.schema.yaml | 4 +- .../summary_exception_list.gen.ts | 8 +- .../summary_exception_list.schema.yaml | 9 +- .../src/request/index.ts | 1 - .../index.ts | 4 +- .../index.test.ts | 45 ------ .../index.ts | 42 ------ .../tsconfig.json | 16 +-- .../create_exception_list_item_route.ts | 19 --- .../delete_exception_list_route.ts | 18 --- .../delete_exception_list_item_route.ts | 18 --- .../duplicate_exception_list_route.ts | 18 --- .../export_exception_list_route.ts | 10 -- .../export_list_item_route.ts | 10 -- .../find_exception_list_route.ts | 18 --- .../find_exception_list_item_route.ts | 18 --- .../import_exceptions_route.ts | 15 -- .../read_exception_list_route.ts | 18 --- .../read_exception_list_item_route.ts | 18 --- .../summary_exception_list_route.ts | 18 --- .../update_exception_list_route.ts | 18 --- .../update_exception_list_item_route.ts | 18 --- x-pack/plugins/lists/common/api/index.ts | 14 -- .../create_exception_list_item_route.ts | 136 +++++++++--------- .../routes/create_exception_list_route.ts | 53 +++++-- .../delete_exception_list_item_route.ts | 50 +++---- .../routes/delete_exception_list_route.ts | 56 +++----- .../routes/duplicate_exception_list_route.ts | 25 ++-- .../routes/export_exception_list_route.ts | 7 +- .../routes/find_exception_list_item_route.ts | 63 ++++---- .../routes/find_exception_list_route.ts | 26 ++-- .../server/routes/import_exceptions_route.ts | 27 ++-- .../routes/read_exception_list_item_route.ts | 57 +++----- .../routes/read_exception_list_route.ts | 59 +++----- .../routes/summary_exception_list_route.ts | 67 ++++----- .../update_exception_list_item_route.ts | 92 ++++++------ .../routes/update_exception_list_route.ts | 72 ++++------ .../utils/validate_comments_to_update.test.ts | 30 ++++ .../utils/validate_comments_to_update.ts | 33 +++++ x-pack/plugins/lists/tsconfig.json | 1 + .../api/create_rule_exceptions/route.ts | 92 +++++------- .../exceptions/api/manage_exceptions/route.ts | 18 +-- .../plugins/security_solution/tsconfig.json | 7 +- .../trial_license_complete_tier/blocklists.ts | 6 +- .../lists/find_exception_lists.ts | 13 +- 52 files changed, 539 insertions(+), 898 deletions(-) delete mode 100644 packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_validation/index.test.ts delete mode 100644 packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_validation/index.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/create_exception_list_item/create_exception_list_item_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/delete_exception_list/delete_exception_list_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/delete_exception_list_item/delete_exception_list_item_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/duplicate_exception_list/duplicate_exception_list_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/export_exception_list/export_exception_list_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/export_list_item/export_list_item_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/find_exception_list/find_exception_list_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/find_exception_list_item/find_exception_list_item_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/import_exceptions/import_exceptions_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/read_exception_list/read_exception_list_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/read_exception_list_item/read_exception_list_item_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/summary_exception_list/summary_exception_list_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/update_exception_list/update_exception_list_route.ts delete mode 100644 x-pack/plugins/lists/common/api/exceptions/update_exception_list_item/update_exception_list_item_route.ts create mode 100644 x-pack/plugins/lists/server/routes/utils/validate_comments_to_update.test.ts create mode 100644 x-pack/plugins/lists/server/routes/utils/validate_comments_to_update.ts diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen.ts index 7c86af9eefd7c..e30f466cc056c 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen.ts @@ -17,11 +17,10 @@ import { z } from 'zod'; -import { UUID } from '@kbn/openapi-common/schemas/primitives.gen'; +import { UUID, NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; import { ExceptionListItem, ExceptionListItemHumanId, - ExceptionListHumanId, ExceptionListItemType, ExceptionListItemName, ExceptionListItemDescription, @@ -29,27 +28,35 @@ import { ExceptionListItemOsTypeArray, ExceptionListItemTags, ExceptionListItemMeta, - ExceptionListItemCommentArray, } from '../model/exception_list_common.gen'; import { ExceptionListItemEntryArray } from '../model/exception_list_item_entry.gen'; export type RuleId = z.infer; export const RuleId = UUID; +export type CreateRuleExceptionListItemComment = z.infer; +export const CreateRuleExceptionListItemComment = z.object({ + comment: NonEmptyString, +}); + +export type CreateRuleExceptionListItemCommentArray = z.infer< + typeof CreateRuleExceptionListItemCommentArray +>; +export const CreateRuleExceptionListItemCommentArray = z.array(CreateRuleExceptionListItemComment); + export type CreateRuleExceptionListItemProps = z.infer; export const CreateRuleExceptionListItemProps = z.object({ item_id: ExceptionListItemHumanId.optional(), - list_id: ExceptionListHumanId.optional(), type: ExceptionListItemType, name: ExceptionListItemName, description: ExceptionListItemDescription, entries: ExceptionListItemEntryArray, namespace_type: ExceptionNamespaceType.optional().default('single'), - os_types: ExceptionListItemOsTypeArray.optional(), - tags: ExceptionListItemTags.optional(), + os_types: ExceptionListItemOsTypeArray.optional().default([]), + tags: ExceptionListItemTags.optional().default([]), meta: ExceptionListItemMeta.optional(), expire_time: z.string().datetime().optional(), - comments: ExceptionListItemCommentArray.optional(), + comments: CreateRuleExceptionListItemCommentArray.optional().default([]), }); export type CreateRuleExceptionListItemsRequestParams = z.infer< @@ -78,4 +85,4 @@ export type CreateRuleExceptionListItemsRequestBodyInput = z.input< export type CreateRuleExceptionListItemsResponse = z.infer< typeof CreateRuleExceptionListItemsResponse >; -export const CreateRuleExceptionListItemsResponse = ExceptionListItem; +export const CreateRuleExceptionListItemsResponse = z.array(ExceptionListItem); diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.schema.yaml index e8f6656bc655f..b7cad73c9bb22 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.schema.yaml @@ -37,7 +37,9 @@ paths: content: application/json: schema: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' + type: array + items: + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' 400: description: Invalid input data response content: @@ -70,13 +72,24 @@ components: RuleId: $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/UUID' + CreateRuleExceptionListItemComment: + type: object + properties: + comment: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + required: + - comment + + CreateRuleExceptionListItemCommentArray: + type: array + items: + $ref: '#/components/schemas/CreateRuleExceptionListItemComment' + CreateRuleExceptionListItemProps: type: object properties: item_id: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' - list_id: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' type: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' name: @@ -90,15 +103,18 @@ components: default: 'single' os_types: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' + default: [] tags: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' + default: [] meta: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' expire_time: type: string format: date-time comments: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemCommentArray' + $ref: '#/components/schemas/CreateRuleExceptionListItemCommentArray' + default: [] required: - type - name diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts index 8fa1f31b835b6..de28bfabd023e 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts @@ -41,7 +41,7 @@ Uses the `so type.field name:field` value syntax, where `so type` can be: or available in all spaces (`agnostic` or `single`) */ - namespace_type: ArrayFromString(ExceptionNamespaceType).optional().default([]), + namespace_type: ArrayFromString(ExceptionNamespaceType).optional().default(['single']), /** * The page number to return */ diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml index 11e4faad12642..86bed1e556afb 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml @@ -34,7 +34,7 @@ paths: type: array items: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' - default: [] + default: [single] - name: page in: query required: false diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts index 67cd12c225071..01990ea698798 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts @@ -46,7 +46,7 @@ export type ExceptionListName = z.infer; export const ExceptionListName = NonEmptyString; export type ExceptionListDescription = z.infer; -export const ExceptionListDescription = NonEmptyString; +export const ExceptionListDescription = z.string(); export type ExceptionListMeta = z.infer; export const ExceptionListMeta = z.object({}).catchall(z.unknown()); @@ -81,12 +81,12 @@ export const ExceptionListVersion = z.number().int().min(1); export type ExceptionList = z.infer; export const ExceptionList = z.object({ id: ExceptionListId, - list_id: ExceptionListHumanId.optional(), + list_id: ExceptionListHumanId, type: ExceptionListType, name: ExceptionListName, description: ExceptionListDescription, immutable: z.boolean(), - namespace_type: ExceptionNamespaceType.optional(), + namespace_type: ExceptionNamespaceType, os_types: ExceptionListOsTypeArray.optional(), tags: ExceptionListTags.optional(), meta: ExceptionListMeta.optional(), @@ -112,7 +112,7 @@ export type ExceptionListItemName = z.infer; export const ExceptionListItemName = NonEmptyString; export type ExceptionListItemDescription = z.infer; -export const ExceptionListItemDescription = NonEmptyString; +export const ExceptionListItemDescription = z.string(); export type ExceptionListItemMeta = z.infer; export const ExceptionListItemMeta = z.object({}).catchall(z.unknown()); @@ -150,7 +150,7 @@ export const ExceptionListItem = z.object({ name: ExceptionListItemName, description: ExceptionListItemDescription, entries: ExceptionListItemEntryArray, - namespace_type: ExceptionNamespaceType.optional(), + namespace_type: ExceptionNamespaceType, os_types: ExceptionListItemOsTypeArray.optional(), tags: ExceptionListItemTags.optional(), meta: ExceptionListItemMeta.optional(), diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml index 1828742e50322..d0cb8be84d1fd 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml @@ -28,7 +28,7 @@ components: $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' ExceptionListDescription: - $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + type: string ExceptionListMeta: type: object @@ -108,10 +108,12 @@ components: type: string required: - id + - list_id - type - name - description - immutable + - namespace_type - version - tie_breaker_id - created_at @@ -133,7 +135,7 @@ components: $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' ExceptionListItemDescription: - $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + type: string ExceptionListItemMeta: type: object @@ -236,6 +238,7 @@ components: - name - description - entries + - namespace_type - comments - tie_breaker_id - created_at diff --git a/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen.ts index 9ba39cd55d381..5acf491245ce2 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen.ts @@ -41,4 +41,4 @@ export type GetExceptionListItemRequestQueryInput = z.input< >; export type GetExceptionListItemResponse = z.infer; -export const GetExceptionListItemResponse = z.array(ExceptionListItem); +export const GetExceptionListItemResponse = ExceptionListItem; diff --git a/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.schema.yaml index 421e77d51ffc0..1ebad10125160 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.schema.yaml @@ -36,9 +36,7 @@ paths: content: application/json: schema: - type: array - items: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' + $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' 400: description: Invalid input data response content: diff --git a/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen.ts index 139ae1822a01a..166093ccbeb30 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen.ts @@ -30,16 +30,16 @@ export const GetExceptionListSummaryRequestQuery = z.object({ /** * Exception list's identifier generated upon creation */ - id: ExceptionListId, + id: ExceptionListId.optional(), /** * Exception list's human readable identifier */ - list_id: ExceptionListHumanId, - namespace_type: ExceptionNamespaceType, + list_id: ExceptionListHumanId.optional(), + namespace_type: ExceptionNamespaceType.optional().default('single'), /** * Search filter clause */ - filter: z.string(), + filter: z.string().optional(), }); export type GetExceptionListSummaryRequestQueryInput = z.input< typeof GetExceptionListSummaryRequestQuery diff --git a/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.schema.yaml index 17f0f7ed0eee9..cc288ee524ff2 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.schema.yaml @@ -14,24 +14,25 @@ paths: parameters: - name: id in: query - required: true + required: false description: Exception list's identifier generated upon creation schema: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListId' - name: list_id in: query - required: true + required: false description: Exception list's human readable identifier schema: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' - name: namespace_type in: query - required: true + required: false schema: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' + default: single - name: filter in: query - required: true + required: false description: Search filter clause schema: type: string diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/request/index.ts b/packages/kbn-securitysolution-io-ts-list-types/src/request/index.ts index 2f82690bbecd6..7e51e6be46d78 100644 --- a/packages/kbn-securitysolution-io-ts-list-types/src/request/index.ts +++ b/packages/kbn-securitysolution-io-ts-list-types/src/request/index.ts @@ -39,7 +39,6 @@ export * from './read_list_schema'; export * from './summary_exception_list_schema'; export * from './update_endpoint_list_item_schema'; export * from './update_exception_list_item_schema'; -export * from './update_exception_list_item_validation'; export * from './update_exception_list_schema'; export * from './update_list_item_schema'; export * from './update_list_schema'; diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_schema/index.ts b/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_schema/index.ts index bb6ae55c0f037..b998a1695712d 100644 --- a/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_schema/index.ts +++ b/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_schema/index.ts @@ -7,9 +7,9 @@ */ import * as t from 'io-ts'; +import { ExceptionListItemEntryArray } from '@kbn/securitysolution-exceptions-common/api'; import { NamespaceType } from '../../common/default_namespace'; import { DefaultUpdateCommentsArray } from '../../common/default_update_comments_array'; -import { EntriesArray } from '../../common/entries'; import { exceptionListItemType } from '../../common/exception_list_item_type'; import { nonEmptyEntriesArray } from '../../common/non_empty_entries_array'; import { OsTypeArray, osTypeArrayOrUndefined } from '../../common/os_type'; @@ -57,7 +57,7 @@ export type UpdateExceptionListItemSchemaDecoded = Omit< > & { comments: UpdateCommentsArray; tags: Tags; - entries: EntriesArray; + entries: ExceptionListItemEntryArray; namespace_type: NamespaceType; os_types: OsTypeArray; expire_time: ExpireTimeOrUndefined; diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_validation/index.test.ts b/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_validation/index.test.ts deleted file mode 100644 index fea25b1ca8a21..0000000000000 --- a/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_validation/index.test.ts +++ /dev/null @@ -1,45 +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 { validateComments } from '.'; -import { getUpdateExceptionListItemSchemaMock } from '../update_exception_list_item_schema/index.mock'; - -describe('update_exception_list_item_validation', () => { - describe('#validateComments', () => { - test('it returns no errors if comments is undefined', () => { - const payload = getUpdateExceptionListItemSchemaMock(); - delete payload.comments; - const output = validateComments(payload); - - expect(output).toEqual([]); - }); - - test('it returns no errors if new comments are append only', () => { - const payload = getUpdateExceptionListItemSchemaMock(); - payload.comments = [ - { comment: 'Im an old comment', id: '1' }, - { comment: 'Im a new comment' }, - ]; - const output = validateComments(payload); - - expect(output).toEqual([]); - }); - - test('it returns error if comments are not append only', () => { - const payload = getUpdateExceptionListItemSchemaMock(); - payload.comments = [ - { comment: 'Im an old comment', id: '1' }, - { comment: 'Im a new comment modifying the order of existing comments' }, - { comment: 'Im an old comment', id: '2' }, - ]; - const output = validateComments(payload); - - expect(output).toEqual(['item "comments" are append only']); - }); - }); -}); diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_validation/index.ts b/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_validation/index.ts deleted file mode 100644 index 72c418eb913a2..0000000000000 --- a/packages/kbn-securitysolution-io-ts-list-types/src/request/update_exception_list_item_validation/index.ts +++ /dev/null @@ -1,42 +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 { UpdateExceptionListItemSchema } from '../update_exception_list_item_schema'; - -export const validateComments = (item: UpdateExceptionListItemSchema): string[] => { - if (item.comments == null) { - return []; - } - - const [appendOnly] = item.comments.reduce( - (acc, comment) => { - const [, hasNewComments] = acc; - if (comment.id == null) { - return [true, true]; - } - - if (hasNewComments && comment.id != null) { - return [false, true]; - } - - return acc; - }, - [true, false] - ); - if (!appendOnly) { - return ['item "comments" are append only']; - } else { - return []; - } -}; - -export const updateExceptionListItemValidate = ( - schema: UpdateExceptionListItemSchema -): string[] => { - return [...validateComments(schema)]; -}; diff --git a/packages/kbn-securitysolution-io-ts-list-types/tsconfig.json b/packages/kbn-securitysolution-io-ts-list-types/tsconfig.json index 124e310f10465..706aa6e81fc59 100644 --- a/packages/kbn-securitysolution-io-ts-list-types/tsconfig.json +++ b/packages/kbn-securitysolution-io-ts-list-types/tsconfig.json @@ -2,23 +2,17 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "target/types", - "types": [ - "jest", - "node" - ] + "types": ["jest", "node"] }, - "include": [ - "**/*.ts" - ], + "include": ["**/*.ts"], "kbn_references": [ "@kbn/securitysolution-io-ts-types", "@kbn/securitysolution-io-ts-utils", "@kbn/securitysolution-list-constants", "@kbn/es-query", "@kbn/core-http-browser", - "@kbn/core-notifications-browser" + "@kbn/core-notifications-browser", + "@kbn/securitysolution-exceptions-common" ], - "exclude": [ - "target/**/*", - ] + "exclude": ["target/**/*"] } diff --git a/x-pack/plugins/lists/common/api/exceptions/create_exception_list_item/create_exception_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/create_exception_list_item/create_exception_list_item_route.ts deleted file mode 100644 index cca081025db37..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/create_exception_list_item/create_exception_list_item_route.ts +++ /dev/null @@ -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. - */ - -import { - CreateExceptionListItemSchemaDecoded, - ExceptionListItemSchema, - createExceptionListItemSchema, - exceptionListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { createExceptionListItemSchema as createExceptionListItemRequest }; -export type { CreateExceptionListItemSchemaDecoded as CreateExceptionListItemRequestDecoded }; - -export const createExceptionListItemResponse = exceptionListItemSchema; -export type CreateExceptionListItemResponse = ExceptionListItemSchema; diff --git a/x-pack/plugins/lists/common/api/exceptions/delete_exception_list/delete_exception_list_route.ts b/x-pack/plugins/lists/common/api/exceptions/delete_exception_list/delete_exception_list_route.ts deleted file mode 100644 index 1d068739183b7..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/delete_exception_list/delete_exception_list_route.ts +++ /dev/null @@ -1,18 +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 { - DeleteExceptionListSchemaDecoded, - deleteExceptionListSchema, - exceptionListSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - deleteExceptionListSchema as deleteExceptionListRequestQuery, - exceptionListSchema as deleteExceptionListResponse, -}; -export type { DeleteExceptionListSchemaDecoded as DeleteExceptionListRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/delete_exception_list_item/delete_exception_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/delete_exception_list_item/delete_exception_list_item_route.ts deleted file mode 100644 index 327c83c48dd1f..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/delete_exception_list_item/delete_exception_list_item_route.ts +++ /dev/null @@ -1,18 +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 { - DeleteExceptionListItemSchemaDecoded, - deleteExceptionListItemSchema, - exceptionListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - deleteExceptionListItemSchema as deleteExceptionListItemRequestQuery, - exceptionListItemSchema as deleteExceptionListItemResponse, -}; -export type { DeleteExceptionListItemSchemaDecoded as DeleteExceptionListItemRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/duplicate_exception_list/duplicate_exception_list_route.ts b/x-pack/plugins/lists/common/api/exceptions/duplicate_exception_list/duplicate_exception_list_route.ts deleted file mode 100644 index dbbcdc62f995b..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/duplicate_exception_list/duplicate_exception_list_route.ts +++ /dev/null @@ -1,18 +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 { - DuplicateExceptionListQuerySchemaDecoded, - duplicateExceptionListQuerySchema, - exceptionListSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - duplicateExceptionListQuerySchema as duplicateExceptionListRequestQuery, - exceptionListSchema as duplicateExceptionListResponse, -}; -export type { DuplicateExceptionListQuerySchemaDecoded as DuplicateExceptionListRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/export_exception_list/export_exception_list_route.ts b/x-pack/plugins/lists/common/api/exceptions/export_exception_list/export_exception_list_route.ts deleted file mode 100644 index 9423bceabcc15..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/export_exception_list/export_exception_list_route.ts +++ /dev/null @@ -1,10 +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 { exportExceptionListQuerySchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { exportExceptionListQuerySchema as exportExceptionListRequestQuery }; diff --git a/x-pack/plugins/lists/common/api/exceptions/export_list_item/export_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/export_list_item/export_list_item_route.ts deleted file mode 100644 index d2870f139da5f..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/export_list_item/export_list_item_route.ts +++ /dev/null @@ -1,10 +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 { exportListItemQuerySchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { exportListItemQuerySchema as exportListItemRequestQuery }; diff --git a/x-pack/plugins/lists/common/api/exceptions/find_exception_list/find_exception_list_route.ts b/x-pack/plugins/lists/common/api/exceptions/find_exception_list/find_exception_list_route.ts deleted file mode 100644 index da1da9dde9299..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/find_exception_list/find_exception_list_route.ts +++ /dev/null @@ -1,18 +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 { - FindExceptionListSchemaDecoded, - findExceptionListSchema, - foundExceptionListSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - findExceptionListSchema as findExceptionListRequestQuery, - foundExceptionListSchema as findExceptionListResponse, -}; -export type { FindExceptionListSchemaDecoded as FindExceptionListRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/find_exception_list_item/find_exception_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/find_exception_list_item/find_exception_list_item_route.ts deleted file mode 100644 index 02bf165d7f990..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/find_exception_list_item/find_exception_list_item_route.ts +++ /dev/null @@ -1,18 +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 { - FindExceptionListItemSchemaDecoded, - findExceptionListItemSchema, - foundExceptionListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - findExceptionListItemSchema as findExceptionListItemRequestQuery, - foundExceptionListItemSchema as findExceptionListItemResponse, -}; -export type { FindExceptionListItemSchemaDecoded as FindExceptionListItemRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/import_exceptions/import_exceptions_route.ts b/x-pack/plugins/lists/common/api/exceptions/import_exceptions/import_exceptions_route.ts deleted file mode 100644 index 0b18d65ff5178..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/import_exceptions/import_exceptions_route.ts +++ /dev/null @@ -1,15 +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 { ImportQuerySchemaDecoded, importQuerySchema } from '@kbn/securitysolution-io-ts-types'; -import { importExceptionsResponseSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { - importQuerySchema as importExceptionsRequestQuery, - importExceptionsResponseSchema as importExceptionsResponse, -}; -export type { ImportQuerySchemaDecoded as ImportExceptionsRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/read_exception_list/read_exception_list_route.ts b/x-pack/plugins/lists/common/api/exceptions/read_exception_list/read_exception_list_route.ts deleted file mode 100644 index 58b43899f7f77..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/read_exception_list/read_exception_list_route.ts +++ /dev/null @@ -1,18 +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 { - ReadExceptionListSchemaDecoded, - exceptionListSchema, - readExceptionListSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - readExceptionListSchema as readExceptionListRequestQuery, - exceptionListSchema as readExceptionListResponse, -}; -export type { ReadExceptionListSchemaDecoded as ReadExceptionListRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/read_exception_list_item/read_exception_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/read_exception_list_item/read_exception_list_item_route.ts deleted file mode 100644 index 1499b875b9813..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/read_exception_list_item/read_exception_list_item_route.ts +++ /dev/null @@ -1,18 +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 { - ReadExceptionListItemSchemaDecoded, - exceptionListItemSchema, - readExceptionListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - readExceptionListItemSchema as readExceptionListItemRequestQuery, - exceptionListItemSchema as readExceptionListItemResponse, -}; -export type { ReadExceptionListItemSchemaDecoded as ReadExceptionListItemRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/summary_exception_list/summary_exception_list_route.ts b/x-pack/plugins/lists/common/api/exceptions/summary_exception_list/summary_exception_list_route.ts deleted file mode 100644 index aecd14d6cba02..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/summary_exception_list/summary_exception_list_route.ts +++ /dev/null @@ -1,18 +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 { - SummaryExceptionListSchemaDecoded, - exceptionListSummarySchema, - summaryExceptionListSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - summaryExceptionListSchema as summaryExceptionListRequestQuery, - exceptionListSummarySchema as summaryExceptionListResponse, -}; -export type { SummaryExceptionListSchemaDecoded as SummaryExceptionListRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/update_exception_list/update_exception_list_route.ts b/x-pack/plugins/lists/common/api/exceptions/update_exception_list/update_exception_list_route.ts deleted file mode 100644 index 0550a5d90311b..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/update_exception_list/update_exception_list_route.ts +++ /dev/null @@ -1,18 +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 { - UpdateExceptionListSchemaDecoded, - exceptionListSchema, - updateExceptionListSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - updateExceptionListSchema as updateExceptionListRequest, - exceptionListSchema as updateExceptionListResponse, -}; -export type { UpdateExceptionListSchemaDecoded as UpdateExceptionListRequestDecoded }; diff --git a/x-pack/plugins/lists/common/api/exceptions/update_exception_list_item/update_exception_list_item_route.ts b/x-pack/plugins/lists/common/api/exceptions/update_exception_list_item/update_exception_list_item_route.ts deleted file mode 100644 index 330198a81bd81..0000000000000 --- a/x-pack/plugins/lists/common/api/exceptions/update_exception_list_item/update_exception_list_item_route.ts +++ /dev/null @@ -1,18 +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 { - UpdateExceptionListItemSchemaDecoded, - exceptionListItemSchema, - updateExceptionListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - updateExceptionListItemSchema as updateExceptionListItemRequest, - exceptionListItemSchema as updateExceptionListItemResponse, -}; -export type { UpdateExceptionListItemSchemaDecoded as UpdateExceptionListItemRequestDecoded }; diff --git a/x-pack/plugins/lists/common/api/index.ts b/x-pack/plugins/lists/common/api/index.ts index 1cbbeba219078..bc8f36dbfde0e 100644 --- a/x-pack/plugins/lists/common/api/index.ts +++ b/x-pack/plugins/lists/common/api/index.ts @@ -7,24 +7,10 @@ export * from './exceptions/create_endpoint_list_item/create_endpoint_list_item_route'; export * from './exceptions/create_endpoint_list/create_endpoint_list_route'; -export * from './exceptions/create_exception_list_item/create_exception_list_item_route'; export * from './exceptions/create_exception_list/create_exception_list_route'; export * from './exceptions/delete_endpoint_list_item/delete_endpoint_list_item_route'; -export * from './exceptions/delete_exception_list_item/delete_exception_list_item_route'; -export * from './exceptions/delete_exception_list/delete_exception_list_route'; -export * from './exceptions/duplicate_exception_list/duplicate_exception_list_route'; -export * from './exceptions/export_exception_list/export_exception_list_route'; -export * from './exceptions/export_list_item/export_list_item_route'; export * from './exceptions/find_endpoint_list_item/find_endpoint_list_item_route'; -export * from './exceptions/find_exception_list_item/find_exception_list_item_route'; -export * from './exceptions/find_exception_list/find_exception_list_route'; export * from './exceptions/get_exception_filter/get_exception_filter_route'; -export * from './exceptions/import_exceptions/import_exceptions_route'; export * from './exceptions/read_endpoint_list_item/read_endpoint_list_item_route'; -export * from './exceptions/read_exception_list_item/read_exception_list_item_route'; -export * from './exceptions/read_exception_list/read_exception_list_route'; -export * from './exceptions/summary_exception_list/summary_exception_list_route'; export * from './exceptions/update_endpoint_list_item/update_endpoint_list_item_route'; -export * from './exceptions/update_exception_list_item/update_exception_list_item_route'; -export * from './exceptions/update_exception_list/update_exception_list_route'; export * from './values/find_lists_by_size/find_lists_by_size_route'; diff --git a/x-pack/plugins/lists/server/routes/create_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/create_exception_list_item_route.ts index cbe76bc4b3203..7071ec6412a27 100644 --- a/x-pack/plugins/lists/server/routes/create_exception_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/create_exception_list_item_route.ts @@ -5,18 +5,18 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; +import { v4 as uuidv4 } from 'uuid'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + CreateExceptionListItemRequestBody, + CreateExceptionListItemResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - CreateExceptionListItemRequestDecoded, - createExceptionListItemRequest, - createExceptionListItemResponse, -} from '../../common/api'; -import { buildRouteValidation, buildSiemResponse } from './utils'; +import { buildSiemResponse } from './utils'; import { getExceptionListClient } from './utils/get_exception_list_client'; import { endpointDisallowedFields } from './endpoint_disallowed_fields'; import { validateEndpointExceptionItemEntries, validateExceptionListSize } from './validate'; @@ -34,10 +34,7 @@ export const createExceptionListItemRoute = (router: ListsPluginRouter): void => { validate: { request: { - body: buildRouteValidation< - typeof createExceptionListItemRequest, - CreateExceptionListItemRequestDecoded - >(createExceptionListItemRequest), + body: buildRouteValidationWithZod(CreateExceptionListItemRequestBody), }, }, version: '2023-10-31', @@ -53,7 +50,7 @@ export const createExceptionListItemRoute = (router: ListsPluginRouter): void => comments, description, entries, - item_id: itemId, + item_id: itemId = uuidv4(), list_id: listId, os_types: osTypes, type, @@ -65,71 +62,74 @@ export const createExceptionListItemRoute = (router: ListsPluginRouter): void => listId, namespaceType, }); + if (exceptionList == null) { return siemResponse.error({ body: `exception list id: "${listId}" does not exist`, statusCode: 404, }); - } else { - const exceptionListItem = await exceptionLists.getExceptionListItem({ - id: undefined, - itemId, - namespaceType, + } + + const exceptionListItem = await exceptionLists.getExceptionListItem({ + id: undefined, + itemId, + namespaceType, + }); + + if (exceptionListItem != null) { + return siemResponse.error({ + body: `exception list item id: "${itemId}" already exists`, + statusCode: 409, }); - if (exceptionListItem != null) { - return siemResponse.error({ - body: `exception list item id: "${itemId}" already exists`, - statusCode: 409, - }); - } else { - if (exceptionList.type === 'endpoint') { - const error = validateEndpointExceptionItemEntries(request.body.entries); - if (error != null) { - return siemResponse.error(error); - } - for (const entry of entries) { - if (endpointDisallowedFields.includes(entry.field)) { - return siemResponse.error({ - body: `cannot add endpoint exception item on field ${entry.field}`, - statusCode: 400, - }); - } - } - } - const createdList = await exceptionLists.createExceptionListItem({ - comments, - description, - entries, - expireTime, - itemId, - listId, - meta, - name, - namespaceType, - osTypes, - tags, - type, - }); - const [validated, errors] = validate(createdList, createExceptionListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - const listSizeError = await validateExceptionListSize( - exceptionLists, - listId, - namespaceType - ); - if (listSizeError != null) { - await exceptionLists.deleteExceptionListItemById({ - id: createdList.id, - namespaceType, - }); - return siemResponse.error(listSizeError); - } - return response.ok({ body: validated ?? {} }); + } + + if (exceptionList.type === 'endpoint') { + const error = validateEndpointExceptionItemEntries(request.body.entries); + if (error != null) { + return siemResponse.error(error); + } + for (const entry of entries) { + if (endpointDisallowedFields.includes(entry.field)) { + return siemResponse.error({ + body: `cannot add endpoint exception item on field ${entry.field}`, + statusCode: 400, + }); } } } + + const createdListItem = await exceptionLists.createExceptionListItem({ + comments, + description, + entries, + expireTime, + itemId, + listId, + meta, + name, + namespaceType, + osTypes, + tags, + type, + }); + + const listSizeError = await validateExceptionListSize( + exceptionLists, + listId, + namespaceType + ); + + if (listSizeError != null) { + await exceptionLists.deleteExceptionListItemById({ + id: createdListItem.id, + namespaceType, + }); + return siemResponse.error(listSizeError); + } + + return response.ok({ + body: CreateExceptionListItemResponse.parse(createdListItem), + }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/create_exception_list_route.ts b/x-pack/plugins/lists/server/routes/create_exception_list_route.ts index f658178ea9193..a0c0568c31b8d 100644 --- a/x-pack/plugins/lists/server/routes/create_exception_list_route.ts +++ b/x-pack/plugins/lists/server/routes/create_exception_list_route.ts @@ -5,14 +5,18 @@ * 2.0. */ +import { v4 as uuidv4 } from 'uuid'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + CreateExceptionListRequestBody, + CreateExceptionListResponse, +} from '@kbn/securitysolution-exceptions-common/api'; -import { CreateExceptionListRequestDecoded, createExceptionListRequest } from '../../common/api'; import type { ListsPluginRouter } from '../types'; -import { createExceptionListHandler } from '../handlers/create_exception_list_handler'; -import { buildRouteValidation, buildSiemResponse } from './utils'; +import { buildSiemResponse, getExceptionListClient } from './utils'; export const createExceptionListRoute = (router: ListsPluginRouter): void => { router.versioned @@ -27,10 +31,7 @@ export const createExceptionListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - body: buildRouteValidation< - typeof createExceptionListRequest, - CreateExceptionListRequestDecoded - >(createExceptionListRequest), + body: buildRouteValidationWithZod(CreateExceptionListRequestBody), }, }, version: '2023-10-31', @@ -38,7 +39,43 @@ export const createExceptionListRoute = (router: ListsPluginRouter): void => { async (context, request, response) => { const siemResponse = buildSiemResponse(response); try { - return await createExceptionListHandler(context, request, response, siemResponse); + const { + name, + tags, + meta, + namespace_type: namespaceType, + description, + list_id: listId = uuidv4(), + type, + version, + } = request.body; + const exceptionLists = await getExceptionListClient(context); + const exceptionList = await exceptionLists.getExceptionList({ + id: undefined, + listId, + namespaceType, + }); + + if (exceptionList != null) { + return siemResponse.error({ + body: `exception list id: "${listId}" already exists`, + statusCode: 409, + }); + } + + const createdList = await exceptionLists.createExceptionList({ + description, + immutable: false, + listId, + meta, + name, + namespaceType, + tags, + type, + version, + }); + + return response.ok({ body: CreateExceptionListResponse.parse(createdList) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/delete_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/delete_exception_list_item_route.ts index 665795b389e21..d460610cd02b7 100644 --- a/x-pack/plugins/lists/server/routes/delete_exception_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/delete_exception_list_item_route.ts @@ -5,19 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + DeleteExceptionListItemRequestQuery, + DeleteExceptionListItemResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - DeleteExceptionListItemRequestQueryDecoded, - deleteExceptionListItemRequestQuery, - deleteExceptionListItemResponse, -} from '../../common/api'; import { - buildRouteValidation, buildSiemResponse, getErrorMessageExceptionListItem, getExceptionListClient, @@ -36,10 +34,7 @@ export const deleteExceptionListItemRoute = (router: ListsPluginRouter): void => { validate: { request: { - query: buildRouteValidation< - typeof deleteExceptionListItemRequestQuery, - DeleteExceptionListItemRequestQueryDecoded - >(deleteExceptionListItemRequestQuery), + query: buildRouteValidationWithZod(DeleteExceptionListItemRequestQuery), }, }, version: '2023-10-31', @@ -49,31 +44,28 @@ export const deleteExceptionListItemRoute = (router: ListsPluginRouter): void => try { const exceptionLists = await getExceptionListClient(context); const { item_id: itemId, id, namespace_type: namespaceType } = request.query; + if (itemId == null && id == null) { return siemResponse.error({ body: 'Either "item_id" or "id" needs to be defined in the request', statusCode: 400, }); - } else { - const deleted = await exceptionLists.deleteExceptionListItem({ - id, - itemId, - namespaceType, + } + + const deleted = await exceptionLists.deleteExceptionListItem({ + id, + itemId, + namespaceType, + }); + + if (deleted == null) { + return siemResponse.error({ + body: getErrorMessageExceptionListItem({ id, itemId }), + statusCode: 404, }); - if (deleted == null) { - return siemResponse.error({ - body: getErrorMessageExceptionListItem({ id, itemId }), - statusCode: 404, - }); - } else { - const [validated, errors] = validate(deleted, deleteExceptionListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } - } } + + return response.ok({ body: DeleteExceptionListItemResponse.parse(deleted) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/delete_exception_list_route.ts b/x-pack/plugins/lists/server/routes/delete_exception_list_route.ts index 371b5e8cb5da2..938fc9b9bcc2d 100644 --- a/x-pack/plugins/lists/server/routes/delete_exception_list_route.ts +++ b/x-pack/plugins/lists/server/routes/delete_exception_list_route.ts @@ -5,23 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + DeleteExceptionListRequestQuery, + DeleteExceptionListResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - DeleteExceptionListRequestQueryDecoded, - deleteExceptionListRequestQuery, - deleteExceptionListResponse, -} from '../../common/api'; -import { - buildRouteValidation, - buildSiemResponse, - getErrorMessageExceptionList, - getExceptionListClient, -} from './utils'; +import { buildSiemResponse, getErrorMessageExceptionList, getExceptionListClient } from './utils'; export const deleteExceptionListRoute = (router: ListsPluginRouter): void => { router.versioned @@ -36,10 +30,7 @@ export const deleteExceptionListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof deleteExceptionListRequestQuery, - DeleteExceptionListRequestQueryDecoded - >(deleteExceptionListRequestQuery), + query: buildRouteValidationWithZod(DeleteExceptionListRequestQuery), }, }, version: '2023-10-31', @@ -49,31 +40,28 @@ export const deleteExceptionListRoute = (router: ListsPluginRouter): void => { try { const exceptionLists = await getExceptionListClient(context); const { list_id: listId, id, namespace_type: namespaceType } = request.query; + if (listId == null && id == null) { return siemResponse.error({ body: 'Either "list_id" or "id" needs to be defined in the request', statusCode: 400, }); - } else { - const deleted = await exceptionLists.deleteExceptionList({ - id, - listId, - namespaceType, + } + + const deleted = await exceptionLists.deleteExceptionList({ + id, + listId, + namespaceType, + }); + + if (deleted == null) { + return siemResponse.error({ + body: getErrorMessageExceptionList({ id, listId }), + statusCode: 404, }); - if (deleted == null) { - return siemResponse.error({ - body: getErrorMessageExceptionList({ id, listId }), - statusCode: 404, - }); - } else { - const [validated, errors] = validate(deleted, deleteExceptionListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } - } } + + return response.ok({ body: DeleteExceptionListResponse.parse(deleted) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/duplicate_exception_list_route.ts b/x-pack/plugins/lists/server/routes/duplicate_exception_list_route.ts index df096206e494c..38a51f12a7ed5 100644 --- a/x-pack/plugins/lists/server/routes/duplicate_exception_list_route.ts +++ b/x-pack/plugins/lists/server/routes/duplicate_exception_list_route.ts @@ -6,17 +6,16 @@ */ import { transformError } from '@kbn/securitysolution-es-utils'; -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + DuplicateExceptionListRequestQuery, + DuplicateExceptionListResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - DuplicateExceptionListRequestQueryDecoded, - duplicateExceptionListRequestQuery, - duplicateExceptionListResponse, -} from '../../common/api'; -import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils'; +import { buildSiemResponse, getExceptionListClient } from './utils'; export const duplicateExceptionsRoute = (router: ListsPluginRouter): void => { router.versioned @@ -31,10 +30,7 @@ export const duplicateExceptionsRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof duplicateExceptionListRequestQuery, - DuplicateExceptionListRequestQueryDecoded - >(duplicateExceptionListRequestQuery), + query: buildRouteValidationWithZod(DuplicateExceptionListRequestQuery), }, }, version: '2023-10-31', @@ -83,12 +79,7 @@ export const duplicateExceptionsRoute = (router: ListsPluginRouter): void => { }); } - const [validated, errors] = validate(duplicatedList, duplicateExceptionListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: DuplicateExceptionListResponse.parse(duplicatedList) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/export_exception_list_route.ts b/x-pack/plugins/lists/server/routes/export_exception_list_route.ts index 5f1787a2de232..72ac564604337 100644 --- a/x-pack/plugins/lists/server/routes/export_exception_list_route.ts +++ b/x-pack/plugins/lists/server/routes/export_exception_list_route.ts @@ -7,11 +7,12 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { ExportExceptionListRequestQuery } from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { exportExceptionListRequestQuery } from '../../common/api'; -import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils'; +import { buildSiemResponse, getExceptionListClient } from './utils'; export const exportExceptionsRoute = (router: ListsPluginRouter): void => { router.versioned @@ -26,7 +27,7 @@ export const exportExceptionsRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation(exportExceptionListRequestQuery), + query: buildRouteValidationWithZod(ExportExceptionListRequestQuery), }, }, version: '2023-10-31', diff --git a/x-pack/plugins/lists/server/routes/find_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/find_exception_list_item_route.ts index c119b5bf166b9..f0e4b5546df4f 100644 --- a/x-pack/plugins/lists/server/routes/find_exception_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/find_exception_list_item_route.ts @@ -5,18 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + FindExceptionListItemsRequestQuery, + FindExceptionListItemsResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - FindExceptionListItemRequestQueryDecoded, - findExceptionListItemRequestQuery, - findExceptionListItemResponse, -} from '../../common/api'; -import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils'; +import { buildSiemResponse, getExceptionListClient } from './utils'; export const findExceptionListItemRoute = (router: ListsPluginRouter): void => { router.versioned @@ -31,10 +30,7 @@ export const findExceptionListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof findExceptionListItemRequestQuery, - FindExceptionListItemRequestQueryDecoded - >(findExceptionListItemRequestQuery), + query: buildRouteValidationWithZod(FindExceptionListItemsRequestQuery), }, }, version: '2023-10-31', @@ -64,32 +60,29 @@ export const findExceptionListItemRoute = (router: ListsPluginRouter): void => { body: `list_id and filter need to have the same comma separated number of values. Expected list_id length: ${listId.length} to equal filter length: ${filter.length}`, statusCode: 400, }); - } else { - const exceptionListItems = await exceptionLists.findExceptionListsItem({ - filter, - listId, - namespaceType, - page, - perPage, - pit: undefined, - search, - searchAfter: undefined, - sortField, - sortOrder, + } + + const exceptionListItems = await exceptionLists.findExceptionListsItem({ + filter, + listId, + namespaceType, + page, + perPage, + pit: undefined, + search, + searchAfter: undefined, + sortField, + sortOrder, + }); + + if (exceptionListItems == null) { + return siemResponse.error({ + body: `exception list id: "${listId}" does not exist`, + statusCode: 404, }); - if (exceptionListItems == null) { - return siemResponse.error({ - body: `exception list id: "${listId}" does not exist`, - statusCode: 404, - }); - } - const [validated, errors] = validate(exceptionListItems, findExceptionListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } } + + return response.ok({ body: FindExceptionListItemsResponse.parse(exceptionListItems) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/find_exception_list_route.ts b/x-pack/plugins/lists/server/routes/find_exception_list_route.ts index d5b950c35e95e..93206b178e2d1 100644 --- a/x-pack/plugins/lists/server/routes/find_exception_list_route.ts +++ b/x-pack/plugins/lists/server/routes/find_exception_list_route.ts @@ -5,18 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + FindExceptionListsRequestQuery, + FindExceptionListsResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - FindExceptionListRequestQueryDecoded, - findExceptionListRequestQuery, - findExceptionListResponse, -} from '../../common/api'; -import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils'; +import { buildSiemResponse, getExceptionListClient } from './utils'; export const findExceptionListRoute = (router: ListsPluginRouter): void => { router.versioned @@ -31,10 +30,7 @@ export const findExceptionListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof findExceptionListRequestQuery, - FindExceptionListRequestQueryDecoded - >(findExceptionListRequestQuery), + query: buildRouteValidationWithZod(FindExceptionListsRequestQuery), }, }, version: '2023-10-31', @@ -61,12 +57,8 @@ export const findExceptionListRoute = (router: ListsPluginRouter): void => { sortField, sortOrder, }); - const [validated, errors] = validate(exceptionListItems, findExceptionListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + + return response.ok({ body: FindExceptionListsResponse.parse(exceptionListItems) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/import_exceptions_route.ts b/x-pack/plugins/lists/server/routes/import_exceptions_route.ts index 36ea934e4ea21..af6a88254915c 100644 --- a/x-pack/plugins/lists/server/routes/import_exceptions_route.ts +++ b/x-pack/plugins/lists/server/routes/import_exceptions_route.ts @@ -10,17 +10,16 @@ import { extname } from 'path'; import { schema } from '@kbn/config-schema'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; -import { validate } from '@kbn/securitysolution-io-ts-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + ImportExceptionListRequestQuery, + ImportExceptionListResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; import { ConfigType } from '../config'; -import { - ImportExceptionsRequestQueryDecoded, - importExceptionsRequestQuery, - importExceptionsResponse, -} from '../../common/api'; -import { buildRouteValidation, buildSiemResponse, getExceptionListClient } from './utils'; +import { buildSiemResponse, getExceptionListClient } from './utils'; /** * Takes an ndjson file of exception lists and exception list items and @@ -45,10 +44,7 @@ export const importExceptionsRoute = (router: ListsPluginRouter, config: ConfigT validate: { request: { body: schema.any(), // validation on file object is accomplished later in the handler. - query: buildRouteValidation< - typeof importExceptionsRequestQuery, - ImportExceptionsRequestQueryDecoded - >(importExceptionsRequestQuery), + query: buildRouteValidationWithZod(ImportExceptionListRequestQuery), }, }, version: '2023-10-31', @@ -60,6 +56,7 @@ export const importExceptionsRoute = (router: ListsPluginRouter, config: ConfigT try { const { filename } = request.body.file.hapi; const fileExtension = extname(filename).toLowerCase(); + if (fileExtension !== '.ndjson') { return siemResponse.error({ body: `Invalid file extension ${fileExtension}`, @@ -74,13 +71,7 @@ export const importExceptionsRoute = (router: ListsPluginRouter, config: ConfigT overwrite: request.query.overwrite, }); - const [validated, errors] = validate(importsSummary, importExceptionsResponse); - - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: ImportExceptionListResponse.parse(importsSummary) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/read_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/read_exception_list_item_route.ts index 7e74e928a717c..768592f1e450d 100644 --- a/x-pack/plugins/lists/server/routes/read_exception_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/read_exception_list_item_route.ts @@ -5,19 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + GetExceptionListItemRequestQuery, + GetExceptionListItemResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - ReadExceptionListItemRequestQueryDecoded, - readExceptionListItemRequestQuery, - readExceptionListItemResponse, -} from '../../common/api'; import { - buildRouteValidation, buildSiemResponse, getErrorMessageExceptionListItem, getExceptionListClient, @@ -36,10 +34,7 @@ export const readExceptionListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof readExceptionListItemRequestQuery, - ReadExceptionListItemRequestQueryDecoded - >(readExceptionListItemRequestQuery), + query: buildRouteValidationWithZod(GetExceptionListItemRequestQuery), }, }, version: '2023-10-31', @@ -49,31 +44,25 @@ export const readExceptionListItemRoute = (router: ListsPluginRouter): void => { try { const { id, item_id: itemId, namespace_type: namespaceType } = request.query; const exceptionLists = await getExceptionListClient(context); - if (id != null || itemId != null) { - const exceptionListItem = await exceptionLists.getExceptionListItem({ - id, - itemId, - namespaceType, - }); - if (exceptionListItem == null) { - return siemResponse.error({ - body: getErrorMessageExceptionListItem({ id, itemId }), - statusCode: 404, - }); - } else { - const [validated, errors] = validate( - exceptionListItem, - readExceptionListItemResponse - ); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } - } - } else { + + if (id == null && itemId == null) { return siemResponse.error({ body: 'id or item_id required', statusCode: 400 }); } + + const exceptionListItem = await exceptionLists.getExceptionListItem({ + id, + itemId, + namespaceType, + }); + + if (exceptionListItem == null) { + return siemResponse.error({ + body: getErrorMessageExceptionListItem({ id, itemId }), + statusCode: 404, + }); + } + + return response.ok({ body: GetExceptionListItemResponse.parse(exceptionListItem) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/read_exception_list_route.ts b/x-pack/plugins/lists/server/routes/read_exception_list_route.ts index 5da7395cf4875..899804ff9b9fa 100644 --- a/x-pack/plugins/lists/server/routes/read_exception_list_route.ts +++ b/x-pack/plugins/lists/server/routes/read_exception_list_route.ts @@ -5,23 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + GetExceptionListRequestQuery, + GetExceptionListResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - ReadExceptionListRequestQueryDecoded, - readExceptionListRequestQuery, - readExceptionListResponse, -} from '../../common/api'; -import { - buildRouteValidation, - buildSiemResponse, - getErrorMessageExceptionList, - getExceptionListClient, -} from './utils'; +import { buildSiemResponse, getErrorMessageExceptionList, getExceptionListClient } from './utils'; export const readExceptionListRoute = (router: ListsPluginRouter): void => { router.versioned @@ -36,10 +30,7 @@ export const readExceptionListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof readExceptionListRequestQuery, - ReadExceptionListRequestQueryDecoded - >(readExceptionListRequestQuery), + query: buildRouteValidationWithZod(GetExceptionListRequestQuery), }, }, version: '2023-10-31', @@ -49,28 +40,24 @@ export const readExceptionListRoute = (router: ListsPluginRouter): void => { try { const { id, list_id: listId, namespace_type: namespaceType } = request.query; const exceptionLists = await getExceptionListClient(context); - if (id != null || listId != null) { - const exceptionList = await exceptionLists.getExceptionList({ - id, - listId, - namespaceType, - }); - if (exceptionList == null) { - return siemResponse.error({ - body: getErrorMessageExceptionList({ id, listId }), - statusCode: 404, - }); - } else { - const [validated, errors] = validate(exceptionList, readExceptionListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } - } - } else { + + if (id == null && listId == null) { return siemResponse.error({ body: 'id or list_id required', statusCode: 400 }); } + + const exceptionList = await exceptionLists.getExceptionList({ + id, + listId, + namespaceType, + }); + if (exceptionList == null) { + return siemResponse.error({ + body: getErrorMessageExceptionList({ id, listId }), + statusCode: 404, + }); + } + + return response.ok({ body: GetExceptionListResponse.parse(exceptionList) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/summary_exception_list_route.ts b/x-pack/plugins/lists/server/routes/summary_exception_list_route.ts index c927a1e947145..3e8f8cc384d3e 100644 --- a/x-pack/plugins/lists/server/routes/summary_exception_list_route.ts +++ b/x-pack/plugins/lists/server/routes/summary_exception_list_route.ts @@ -5,23 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + GetExceptionListSummaryRequestQuery, + GetExceptionListSummaryResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - SummaryExceptionListRequestQueryDecoded, - summaryExceptionListRequestQuery, - summaryExceptionListResponse, -} from '../../common/api'; -import { - buildRouteValidation, - buildSiemResponse, - getErrorMessageExceptionList, - getExceptionListClient, -} from './utils'; +import { buildSiemResponse, getErrorMessageExceptionList, getExceptionListClient } from './utils'; export const summaryExceptionListRoute = (router: ListsPluginRouter): void => { router.versioned @@ -36,10 +30,7 @@ export const summaryExceptionListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof summaryExceptionListRequestQuery, - SummaryExceptionListRequestQueryDecoded - >(summaryExceptionListRequestQuery), + query: buildRouteValidationWithZod(GetExceptionListSummaryRequestQuery), }, }, version: '2023-10-31', @@ -49,32 +40,28 @@ export const summaryExceptionListRoute = (router: ListsPluginRouter): void => { try { const { id, list_id: listId, namespace_type: namespaceType, filter } = request.query; const exceptionLists = await getExceptionListClient(context); - if (id != null || listId != null) { - const exceptionListSummary = await exceptionLists.getExceptionListSummary({ - filter, - id, - listId, - namespaceType, - }); - if (exceptionListSummary == null) { - return siemResponse.error({ - body: getErrorMessageExceptionList({ id, listId }), - statusCode: 404, - }); - } else { - const [validated, errors] = validate( - exceptionListSummary, - summaryExceptionListResponse - ); - if (errors != null) { - return response.ok({ body: exceptionListSummary }); - } else { - return response.ok({ body: validated ?? {} }); - } - } - } else { + + if (id == null && listId == null) { return siemResponse.error({ body: 'id or list_id required', statusCode: 400 }); } + + const exceptionListSummary = await exceptionLists.getExceptionListSummary({ + filter, + id, + listId, + namespaceType, + }); + + if (exceptionListSummary == null) { + return siemResponse.error({ + body: getErrorMessageExceptionList({ id, listId }), + statusCode: 404, + }); + } + + return response.ok({ + body: GetExceptionListSummaryResponse.parse(exceptionListSummary), + }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/update_exception_list_item_route.ts b/x-pack/plugins/lists/server/routes/update_exception_list_item_route.ts index da3b6849fe143..f3f925317afb0 100644 --- a/x-pack/plugins/lists/server/routes/update_exception_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/update_exception_list_item_route.ts @@ -5,19 +5,18 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; -import { updateExceptionListItemValidate } from '@kbn/securitysolution-io-ts-list-types'; import { EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + UpdateExceptionListItemRequestBody, + UpdateExceptionListItemResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - UpdateExceptionListItemRequestDecoded, - updateExceptionListItemRequest, - updateExceptionListItemResponse, -} from '../../common/api'; -import { buildRouteValidation, buildSiemResponse } from './utils'; +import { buildSiemResponse } from './utils'; +import { validateCommentsToUpdate } from './utils/validate_comments_to_update'; import { getExceptionListClient } from '.'; @@ -34,17 +33,14 @@ export const updateExceptionListItemRoute = (router: ListsPluginRouter): void => { validate: { request: { - body: buildRouteValidation< - typeof updateExceptionListItemRequest, - UpdateExceptionListItemRequestDecoded - >(updateExceptionListItemRequest), + body: buildRouteValidationWithZod(UpdateExceptionListItemRequestBody), }, }, version: '2023-10-31', }, async (context, request, response) => { const siemResponse = buildSiemResponse(response); - const validationErrors = updateExceptionListItemValidate(request.body); + const validationErrors = validateCommentsToUpdate(request.body.comments); if (validationErrors.length) { return siemResponse.error({ body: validationErrors, statusCode: 400 }); } @@ -65,52 +61,44 @@ export const updateExceptionListItemRoute = (router: ListsPluginRouter): void => tags, expire_time: expireTime, } = request.body; + if (id == null && itemId == null) { return siemResponse.error({ body: 'either id or item_id need to be defined', statusCode: 404, }); - } else { - const exceptionLists = await getExceptionListClient(context); - const exceptionListItem = await exceptionLists.updateOverwriteExceptionListItem({ - _version, - comments, - description, - entries, - expireTime, - id, - itemId, - meta, - name, - namespaceType, - osTypes, - tags, - type, + } + + const exceptionLists = await getExceptionListClient(context); + const exceptionListItem = await exceptionLists.updateOverwriteExceptionListItem({ + _version, + comments, + description, + entries, + expireTime, + id, + itemId, + meta, + name, + namespaceType, + osTypes, + tags, + type, + }); + + if (exceptionListItem == null) { + return siemResponse.error({ + body: + id != null + ? `exception list item id: "${id}" does not exist` + : `exception list item item_id: "${itemId}" does not exist`, + statusCode: 404, }); - if (exceptionListItem == null) { - if (id != null) { - return siemResponse.error({ - body: `exception list item id: "${id}" does not exist`, - statusCode: 404, - }); - } else { - return siemResponse.error({ - body: `exception list item item_id: "${itemId}" does not exist`, - statusCode: 404, - }); - } - } else { - const [validated, errors] = validate( - exceptionListItem, - updateExceptionListItemResponse - ); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } - } } + + return response.ok({ + body: UpdateExceptionListItemResponse.parse(exceptionListItem), + }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/update_exception_list_route.ts b/x-pack/plugins/lists/server/routes/update_exception_list_route.ts index 636f77d9f2eba..6998b612c78a2 100644 --- a/x-pack/plugins/lists/server/routes/update_exception_list_route.ts +++ b/x-pack/plugins/lists/server/routes/update_exception_list_route.ts @@ -5,23 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + UpdateExceptionListRequestBody, + UpdateExceptionListResponse, +} from '@kbn/securitysolution-exceptions-common/api'; import type { ListsPluginRouter } from '../types'; -import { - UpdateExceptionListRequestDecoded, - updateExceptionListRequest, - updateExceptionListResponse, -} from '../../common/api'; -import { - buildRouteValidation, - buildSiemResponse, - getErrorMessageExceptionList, - getExceptionListClient, -} from './utils'; +import { buildSiemResponse, getErrorMessageExceptionList, getExceptionListClient } from './utils'; export const updateExceptionListRoute = (router: ListsPluginRouter): void => { router.versioned @@ -36,10 +30,7 @@ export const updateExceptionListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - body: buildRouteValidation< - typeof updateExceptionListRequest, - UpdateExceptionListRequestDecoded - >(updateExceptionListRequest), + body: buildRouteValidationWithZod(UpdateExceptionListRequestBody), }, }, version: '2023-10-31', @@ -61,39 +52,36 @@ export const updateExceptionListRoute = (router: ListsPluginRouter): void => { version, } = request.body; const exceptionLists = await getExceptionListClient(context); + if (id == null && listId == null) { return siemResponse.error({ body: 'either id or list_id need to be defined', statusCode: 404, }); - } else { - const list = await exceptionLists.updateExceptionList({ - _version, - description, - id, - listId, - meta, - name, - namespaceType, - osTypes, - tags, - type, - version, + } + + const list = await exceptionLists.updateExceptionList({ + _version, + description, + id, + listId, + meta, + name, + namespaceType, + osTypes, + tags, + type, + version, + }); + + if (list == null) { + return siemResponse.error({ + body: getErrorMessageExceptionList({ id, listId }), + statusCode: 404, }); - if (list == null) { - return siemResponse.error({ - body: getErrorMessageExceptionList({ id, listId }), - statusCode: 404, - }); - } else { - const [validated, errors] = validate(list, updateExceptionListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } - } } + + return response.ok({ body: UpdateExceptionListResponse.parse(list) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/utils/validate_comments_to_update.test.ts b/x-pack/plugins/lists/server/routes/utils/validate_comments_to_update.test.ts new file mode 100644 index 0000000000000..9e2909014d43b --- /dev/null +++ b/x-pack/plugins/lists/server/routes/utils/validate_comments_to_update.test.ts @@ -0,0 +1,30 @@ +/* + * 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 { validateCommentsToUpdate } from './validate_comments_to_update'; + +describe('update_exception_list_item_validation', () => { + describe('#validateComments', () => { + test('it returns no errors if new comments are append only', () => { + const comments = [{ comment: 'Im an old comment', id: '1' }, { comment: 'Im a new comment' }]; + const output = validateCommentsToUpdate(comments); + + expect(output).toEqual([]); + }); + + test('it returns error if comments are not append only', () => { + const comments = [ + { comment: 'Im an old comment', id: '1' }, + { comment: 'Im a new comment modifying the order of existing comments' }, + { comment: 'Im an old comment', id: '2' }, + ]; + const output = validateCommentsToUpdate(comments); + + expect(output).toEqual(['item "comments" are append only']); + }); + }); +}); diff --git a/x-pack/plugins/lists/server/routes/utils/validate_comments_to_update.ts b/x-pack/plugins/lists/server/routes/utils/validate_comments_to_update.ts new file mode 100644 index 0000000000000..7eda0ca4aaaec --- /dev/null +++ b/x-pack/plugins/lists/server/routes/utils/validate_comments_to_update.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { UpdateExceptionListItemCommentArray } from '@kbn/securitysolution-exceptions-common/api'; + +export const validateCommentsToUpdate = ( + comments: UpdateExceptionListItemCommentArray +): string[] => { + const [appendOnly] = comments.reduce( + (acc, comment) => { + const [, hasNewComments] = acc; + if (comment.id == null) { + return [true, true]; + } + + if (hasNewComments && comment.id != null) { + return [false, true]; + } + + return acc; + }, + [true, false] + ); + if (!appendOnly) { + return ['item "comments" are append only']; + } else { + return []; + } +}; diff --git a/x-pack/plugins/lists/tsconfig.json b/x-pack/plugins/lists/tsconfig.json index 8371f9de72c8c..784e8e27ef7d0 100644 --- a/x-pack/plugins/lists/tsconfig.json +++ b/x-pack/plugins/lists/tsconfig.json @@ -20,6 +20,7 @@ "@kbn/securitysolution-list-hooks", "@kbn/securitysolution-list-api", "@kbn/securitysolution-lists-common", + "@kbn/securitysolution-exceptions-common", "@kbn/kibana-react-plugin", "@kbn/i18n", "@kbn/data-plugin", diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_exceptions/api/create_rule_exceptions/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_exceptions/api/create_rule_exceptions/route.ts index 060043c14819f..22aa94ad80aee 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_exceptions/api/create_rule_exceptions/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_exceptions/api/create_rule_exceptions/route.ts @@ -5,44 +5,30 @@ * 2.0. */ -import * as t from 'io-ts'; - -import { fold } from 'fp-ts/lib/Either'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { identity } from 'fp-ts/lib/function'; - +import { v4 as uuidv4 } from 'uuid'; import { transformError } from '@kbn/securitysolution-es-utils'; -import type { - CreateExceptionListSchema, - CreateExceptionListSchemaDecoded, - CreateRuleExceptionListItemSchemaDecoded, - ExceptionListSchema, -} from '@kbn/securitysolution-io-ts-list-types'; -import { - createExceptionListSchema, - exceptionListItemSchema, - ExceptionListTypeEnum, -} from '@kbn/securitysolution-io-ts-list-types'; -import { formatErrors, validate } from '@kbn/securitysolution-io-ts-utils'; +import { ExceptionListTypeEnum } from '@kbn/securitysolution-io-ts-list-types'; import type { SanitizedRule } from '@kbn/alerting-plugin/common'; import type { ExceptionListClient } from '@kbn/lists-plugin/server'; - +import { buildRouteValidationWithZod, stringifyZodError } from '@kbn/zod-helpers'; import type { - CreateRuleExceptionsRequestBodyDecoded, - CreateRuleExceptionsRequestParamsDecoded, -} from '../../../../../../common/api/detection_engine/rule_exceptions'; + CreateRuleExceptionListItemProps, + ExceptionList, +} from '@kbn/securitysolution-exceptions-common/api'; import { - CREATE_RULE_EXCEPTIONS_URL, - CreateRuleExceptionsRequestBody, - CreateRuleExceptionsRequestParams, -} from '../../../../../../common/api/detection_engine/rule_exceptions'; + CreateExceptionListRequestBody, + CreateRuleExceptionListItemsRequestBody, + CreateRuleExceptionListItemsRequestParams, + CreateRuleExceptionListItemsResponse, +} from '@kbn/securitysolution-exceptions-common/api'; + +import { CREATE_RULE_EXCEPTIONS_URL } from '../../../../../../common/api/detection_engine/rule_exceptions'; import { readRules } from '../../../rule_management/logic/detection_rules_client/read_rules'; import { checkDefaultRuleExceptionListReferences } from '../../../rule_management/logic/exceptions/check_for_default_rule_exception_list'; import type { RuleParams } from '../../../rule_schema'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { buildSiemResponse } from '../../../routes/utils'; -import { buildRouteValidation } from '../../../../../utils/build_validation/route_validation'; import type { IDetectionRulesClient } from '../../../rule_management/logic/detection_rules_client/detection_rules_client_interface'; export const createRuleExceptionsRoute = (router: SecuritySolutionPluginRouter) => { @@ -59,14 +45,8 @@ export const createRuleExceptionsRoute = (router: SecuritySolutionPluginRouter) version: '2023-10-31', validate: { request: { - params: buildRouteValidation< - typeof CreateRuleExceptionsRequestParams, - CreateRuleExceptionsRequestParamsDecoded - >(CreateRuleExceptionsRequestParams), - body: buildRouteValidation< - typeof CreateRuleExceptionsRequestBody, - CreateRuleExceptionsRequestBodyDecoded - >(CreateRuleExceptionsRequestBody), + params: buildRouteValidationWithZod(CreateRuleExceptionListItemsRequestParams), + body: buildRouteValidationWithZod(CreateRuleExceptionListItemsRequestBody), }, }, }, @@ -109,12 +89,7 @@ export const createRuleExceptionsRoute = (router: SecuritySolutionPluginRouter) detectionRulesClient, }); - const [validated, errors] = validate(createdItems, t.array(exceptionListItemSchema)); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: CreateRuleExceptionListItemsResponse.parse(createdItems) }); } catch (err) { const error = transformError(err); return siemResponse.error({ @@ -132,7 +107,7 @@ export const createRuleExceptions = async ({ listsClient, detectionRulesClient, }: { - items: CreateRuleExceptionListItemSchemaDecoded[]; + items: CreateRuleExceptionListItemProps[]; listsClient: ExceptionListClient | null; detectionRulesClient: IDetectionRulesClient; rule: SanitizedRule; @@ -159,7 +134,7 @@ export const createRuleExceptions = async ({ if (exceptionListAssociatedToRule != null) { return createExceptionListItems({ items, - defaultList: exceptionListAssociatedToRule, + defaultList: exceptionListAssociatedToRule as ExceptionList, listsClient, }); } else { @@ -192,8 +167,8 @@ export const createExceptionListItems = async ({ defaultList, listsClient, }: { - items: CreateRuleExceptionListItemSchemaDecoded[]; - defaultList: ExceptionListSchema; + items: CreateRuleExceptionListItemProps[]; + defaultList: ExceptionList; listsClient: ExceptionListClient | null; }) => { return Promise.all( @@ -203,7 +178,7 @@ export const createExceptionListItems = async ({ description: item.description, entries: item.entries, expireTime: item.expire_time, - itemId: item.item_id, + itemId: item.item_id ?? uuidv4(), listId: defaultList.list_id, meta: item.meta, name: item.name, @@ -222,10 +197,10 @@ export const createExceptionList = async ({ }: { rule: SanitizedRule; listsClient: ExceptionListClient | null; -}): Promise => { +}): Promise => { if (!listsClient) return null; - const exceptionList: CreateExceptionListSchema = { + const exceptionList: CreateExceptionListRequestBody = { description: `Exception list containing exceptions for rule with id: ${rule.id}`, meta: undefined, name: `Exceptions for rule - ${rule.name}`, @@ -235,25 +210,22 @@ export const createExceptionList = async ({ version: 1, }; - // The `as` defeated me. Please send help - // if you know what's missing here. - const validated = pipe( - createExceptionListSchema.decode(exceptionList), - fold((errors) => { - throw new Error(formatErrors(errors).join()); - }, identity) - ) as CreateExceptionListSchemaDecoded; + const parseResult = CreateExceptionListRequestBody.safeParse(exceptionList); + + if (!parseResult.success) { + throw new Error(stringifyZodError(parseResult.error)); + } const { description, - list_id: listId, + list_id: listId = uuidv4(), meta, name, namespace_type: namespaceType, tags, type, version, - } = validated; + } = parseResult.data; // create the default rule list return listsClient.createExceptionList({ @@ -266,7 +238,7 @@ export const createExceptionList = async ({ tags, type, version, - }); + }) as Promise; }; export const createAndAssociateDefaultExceptionList = async ({ @@ -279,7 +251,7 @@ export const createAndAssociateDefaultExceptionList = async ({ listsClient: ExceptionListClient | null; detectionRulesClient: IDetectionRulesClient; removeOldAssociation: boolean; -}): Promise => { +}): Promise => { const exceptionListToAssociate = await createExceptionList({ rule, listsClient }); if (exceptionListToAssociate == null) { diff --git a/x-pack/plugins/security_solution/server/lib/exceptions/api/manage_exceptions/route.ts b/x-pack/plugins/security_solution/server/lib/exceptions/api/manage_exceptions/route.ts index 35dbfea0c2125..01a04a284b16a 100644 --- a/x-pack/plugins/security_solution/server/lib/exceptions/api/manage_exceptions/route.ts +++ b/x-pack/plugins/security_solution/server/lib/exceptions/api/manage_exceptions/route.ts @@ -6,14 +6,17 @@ */ import { v4 as uuidv4 } from 'uuid'; -import type { ExceptionListSchema } from '@kbn/securitysolution-io-ts-list-types'; import type { IKibanaResponse } from '@kbn/core/server'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import type { ExceptionList } from '@kbn/securitysolution-exceptions-common/api'; +import { + CreateSharedExceptionListRequestBody, + CreateSharedExceptionListResponse, +} from '@kbn/securitysolution-exceptions-common/api'; -import { CreateSharedExceptionListRequest } from '../../../../../common/api/detection_engine'; import { SHARED_EXCEPTION_LIST_URL } from '../../../../../common/constants'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { buildSiemResponse } from '../../../detection_engine/routes/utils'; -import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; export const createSharedExceptionListRoute = (router: SecuritySolutionPluginRouter) => { router.versioned @@ -29,14 +32,11 @@ export const createSharedExceptionListRoute = (router: SecuritySolutionPluginRou version: '2023-10-31', validate: { request: { - body: buildRouteValidation< - typeof CreateSharedExceptionListRequest, - CreateSharedExceptionListRequest - >(CreateSharedExceptionListRequest), + body: buildRouteValidationWithZod(CreateSharedExceptionListRequestBody), }, }, }, - async (context, request, response): Promise> => { + async (context, request, response): Promise> => { const siemResponse = buildSiemResponse(response); const { description, name } = request.body; @@ -60,7 +60,7 @@ export const createSharedExceptionListRoute = (router: SecuritySolutionPluginRou type: 'detection', version: 1, }); - return response.ok({ body: createdSharedList }); + return response.ok({ body: CreateSharedExceptionListResponse.parse(createdSharedList) }); } catch (exc) { return siemResponse.error({ body: exc.message, diff --git a/x-pack/plugins/security_solution/tsconfig.json b/x-pack/plugins/security_solution/tsconfig.json index 400efb61ae0aa..001a6e1b72d4b 100644 --- a/x-pack/plugins/security_solution/tsconfig.json +++ b/x-pack/plugins/security_solution/tsconfig.json @@ -15,11 +15,7 @@ "public/**/*.json", "../../../typings/**/*" ], - "exclude": [ - "target/**/*", - "**/cypress/**", - "public/management/cypress.config.ts" - ], + "exclude": ["target/**/*", "**/cypress/**", "public/management/cypress.config.ts"], "kbn_references": [ "@kbn/core", { @@ -93,6 +89,7 @@ "@kbn/core-http-browser-mocks", "@kbn/securitysolution-list-hooks", "@kbn/securitysolution-exception-list-components", + "@kbn/securitysolution-exceptions-common", "@kbn/rison", "@kbn/shared-ux-page-kibana-template", "@kbn/saved-objects-tagging-plugin", diff --git a/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/artifacts/trial_license_complete_tier/blocklists.ts b/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/artifacts/trial_license_complete_tier/blocklists.ts index 10cd447755c25..e483166e7f47c 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/artifacts/trial_license_complete_tier/blocklists.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/artifacts/trial_license_complete_tier/blocklists.ts @@ -203,7 +203,11 @@ export default function ({ getService }: FtrProviderContext) { .set('kbn-xsrf', 'true') .send(body) .expect(400) - .expect(anErrorMessageWith(/Invalid value \"\[\]\"/)); + .expect( + anErrorMessageWith( + '[request body]: entries.0.value: Array must contain at least 1 element(s)' + ) + ); }); it(`should error on [${blocklistApiCall.method}] if signer is set for a non windows os entry item`, async () => { diff --git a/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/lists/find_exception_lists.ts b/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/lists/find_exception_lists.ts index 3ffcad93b568e..31ece2f7a1a58 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/lists/find_exception_lists.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/lists/find_exception_lists.ts @@ -5,19 +5,17 @@ * 2.0. */ -import expect from '@kbn/expect'; +import expect from 'expect'; import { EXCEPTION_LIST_URL } from '@kbn/securitysolution-list-constants'; -import { getExceptionResponseMockWithoutAutoGeneratedValues } from '@kbn/lists-plugin/common/schemas/response/exception_list_schema.mock'; import { getCreateExceptionListMinimalSchemaMock } from '@kbn/lists-plugin/common/schemas/request/create_exception_list_schema.mock'; -import { deleteAllExceptions, removeExceptionListServerGeneratedProperties } from '../../../utils'; +import { deleteAllExceptions } from '../../../utils'; import { FtrProviderContext } from '../../../../../ftr_provider_context'; export default ({ getService }: FtrProviderContext): void => { const supertest = getService('supertest'); const log = getService('log'); - const utils = getService('securitySolutionUtils'); describe('@ess @serverless find_exception_lists', () => { describe('find exception lists', () => { @@ -32,7 +30,7 @@ export default ({ getService }: FtrProviderContext): void => { .send() .expect(200); - expect(body).to.eql({ + expect(body).toEqual({ data: [], page: 1, per_page: 20, @@ -55,9 +53,8 @@ export default ({ getService }: FtrProviderContext): void => { .send() .expect(200); - body.data = [removeExceptionListServerGeneratedProperties(body.data[0])]; - expect(body).to.eql({ - data: [getExceptionResponseMockWithoutAutoGeneratedValues(await utils.getUsername())], + expect(body).toEqual({ + data: [expect.objectContaining(getCreateExceptionListMinimalSchemaMock())], page: 1, per_page: 20, total: 1, From 85f5a4790ec003631358e8bbae8b4b5d43f22993 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Sat, 22 Jun 2024 07:45:44 +0200 Subject: [PATCH 04/15] enable Exceptions Common package PR pipeline code generation --- .../code_generation/security_solution_codegen.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh b/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh index 5a37c8a08d99a..63ed00a3513f9 100755 --- a/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh +++ b/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh @@ -6,17 +6,22 @@ source .buildkite/scripts/common/util.sh echo --- Security Solution OpenAPI Code Generation -echo OpenAPI Common Package +echo -e "\n[Security Solution OpenAPI Code Generation] OpenAPI Common Package" (cd packages/kbn-openapi-common && yarn openapi:generate) check_for_changed_files "yarn openapi:generate" true -echo Lists API Common Package +echo -e "\n[Security Solution OpenAPI Code Generation] Lists Common Package\n" (cd packages/kbn-securitysolution-lists-common && yarn openapi:generate) check_for_changed_files "yarn openapi:generate" true -echo Security Solution Plugin +echo -e "\n[Security Solution OpenAPI Code Generation] Exceptions Common Package" + +(cd packages/kbn-securitysolution-exceptions-common && yarn openapi:generate) +check_for_changed_files "yarn openapi:generate" true + +echo -e "\n[Security Solution OpenAPI Code Generation] Security Solution Plugin" (cd x-pack/plugins/security_solution && yarn openapi:generate) check_for_changed_files "yarn openapi:generate" true \ No newline at end of file From c5fc6e525deb211a7266188c2a1d705590ffd854 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Sat, 22 Jun 2024 07:45:56 +0200 Subject: [PATCH 05/15] generate test clients --- .../scripts/openapi_generate.js | 17 +- .../scripts/openapi_generate.js | 17 +- .../security_solution_exceptions.gen.ts | 247 +++++++++++++++++ .../services/security_solution_lists.gen.ts | 250 ++++++++++++++++++ 4 files changed, 529 insertions(+), 2 deletions(-) create mode 100644 x-pack/test/api_integration/services/security_solution_exceptions.gen.ts create mode 100644 x-pack/test/api_integration/services/security_solution_lists.gen.ts diff --git a/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js b/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js index 8d6e8b0bc5aba..f2211271e8a0a 100644 --- a/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js +++ b/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js @@ -7,8 +7,9 @@ */ require('../../../src/setup_node_env'); -const { resolve } = require('path'); +const { join, resolve } = require('path'); const { generate } = require('@kbn/openapi-generator'); +const { REPO_ROOT } = require('@kbn/repo-info'); const ROOT = resolve(__dirname, '..'); @@ -19,4 +20,18 @@ const ROOT = resolve(__dirname, '..'); sourceGlob: './**/*.schema.yaml', templateName: 'zod_operation_schema', }); + + await generate({ + title: 'Exceptions API client for tests', + rootDir: ROOT, + sourceGlob: './**/*.schema.yaml', + templateName: 'api_client_supertest', + skipLinting: true, + bundle: { + outFile: join( + REPO_ROOT, + 'x-pack/test/api_integration/services/security_solution_exceptions.gen.ts' + ), + }, + }); })(); diff --git a/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js b/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js index 8580994b16859..93da12e9867a9 100644 --- a/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js +++ b/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js @@ -7,8 +7,9 @@ */ require('../../../src/setup_node_env'); -const { resolve } = require('path'); +const { join, resolve } = require('path'); const { generate } = require('@kbn/openapi-generator'); +const { REPO_ROOT } = require('@kbn/repo-info'); const ROOT = resolve(__dirname, '..'); @@ -19,4 +20,18 @@ const ROOT = resolve(__dirname, '..'); sourceGlob: './**/*.schema.yaml', templateName: 'zod_operation_schema', }); + + await generate({ + title: 'Lists API client for tests', + rootDir: ROOT, + sourceGlob: './**/*.schema.yaml', + templateName: 'api_client_supertest', + skipLinting: true, + bundle: { + outFile: join( + REPO_ROOT, + 'x-pack/test/api_integration/services/security_solution_lists.gen.ts' + ), + }, + }); })(); diff --git a/x-pack/test/api_integration/services/security_solution_exceptions.gen.ts b/x-pack/test/api_integration/services/security_solution_exceptions.gen.ts new file mode 100644 index 0000000000000..3ad3383ec4969 --- /dev/null +++ b/x-pack/test/api_integration/services/security_solution_exceptions.gen.ts @@ -0,0 +1,247 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Exceptions API client for tests + * version: Bundle (no version) + */ + +import { + ELASTIC_HTTP_VERSION_HEADER, + X_ELASTIC_INTERNAL_ORIGIN_REQUEST, +} from '@kbn/core-http-common'; + +import { CreateExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen'; +import { CreateExceptionListItemRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen'; +import { + CreateRuleExceptionListItemsRequestParamsInput, + CreateRuleExceptionListItemsRequestBodyInput, +} from '@kbn/securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen'; +import { CreateSharedExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen'; +import { DeleteExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen'; +import { DeleteExceptionListItemRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen'; +import { DuplicateExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen'; +import { ExportExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen'; +import { FindExceptionListItemsRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen'; +import { FindExceptionListsRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen'; +import { GetExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen'; +import { GetExceptionListItemRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen'; +import { GetExceptionListSummaryRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen'; +import { ImportExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen'; +import { UpdateExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen'; +import { UpdateExceptionListItemRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen'; +import { FtrProviderContext } from '../ftr_provider_context'; + +export function SecuritySolutionApiProvider({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + return { + createExceptionList(props: CreateExceptionListProps) { + return supertest + .post('/api/exception_lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + createExceptionListItem(props: CreateExceptionListItemProps) { + return supertest + .post('/api/exception_lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + createRuleExceptionListItems(props: CreateRuleExceptionListItemsProps) { + return supertest + .post(replaceParams('/api/detection_engine/rules/{id}/exceptions', props.params)) + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + createSharedExceptionList(props: CreateSharedExceptionListProps) { + return supertest + .post('/api/exceptions/shared') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + deleteExceptionList(props: DeleteExceptionListProps) { + return supertest + .delete('/api/exception_lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + deleteExceptionListItem(props: DeleteExceptionListItemProps) { + return supertest + .delete('/api/exception_lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + duplicateExceptionList(props: DuplicateExceptionListProps) { + return supertest + .post('/api/exception_lists/_duplicate') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + /** + * Exports an exception list and its associated items to an .ndjson file + */ + exportExceptionList(props: ExportExceptionListProps) { + return supertest + .post('/api/exception_lists/_export') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + findExceptionListItems(props: FindExceptionListItemsProps) { + return supertest + .get('/api/exception_lists/items/_find') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + findExceptionLists(props: FindExceptionListsProps) { + return supertest + .get('/api/exception_lists/items/_find') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + getExceptionList(props: GetExceptionListProps) { + return supertest + .get('/api/exception_lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + getExceptionListItem(props: GetExceptionListItemProps) { + return supertest + .get('/api/exception_lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + getExceptionListSummary(props: GetExceptionListSummaryProps) { + return supertest + .get('/api/exception_lists/summary') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + /** + * Imports an exception list and associated items + */ + importExceptionList(props: ImportExceptionListProps) { + return supertest + .post('/api/exception_lists/_import') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + updateExceptionList(props: UpdateExceptionListProps) { + return supertest + .put('/api/exception_lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + updateExceptionListItem(props: UpdateExceptionListItemProps) { + return supertest + .put('/api/exception_lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + }; +} + +export interface CreateExceptionListProps { + body: CreateExceptionListRequestBodyInput; +} +export interface CreateExceptionListItemProps { + body: CreateExceptionListItemRequestBodyInput; +} +export interface CreateRuleExceptionListItemsProps { + params: CreateRuleExceptionListItemsRequestParamsInput; + body: CreateRuleExceptionListItemsRequestBodyInput; +} +export interface CreateSharedExceptionListProps { + body: CreateSharedExceptionListRequestBodyInput; +} +export interface DeleteExceptionListProps { + query: DeleteExceptionListRequestQueryInput; +} +export interface DeleteExceptionListItemProps { + query: DeleteExceptionListItemRequestQueryInput; +} +export interface DuplicateExceptionListProps { + query: DuplicateExceptionListRequestQueryInput; +} +export interface ExportExceptionListProps { + query: ExportExceptionListRequestQueryInput; +} +export interface FindExceptionListItemsProps { + query: FindExceptionListItemsRequestQueryInput; +} +export interface FindExceptionListsProps { + query: FindExceptionListsRequestQueryInput; +} +export interface GetExceptionListProps { + query: GetExceptionListRequestQueryInput; +} +export interface GetExceptionListItemProps { + query: GetExceptionListItemRequestQueryInput; +} +export interface GetExceptionListSummaryProps { + query: GetExceptionListSummaryRequestQueryInput; +} +export interface ImportExceptionListProps { + query: ImportExceptionListRequestQueryInput; +} +export interface UpdateExceptionListProps { + body: UpdateExceptionListRequestBodyInput; +} +export interface UpdateExceptionListItemProps { + body: UpdateExceptionListItemRequestBodyInput; +} + +/** + * Replaces placeholders in a path string with provided param value + * + * @param path Path string with placeholders for params + * @param params Object with params to replace + * @returns Path string with params replaced + */ +function replaceParams(path: string, params: Record): string { + let output = path; + Object.entries(params).forEach(([param, value]) => { + output = path.replace(`{${param}}`, `${value}`); + }); + return output; +} diff --git a/x-pack/test/api_integration/services/security_solution_lists.gen.ts b/x-pack/test/api_integration/services/security_solution_lists.gen.ts new file mode 100644 index 0000000000000..fa058606ff4b4 --- /dev/null +++ b/x-pack/test/api_integration/services/security_solution_lists.gen.ts @@ -0,0 +1,250 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Lists API client for tests + * version: Bundle (no version) + */ + +import { + ELASTIC_HTTP_VERSION_HEADER, + X_ELASTIC_INTERNAL_ORIGIN_REQUEST, +} from '@kbn/core-http-common'; + +import { CreateListRequestBodyInput } from '@kbn/securitysolution-lists-common/api/create_list/create_list.gen'; +import { CreateListItemRequestBodyInput } from '@kbn/securitysolution-lists-common/api/create_list_item/create_list_item.gen'; +import { DeleteListRequestQueryInput } from '@kbn/securitysolution-lists-common/api/delete_list/delete_list.gen'; +import { DeleteListItemRequestQueryInput } from '@kbn/securitysolution-lists-common/api/delete_list_item/delete_list_item.gen'; +import { ExportListItemsRequestQueryInput } from '@kbn/securitysolution-lists-common/api/export_list_item/export_list_item.gen'; +import { FindListItemsRequestQueryInput } from '@kbn/securitysolution-lists-common/api/find_list_item/find_list_item.gen'; +import { FindListsRequestQueryInput } from '@kbn/securitysolution-lists-common/api/find_list/find_list.gen'; +import { GetListRequestQueryInput } from '@kbn/securitysolution-lists-common/api/read_list/read_list.gen'; +import { GetListItemRequestQueryInput } from '@kbn/securitysolution-lists-common/api/read_list_item/read_list_item.gen'; +import { ImportListItemsRequestQueryInput } from '@kbn/securitysolution-lists-common/api/import_list_item/import_list_item.gen'; +import { PatchListRequestBodyInput } from '@kbn/securitysolution-lists-common/api/patch_list/patch_list.gen'; +import { PatchListItemRequestBodyInput } from '@kbn/securitysolution-lists-common/api/patch_list_item/patch_list_item.gen'; +import { UpdateListRequestBodyInput } from '@kbn/securitysolution-lists-common/api/update_list/update_list.gen'; +import { UpdateListItemRequestBodyInput } from '@kbn/securitysolution-lists-common/api/update_list_item/update_list_item.gen'; +import { FtrProviderContext } from '../ftr_provider_context'; + +export function SecuritySolutionApiProvider({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + return { + createList(props: CreateListProps) { + return supertest + .post('/api/lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + createListIndex() { + return supertest + .post('/api/lists/index') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana'); + }, + createListItem(props: CreateListItemProps) { + return supertest + .post('/api/lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + deleteList(props: DeleteListProps) { + return supertest + .delete('/api/lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + deleteListIndex() { + return supertest + .delete('/api/lists/index') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana'); + }, + deleteListItem(props: DeleteListItemProps) { + return supertest + .delete('/api/lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + /** + * Exports list item values from the specified list + */ + exportListItems(props: ExportListItemsProps) { + return supertest + .post('/api/lists/items/_export') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + findListItems(props: FindListItemsProps) { + return supertest + .get('/api/lists/_find') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + findLists(props: FindListsProps) { + return supertest + .get('/api/lists/_find') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + getList(props: GetListProps) { + return supertest + .get('/api/lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + getListIndex() { + return supertest + .get('/api/lists/index') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana'); + }, + getListItem(props: GetListItemProps) { + return supertest + .get('/api/lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + getListPrivileges() { + return supertest + .get('/api/lists/privileges') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana'); + }, + /** + * Imports a list of items from a `.txt` or `.csv` file. The maximum file size is 9 million bytes. + +You can import items to a new or existing list. + + */ + importListItems(props: ImportListItemsProps) { + return supertest + .post('/api/lists/items/_import') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .query(props.query); + }, + patchList(props: PatchListProps) { + return supertest + .patch('/api/lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + patchListItem(props: PatchListItemProps) { + return supertest + .patch('/api/lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + updateList(props: UpdateListProps) { + return supertest + .put('/api/lists') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + updateListItem(props: UpdateListItemProps) { + return supertest + .put('/api/lists/items') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') + .send(props.body as object); + }, + }; +} + +export interface CreateListProps { + body: CreateListRequestBodyInput; +} +export interface CreateListItemProps { + body: CreateListItemRequestBodyInput; +} +export interface DeleteListProps { + query: DeleteListRequestQueryInput; +} +export interface DeleteListItemProps { + query: DeleteListItemRequestQueryInput; +} +export interface ExportListItemsProps { + query: ExportListItemsRequestQueryInput; +} +export interface FindListItemsProps { + query: FindListItemsRequestQueryInput; +} +export interface FindListsProps { + query: FindListsRequestQueryInput; +} +export interface GetListProps { + query: GetListRequestQueryInput; +} +export interface GetListItemProps { + query: GetListItemRequestQueryInput; +} +export interface ImportListItemsProps { + query: ImportListItemsRequestQueryInput; +} +export interface PatchListProps { + body: PatchListRequestBodyInput; +} +export interface PatchListItemProps { + body: PatchListItemRequestBodyInput; +} +export interface UpdateListProps { + body: UpdateListRequestBodyInput; +} +export interface UpdateListItemProps { + body: UpdateListItemRequestBodyInput; +} + +/** + * Replaces placeholders in a path string with provided param value + * + * @param path Path string with placeholders for params + * @param params Object with params to replace + * @returns Path string with params replaced + */ +function replaceParams(path: string, params: Record): string { + let output = path; + Object.entries(params).forEach(([param, value]) => { + output = path.replace(`{${param}}`, `${value}`); + }); + return output; +} From a76046fdd7e451eb089083bd9988f6531e059411 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Sat, 22 Jun 2024 08:04:34 +0200 Subject: [PATCH 06/15] simply folded if's in lists API routes --- .../server/routes/list/create_list_route.ts | 54 ++++++++++--------- .../server/routes/list/delete_list_route.ts | 9 ++-- .../server/routes/list/patch_list_route.ts | 5 +- .../server/routes/list/read_list_route.ts | 5 +- .../server/routes/list/update_list_route.ts | 5 +- .../list_index/export_list_item_route.ts | 27 +++++----- .../routes/list_index/find_list_route.ts | 27 +++++----- .../list_item/create_list_item_route.ts | 51 +++++++++--------- .../list_item/delete_list_item_route.ts | 34 ++++++------ .../routes/list_item/find_list_item_route.ts | 39 +++++++------- .../routes/list_item/patch_list_item_route.ts | 5 +- .../routes/list_item/read_list_item_route.ts | 34 ++++++------ .../list_item/update_list_item_route.ts | 5 +- 13 files changed, 159 insertions(+), 141 deletions(-) diff --git a/x-pack/plugins/lists/server/routes/list/create_list_route.ts b/x-pack/plugins/lists/server/routes/list/create_list_route.ts index 3b0e80aa7ee7e..9b4714e14720c 100644 --- a/x-pack/plugins/lists/server/routes/list/create_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/create_list_route.ts @@ -46,34 +46,36 @@ export const createListRoute = (router: ListsPluginRouter): void => { body: `To create a list, the data stream must exist first. Data stream "${lists.getListName()}" does not exist`, statusCode: 400, }); - } else { - // needs to be migrated to data stream - if (!dataStreamExists && indexExists) { - await lists.migrateListIndexToDataStream(); - } - if (id != null) { - const list = await lists.getList({ id }); - if (list != null) { - return siemResponse.error({ - body: `list id: "${id}" already exists`, - statusCode: 409, - }); - } - } - const list = await lists.createList({ - description, - deserializer, - id, - immutable: false, - meta, - name, - serializer, - type, - version, - }); + } + + // needs to be migrated to data stream + if (!dataStreamExists && indexExists) { + await lists.migrateListIndexToDataStream(); + } - return response.ok({ body: CreateListResponse.parse(list) }); + if (id != null) { + const list = await lists.getList({ id }); + if (list != null) { + return siemResponse.error({ + body: `list id: "${id}" already exists`, + statusCode: 409, + }); + } } + + const list = await lists.createList({ + description, + deserializer, + id, + immutable: false, + meta, + name, + serializer, + type, + version, + }); + + return response.ok({ body: CreateListResponse.parse(list) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list/delete_list_route.ts b/x-pack/plugins/lists/server/routes/list/delete_list_route.ts index d28b777a2ba8e..66c8cb2ee4509 100644 --- a/x-pack/plugins/lists/server/routes/list/delete_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/delete_list_route.ts @@ -116,16 +116,17 @@ export const deleteListRoute = (router: ListsPluginRouter): void => { } const deleted = await lists.deleteList({ id }); + if (deleted == null) { return siemResponse.error({ body: `list id: "${id}" was not found`, statusCode: 404, }); - } else { - return response.ok({ - body: DeleteListResponse.parse(deleted), - }); } + + return response.ok({ + body: DeleteListResponse.parse(deleted), + }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list/patch_list_route.ts b/x-pack/plugins/lists/server/routes/list/patch_list_route.ts index fb14166d74f9c..90855ed96885a 100644 --- a/x-pack/plugins/lists/server/routes/list/patch_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/patch_list_route.ts @@ -48,14 +48,15 @@ export const patchListRoute = (router: ListsPluginRouter): void => { } const list = await lists.patchList({ _version, description, id, meta, name, version }); + if (list == null) { return siemResponse.error({ body: `list id: "${id}" not found`, statusCode: 404, }); - } else { - return response.ok({ body: PatchListResponse.parse(list) }); } + + return response.ok({ body: PatchListResponse.parse(list) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list/read_list_route.ts b/x-pack/plugins/lists/server/routes/list/read_list_route.ts index e9af8cfc8f4eb..5f4ecd5faeb76 100644 --- a/x-pack/plugins/lists/server/routes/list/read_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/read_list_route.ts @@ -38,14 +38,15 @@ export const readListRoute = (router: ListsPluginRouter): void => { const { id } = request.query; const lists = await getListClient(context); const list = await lists.getList({ id }); + if (list == null) { return siemResponse.error({ body: `list id: "${id}" does not exist`, statusCode: 404, }); - } else { - return response.ok({ body: GetListResponse.parse(list) }); } + + return response.ok({ body: GetListResponse.parse(list) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list/update_list_route.ts b/x-pack/plugins/lists/server/routes/list/update_list_route.ts index c20714b75e090..cf8e0dc4de83f 100644 --- a/x-pack/plugins/lists/server/routes/list/update_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/update_list_route.ts @@ -48,14 +48,15 @@ export const updateListRoute = (router: ListsPluginRouter): void => { } const list = await lists.updateList({ _version, description, id, meta, name, version }); + if (list == null) { return siemResponse.error({ body: `list id: "${id}" not found`, statusCode: 404, }); - } else { - return response.ok({ body: UpdateListResponse.parse(list) }); } + + return response.ok({ body: UpdateListResponse.parse(list) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list_index/export_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_index/export_list_item_route.ts index af9c40117f9c6..94cacc2f89c40 100644 --- a/x-pack/plugins/lists/server/routes/list_index/export_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_index/export_list_item_route.ts @@ -40,25 +40,26 @@ export const exportListItemRoute = (router: ListsPluginRouter): void => { const { list_id: listId } = request.query; const lists = await getListClient(context); const list = await lists.getList({ id: listId }); + if (list == null) { return siemResponse.error({ body: `list_id: ${listId} does not exist`, statusCode: 400, }); - } else { - // TODO: Allow the API to override the name of the file to export - const fileName = list.name; - - const stream = new Stream.PassThrough(); - lists.exportListItemsToStream({ listId, stream, stringToAppend: '\n' }); - return response.ok({ - body: stream, - headers: { - 'Content-Disposition': `attachment; filename="${fileName}"`, - 'Content-Type': 'application/ndjson', - }, - }); } + + // TODO: Allow the API to override the name of the file to export + const fileName = list.name; + + const stream = new Stream.PassThrough(); + lists.exportListItemsToStream({ listId, stream, stringToAppend: '\n' }); + return response.ok({ + body: stream, + headers: { + 'Content-Disposition': `attachment; filename="${fileName}"`, + 'Content-Type': 'application/ndjson', + }, + }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list_index/find_list_route.ts b/x-pack/plugins/lists/server/routes/list_index/find_list_route.ts index 157b11e3832eb..2bdbcc5239363 100644 --- a/x-pack/plugins/lists/server/routes/list_index/find_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list_index/find_list_route.ts @@ -58,25 +58,26 @@ export const findListRoute = (router: ListsPluginRouter): void => { perPage, sortField, }); + if (!isValid) { return siemResponse.error({ body: errorMessage, statusCode: 400, }); - } else { - const exceptionList = await lists.findList({ - currentIndexPosition, - filter, - page, - perPage, - runtimeMappings: undefined, - searchAfter, - sortField, - sortOrder, - }); - - return response.ok({ body: FindListsResponse.parse(exceptionList) }); } + + const exceptionList = await lists.findList({ + currentIndexPosition, + filter, + page, + perPage, + runtimeMappings: undefined, + searchAfter, + sortField, + sortOrder, + }); + + return response.ok({ body: FindListsResponse.parse(exceptionList) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list_item/create_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/create_list_item_route.ts index 2f8bd2738ae0f..e5b1b15ef10d4 100644 --- a/x-pack/plugins/lists/server/routes/list_item/create_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/create_list_item_route.ts @@ -41,41 +41,42 @@ export const createListItemRoute = (router: ListsPluginRouter): void => { const { id, list_id: listId, value, meta, refresh } = request.body; const lists = await getListClient(context); const list = await lists.getList({ id: listId }); + if (list == null) { return siemResponse.error({ body: `list id: "${listId}" does not exist`, statusCode: 404, }); - } else { - if (id != null) { - const listItem = await lists.getListItem({ id }); - if (listItem != null) { - return siemResponse.error({ - body: `list item id: "${id}" already exists`, - statusCode: 409, - }); - } - } - const createdListItem = await lists.createListItem({ - deserializer: list.deserializer, - id, - listId, - meta, - refresh, - serializer: list.serializer, - type: list.type, - value, - }); + } - if (createdListItem != null) { - return response.ok({ body: CreateListItemResponse.parse(createdListItem) }); - } else { + if (id != null) { + const listItem = await lists.getListItem({ id }); + if (listItem != null) { return siemResponse.error({ - body: 'list item invalid', - statusCode: 400, + body: `list item id: "${id}" already exists`, + statusCode: 409, }); } } + const createdListItem = await lists.createListItem({ + deserializer: list.deserializer, + id, + listId, + meta, + refresh, + serializer: list.serializer, + type: list.type, + value, + }); + + if (createdListItem != null) { + return response.ok({ body: CreateListItemResponse.parse(createdListItem) }); + } else { + return siemResponse.error({ + body: 'list item invalid', + statusCode: 400, + }); + } } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list_item/delete_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/delete_list_item_route.ts index 2cf30a61988b0..4cf9dd4d96911 100644 --- a/x-pack/plugins/lists/server/routes/list_item/delete_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/delete_list_item_route.ts @@ -48,32 +48,34 @@ export const deleteListItemRoute = (router: ListsPluginRouter): void => { body: `list item with id: "${id}" not found`, statusCode: 404, }); - } else { - return response.ok({ body: DeleteListItemResponse.parse(deleted) }); } + + return response.ok({ body: DeleteListItemResponse.parse(deleted) }); } else if (listId != null && value != null) { const list = await lists.getList({ id: listId }); + if (list == null) { return siemResponse.error({ body: `list_id: "${listId}" does not exist`, statusCode: 404, }); - } else { - const deleted = await lists.deleteListItemByValue({ - listId, - refresh: shouldRefresh, - type: list.type, - value, + } + + const deleted = await lists.deleteListItemByValue({ + listId, + refresh: shouldRefresh, + type: list.type, + value, + }); + + if (deleted == null || deleted.length === 0) { + return siemResponse.error({ + body: `list_id: "${listId}" with ${value} was not found`, + statusCode: 404, }); - if (deleted == null || deleted.length === 0) { - return siemResponse.error({ - body: `list_id: "${listId}" with ${value} was not found`, - statusCode: 404, - }); - } else { - return response.ok({ body: DeleteListItemResponse.parse(deleted) }); - } } + + return response.ok({ body: DeleteListItemResponse.parse(deleted) }); } else { return siemResponse.error({ body: 'Either "list_id" or "id" needs to be defined in the request', diff --git a/x-pack/plugins/lists/server/routes/list_item/find_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/find_list_item_route.ts index f65b678e36242..6bfd673f8fbc0 100644 --- a/x-pack/plugins/lists/server/routes/list_item/find_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/find_list_item_route.ts @@ -68,27 +68,28 @@ export const findListItemRoute = (router: ListsPluginRouter): void => { body: errorMessage, statusCode: 400, }); - } else { - const exceptionList = await lists.findListItem({ - currentIndexPosition, - filter, - listId, - page, - perPage, - runtimeMappings: undefined, - searchAfter, - sortField, - sortOrder, + } + + const exceptionList = await lists.findListItem({ + currentIndexPosition, + filter, + listId, + page, + perPage, + runtimeMappings: undefined, + searchAfter, + sortField, + sortOrder, + }); + + if (exceptionList == null) { + return siemResponse.error({ + body: `list id: "${listId}" does not exist`, + statusCode: 404, }); - if (exceptionList == null) { - return siemResponse.error({ - body: `list id: "${listId}" does not exist`, - statusCode: 404, - }); - } else { - return response.ok({ body: FindListItemsResponse.parse(exceptionList) }); - } } + + return response.ok({ body: FindListItemsResponse.parse(exceptionList) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list_item/patch_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/patch_list_item_route.ts index 68c82e93fcc38..3545516e17f3c 100644 --- a/x-pack/plugins/lists/server/routes/list_item/patch_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/patch_list_item_route.ts @@ -58,14 +58,15 @@ export const patchListItemRoute = (router: ListsPluginRouter): void => { refresh: shouldRefresh, value, }); + if (listItem == null) { return siemResponse.error({ body: `list item id: "${id}" not found`, statusCode: 404, }); - } else { - return response.ok({ body: PatchListItemResponse.parse(listItem) }); } + + return response.ok({ body: PatchListItemResponse.parse(listItem) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list_item/read_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/read_list_item_route.ts index 0e6a9dbe50155..8be3daa68eb49 100644 --- a/x-pack/plugins/lists/server/routes/list_item/read_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/read_list_item_route.ts @@ -40,38 +40,42 @@ export const readListItemRoute = (router: ListsPluginRouter): void => { try { const { id, list_id: listId, value } = request.query; const lists = await getListClient(context); + if (id != null) { const listItem = await lists.getListItem({ id }); + if (listItem == null) { return siemResponse.error({ body: `list item id: "${id}" does not exist`, statusCode: 404, }); - } else { - return response.ok({ body: GetListItemResponse.parse(listItem) }); } + + return response.ok({ body: GetListItemResponse.parse(listItem) }); } else if (listId != null && value != null) { const list = await lists.getList({ id: listId }); + if (list == null) { return siemResponse.error({ body: `list id: "${listId}" does not exist`, statusCode: 404, }); - } else { - const listItem = await lists.getListItemByValue({ - listId, - type: list.type, - value, + } + + const listItem = await lists.getListItemByValue({ + listId, + type: list.type, + value, + }); + + if (listItem.length === 0) { + return siemResponse.error({ + body: `list_id: "${listId}" item of ${value} does not exist`, + statusCode: 404, }); - if (listItem.length === 0) { - return siemResponse.error({ - body: `list_id: "${listId}" item of ${value} does not exist`, - statusCode: 404, - }); - } else { - return response.ok({ body: GetListItemResponse.parse(listItem) }); - } } + + return response.ok({ body: GetListItemResponse.parse(listItem) }); } else { return siemResponse.error({ body: 'Either "list_id" or "id" needs to be defined in the request', diff --git a/x-pack/plugins/lists/server/routes/list_item/update_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/update_list_item_route.ts index 8b2c4f65e54eb..408391ca63f11 100644 --- a/x-pack/plugins/lists/server/routes/list_item/update_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/update_list_item_route.ts @@ -56,14 +56,15 @@ export const updateListItemRoute = (router: ListsPluginRouter): void => { meta, value, }); + if (listItem == null) { return siemResponse.error({ body: `list item id: "${id}" not found`, statusCode: 404, }); - } else { - return response.ok({ body: UpdateListItemResponse.parse(listItem) }); } + + return response.ok({ body: UpdateListItemResponse.parse(listItem) }); } catch (err) { const error = transformError(err); return siemResponse.error({ From 353a6a2aba75cdabffd10f7cd9f8c727e99f9d74 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Sat, 22 Jun 2024 10:03:42 +0200 Subject: [PATCH 07/15] update deps --- x-pack/test/tsconfig.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 7c5161a915227..343575f2762ce 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -2,10 +2,7 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "target/types", - "types": [ - "node", - "@kbn/ambient-ftr-types" - ], + "types": ["node", "@kbn/ambient-ftr-types"], // there is still a decent amount of JS in this plugin and we are taking // advantage of the fact that TS doesn't know the types of that code and // gives us `any`. Once that code is converted to .ts we can remove this @@ -173,6 +170,8 @@ "@kbn/reporting-server", "@kbn/data-quality-plugin", "@kbn/securitysolution-io-ts-list-types", - "@kbn/ml-trained-models-utils" + "@kbn/ml-trained-models-utils", + "@kbn/securitysolution-exceptions-common", + "@kbn/securitysolution-lists-common" ] } From 862f51b984ebb7d4d167165da1268caec0f38b20 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Sat, 22 Jun 2024 14:30:18 +0200 Subject: [PATCH 08/15] fix a problem of unused replaceParams helper in API client --- packages/kbn-openapi-common/shared/index.ts | 9 ++++ .../shared/path_params_replacer.ts | 22 +++++++++ .../templates/api_client_supertest.handlebars | 16 +----- .../scripts/openapi_generate.js | 2 +- .../scripts/openapi_generate.js | 2 +- .../services/security_solution_api.gen.ts | 16 +----- ...> security_solution_exceptions_api.gen.ts} | 49 +++++++------------ ....ts => security_solution_lists_api.gen.ts} | 15 ------ x-pack/test/tsconfig.json | 6 +++ 9 files changed, 59 insertions(+), 78 deletions(-) create mode 100644 packages/kbn-openapi-common/shared/index.ts create mode 100644 packages/kbn-openapi-common/shared/path_params_replacer.ts rename x-pack/test/api_integration/services/{security_solution_exceptions.gen.ts => security_solution_exceptions_api.gen.ts} (73%) rename x-pack/test/api_integration/services/{security_solution_lists.gen.ts => security_solution_lists_api.gen.ts} (94%) diff --git a/packages/kbn-openapi-common/shared/index.ts b/packages/kbn-openapi-common/shared/index.ts new file mode 100644 index 0000000000000..98c43c700fca0 --- /dev/null +++ b/packages/kbn-openapi-common/shared/index.ts @@ -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 * from './path_params_replacer'; diff --git a/packages/kbn-openapi-common/shared/path_params_replacer.ts b/packages/kbn-openapi-common/shared/path_params_replacer.ts new file mode 100644 index 0000000000000..3716a818633ad --- /dev/null +++ b/packages/kbn-openapi-common/shared/path_params_replacer.ts @@ -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. + */ + +/** + * Replaces placeholders in a path string with provided param value + * + * @param path Path string with placeholders for params + * @param params Object with params to replace + * @returns Path string with params replaced + */ +export function replaceParams(path: string, params: Record): string { + let output = path; + Object.entries(params).forEach(([param, value]) => { + output = path.replace(`{${param}}`, `${value}`); + }); + return output; +} diff --git a/packages/kbn-openapi-generator/src/template_service/templates/api_client_supertest.handlebars b/packages/kbn-openapi-generator/src/template_service/templates/api_client_supertest.handlebars index 2fc51fb5de6a7..a51be66f1019b 100644 --- a/packages/kbn-openapi-generator/src/template_service/templates/api_client_supertest.handlebars +++ b/packages/kbn-openapi-generator/src/template_service/templates/api_client_supertest.handlebars @@ -8,6 +8,7 @@ {{> disclaimer}} import { ELASTIC_HTTP_VERSION_HEADER, X_ELASTIC_INTERNAL_ORIGIN_REQUEST } from '@kbn/core-http-common'; +import { replaceParams } from '@kbn/openapi-common/shared'; import { FtrProviderContext } from 'x-pack/test/api_integration/ftr_provider_context'; {{#each operations}} @@ -50,18 +51,3 @@ export interface {{operationId}}Props { } {{/if}} {{/each}} - -/** - * Replaces placeholders in a path string with provided param value - * - * @param path Path string with placeholders for params - * @param params Object with params to replace - * @returns Path string with params replaced - */ -function replaceParams(path: string, params: Record): string { - let output = path; - Object.entries(params).forEach(([param, value]) => { - output = path.replace(`{${param}}`, `${value}`); - }); - return output; -} \ No newline at end of file diff --git a/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js b/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js index f2211271e8a0a..9dd381501dc2b 100644 --- a/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js +++ b/packages/kbn-securitysolution-exceptions-common/scripts/openapi_generate.js @@ -30,7 +30,7 @@ const ROOT = resolve(__dirname, '..'); bundle: { outFile: join( REPO_ROOT, - 'x-pack/test/api_integration/services/security_solution_exceptions.gen.ts' + 'x-pack/test/api_integration/services/security_solution_exceptions_api.gen.ts' ), }, }); diff --git a/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js b/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js index 93da12e9867a9..49bd2860befd6 100644 --- a/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js +++ b/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js @@ -30,7 +30,7 @@ const ROOT = resolve(__dirname, '..'); bundle: { outFile: join( REPO_ROOT, - 'x-pack/test/api_integration/services/security_solution_lists.gen.ts' + 'x-pack/test/api_integration/services/security_solution_lists_api.gen.ts' ), }, }); diff --git a/x-pack/test/api_integration/services/security_solution_api.gen.ts b/x-pack/test/api_integration/services/security_solution_api.gen.ts index 31e9c38263a24..bc080f46906e9 100644 --- a/x-pack/test/api_integration/services/security_solution_api.gen.ts +++ b/x-pack/test/api_integration/services/security_solution_api.gen.ts @@ -18,6 +18,7 @@ import { ELASTIC_HTTP_VERSION_HEADER, X_ELASTIC_INTERNAL_ORIGIN_REQUEST, } from '@kbn/core-http-common'; +import { replaceParams } from '@kbn/openapi-common/shared'; import { AlertsMigrationCleanupRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/signals_migration/delete_signals_migration/delete_signals_migration.gen'; import { BulkCreateRulesRequestBodyInput } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_management/bulk_crud/bulk_create_rules/bulk_create_rules_route.gen'; @@ -575,18 +576,3 @@ export interface SuggestUserProfilesProps { export interface UpdateRuleProps { body: UpdateRuleRequestBodyInput; } - -/** - * Replaces placeholders in a path string with provided param value - * - * @param path Path string with placeholders for params - * @param params Object with params to replace - * @returns Path string with params replaced - */ -function replaceParams(path: string, params: Record): string { - let output = path; - Object.entries(params).forEach(([param, value]) => { - output = path.replace(`{${param}}`, `${value}`); - }); - return output; -} diff --git a/x-pack/test/api_integration/services/security_solution_exceptions.gen.ts b/x-pack/test/api_integration/services/security_solution_exceptions_api.gen.ts similarity index 73% rename from x-pack/test/api_integration/services/security_solution_exceptions.gen.ts rename to x-pack/test/api_integration/services/security_solution_exceptions_api.gen.ts index 3ad3383ec4969..f83678a95cab6 100644 --- a/x-pack/test/api_integration/services/security_solution_exceptions.gen.ts +++ b/x-pack/test/api_integration/services/security_solution_exceptions_api.gen.ts @@ -18,26 +18,28 @@ import { ELASTIC_HTTP_VERSION_HEADER, X_ELASTIC_INTERNAL_ORIGIN_REQUEST, } from '@kbn/core-http-common'; +import { replaceParams } from '@kbn/openapi-common/shared'; -import { CreateExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen'; -import { CreateExceptionListItemRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen'; +import { CreateExceptionListRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen'; +import { CreateExceptionListItemRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen'; import { CreateRuleExceptionListItemsRequestParamsInput, CreateRuleExceptionListItemsRequestBodyInput, -} from '@kbn/securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen'; -import { CreateSharedExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen'; -import { DeleteExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen'; -import { DeleteExceptionListItemRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen'; -import { DuplicateExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen'; -import { ExportExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen'; -import { FindExceptionListItemsRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen'; -import { FindExceptionListsRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen'; -import { GetExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen'; -import { GetExceptionListItemRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen'; -import { GetExceptionListSummaryRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen'; -import { ImportExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen'; -import { UpdateExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen'; -import { UpdateExceptionListItemRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen'; +} from '../../../../packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen'; +import { CreateSharedExceptionListRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen'; +import { DeleteExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen'; +import { DeleteExceptionListItemRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen'; +import { DuplicateExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen'; +import { ExportExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen'; +import { FindExceptionListItemsRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen'; +import { FindExceptionListsRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen'; +import { GetExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen'; +import { GetExceptionListItemRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen'; +import { GetExceptionListSummaryRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen'; +import { ImportExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen'; +import { UpdateExceptionListRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen'; +import { UpdateExceptionListItemRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen'; + import { FtrProviderContext } from '../ftr_provider_context'; export function SecuritySolutionApiProvider({ getService }: FtrProviderContext) { @@ -230,18 +232,3 @@ export interface UpdateExceptionListProps { export interface UpdateExceptionListItemProps { body: UpdateExceptionListItemRequestBodyInput; } - -/** - * Replaces placeholders in a path string with provided param value - * - * @param path Path string with placeholders for params - * @param params Object with params to replace - * @returns Path string with params replaced - */ -function replaceParams(path: string, params: Record): string { - let output = path; - Object.entries(params).forEach(([param, value]) => { - output = path.replace(`{${param}}`, `${value}`); - }); - return output; -} diff --git a/x-pack/test/api_integration/services/security_solution_lists.gen.ts b/x-pack/test/api_integration/services/security_solution_lists_api.gen.ts similarity index 94% rename from x-pack/test/api_integration/services/security_solution_lists.gen.ts rename to x-pack/test/api_integration/services/security_solution_lists_api.gen.ts index fa058606ff4b4..4f201d868e92c 100644 --- a/x-pack/test/api_integration/services/security_solution_lists.gen.ts +++ b/x-pack/test/api_integration/services/security_solution_lists_api.gen.ts @@ -233,18 +233,3 @@ export interface UpdateListProps { export interface UpdateListItemProps { body: UpdateListItemRequestBodyInput; } - -/** - * Replaces placeholders in a path string with provided param value - * - * @param path Path string with placeholders for params - * @param params Object with params to replace - * @returns Path string with params replaced - */ -function replaceParams(path: string, params: Record): string { - let output = path; - Object.entries(params).forEach(([param, value]) => { - output = path.replace(`{${param}}`, `${value}`); - }); - return output; -} diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 343575f2762ce..c362343fbccef 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -169,9 +169,15 @@ "@kbn/alerting-state-types", "@kbn/reporting-server", "@kbn/data-quality-plugin", +<<<<<<< HEAD "@kbn/securitysolution-io-ts-list-types", "@kbn/ml-trained-models-utils", "@kbn/securitysolution-exceptions-common", "@kbn/securitysolution-lists-common" +======= + "@kbn/openapi-common", + "@kbn/securitysolution-lists-common", + "@kbn/securitysolution-exceptions-common" +>>>>>>> 1b41cda820b (fix a problem of unused replaceParams helper in API client) ] } From be4fe8a8d2861889b168965c068c66df1cf795fa Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Sat, 22 Jun 2024 21:20:39 +0200 Subject: [PATCH 09/15] fix generated exceptions API client --- .../security_solution_exceptions_api.gen.ts | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/x-pack/test/api_integration/services/security_solution_exceptions_api.gen.ts b/x-pack/test/api_integration/services/security_solution_exceptions_api.gen.ts index f83678a95cab6..af4cad1edc90c 100644 --- a/x-pack/test/api_integration/services/security_solution_exceptions_api.gen.ts +++ b/x-pack/test/api_integration/services/security_solution_exceptions_api.gen.ts @@ -20,26 +20,25 @@ import { } from '@kbn/core-http-common'; import { replaceParams } from '@kbn/openapi-common/shared'; -import { CreateExceptionListRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen'; -import { CreateExceptionListItemRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen'; +import { CreateExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_exception_list/create_exception_list.gen'; +import { CreateExceptionListItemRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen'; import { CreateRuleExceptionListItemsRequestParamsInput, CreateRuleExceptionListItemsRequestBodyInput, -} from '../../../../packages/kbn-securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen'; -import { CreateSharedExceptionListRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen'; -import { DeleteExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen'; -import { DeleteExceptionListItemRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen'; -import { DuplicateExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen'; -import { ExportExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen'; -import { FindExceptionListItemsRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen'; -import { FindExceptionListsRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen'; -import { GetExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen'; -import { GetExceptionListItemRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen'; -import { GetExceptionListSummaryRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen'; -import { ImportExceptionListRequestQueryInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen'; -import { UpdateExceptionListRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen'; -import { UpdateExceptionListItemRequestBodyInput } from '../../../../packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen'; - +} from '@kbn/securitysolution-exceptions-common/api/create_rule_exceptions/create_rule_exceptions.gen'; +import { CreateSharedExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/create_shared_exceptions_list/create_shared_exceptions_list.gen'; +import { DeleteExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/delete_exception_list/delete_exception_list.gen'; +import { DeleteExceptionListItemRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/delete_exception_list_item/delete_exception_list_item.gen'; +import { DuplicateExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/duplicate_exception_list/duplicate_exception_list.gen'; +import { ExportExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/export_exception_list/export_exception_list.gen'; +import { FindExceptionListItemsRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen'; +import { FindExceptionListsRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen'; +import { GetExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/read_exception_list/read_exception_list.gen'; +import { GetExceptionListItemRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/read_exception_list_item/read_exception_list_item.gen'; +import { GetExceptionListSummaryRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/summary_exception_list/summary_exception_list.gen'; +import { ImportExceptionListRequestQueryInput } from '@kbn/securitysolution-exceptions-common/api/import_exceptions/import_exceptions.gen'; +import { UpdateExceptionListRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/update_exception_list/update_exception_list.gen'; +import { UpdateExceptionListItemRequestBodyInput } from '@kbn/securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen'; import { FtrProviderContext } from '../ftr_provider_context'; export function SecuritySolutionApiProvider({ getService }: FtrProviderContext) { From f3cfb599fa62c3ff32d3ea5a0d4629f33d5db00e Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Tue, 9 Jul 2024 09:05:05 +0200 Subject: [PATCH 10/15] use string instead of NonEmptyString where necessary --- .../api/find_exception_list/find_exception_list.gen.ts | 5 ++--- .../api/find_exception_list/find_exception_list.schema.yaml | 4 ++-- .../api/model/exception_list_common.gen.ts | 4 ++-- .../api/model/exception_list_common.schema.yaml | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts index de28bfabd023e..641aa9ed39a65 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts @@ -18,11 +18,10 @@ import { z } from 'zod'; import { ArrayFromString } from '@kbn/zod-helpers'; -import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; import { ExceptionNamespaceType, ExceptionList } from '../model/exception_list_common.gen'; export type FindExceptionListsFilter = z.infer; -export const FindExceptionListsFilter = NonEmptyString; +export const FindExceptionListsFilter = z.string(); export type FindExceptionListsRequestQuery = z.infer; export const FindExceptionListsRequestQuery = z.object({ @@ -53,7 +52,7 @@ or available in all spaces (`agnostic` or `single`) /** * Determines which field is used to sort the results */ - sort_field: NonEmptyString.optional(), + sort_field: z.string().optional(), /** * Determines the sort order, which can be `desc` or `asc` */ diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml index 86bed1e556afb..0f7d798c191b8 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml @@ -54,7 +54,7 @@ paths: required: false description: Determines which field is used to sort the results schema: - $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + type: string - name: sort_order in: query required: false @@ -118,4 +118,4 @@ paths: components: schemas: FindExceptionListsFilter: - $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + type: string diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts index 01990ea698798..360e4ec747d85 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.gen.ts @@ -43,7 +43,7 @@ export type ExceptionListTypeEnum = typeof ExceptionListType.enum; export const ExceptionListTypeEnum = ExceptionListType.enum; export type ExceptionListName = z.infer; -export const ExceptionListName = NonEmptyString; +export const ExceptionListName = z.string(); export type ExceptionListDescription = z.infer; export const ExceptionListDescription = z.string(); @@ -65,7 +65,7 @@ export type ExceptionNamespaceTypeEnum = typeof ExceptionNamespaceType.enum; export const ExceptionNamespaceTypeEnum = ExceptionNamespaceType.enum; export type ExceptionListTags = z.infer; -export const ExceptionListTags = z.array(NonEmptyString); +export const ExceptionListTags = z.array(z.string()); export type ExceptionListOsType = z.infer; export const ExceptionListOsType = z.enum(['linux', 'macos', 'windows']); diff --git a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml index d0cb8be84d1fd..ebcecc9c916f7 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/model/exception_list_common.schema.yaml @@ -25,7 +25,7 @@ components: - endpoint_blocklists ExceptionListName: - $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + type: string ExceptionListDescription: type: string @@ -49,7 +49,7 @@ components: ExceptionListTags: type: array items: - $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + type: string ExceptionListOsType: type: string From e43b80c9f01b5191e1a215f10b68e02bed453dcc Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Tue, 9 Jul 2024 09:34:25 +0200 Subject: [PATCH 11/15] use only positive integers for pagination fields --- .../api/find_exception_list/find_exception_list.gen.ts | 8 ++++---- .../find_exception_list/find_exception_list.schema.yaml | 8 ++++---- .../find_exception_list_item.gen.ts | 4 ++-- .../find_exception_list_item.schema.yaml | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts index 641aa9ed39a65..6ae1aef1f15df 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.gen.ts @@ -44,11 +44,11 @@ or available in all spaces (`agnostic` or `single`) /** * The page number to return */ - page: z.coerce.number().int().min(0).optional(), + page: z.coerce.number().int().min(1).optional(), /** * The number of exception lists to return per page */ - per_page: z.coerce.number().int().min(0).optional(), + per_page: z.coerce.number().int().min(1).optional(), /** * Determines which field is used to sort the results */ @@ -63,7 +63,7 @@ export type FindExceptionListsRequestQueryInput = z.input; export const FindExceptionListsResponse = z.object({ data: z.array(ExceptionList), - page: z.number().int().min(0), - per_page: z.number().int().min(0), + page: z.number().int().min(1), + per_page: z.number().int().min(1), total: z.number().int().min(0), }); diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml index 0f7d798c191b8..280831939b838 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list/find_exception_list.schema.yaml @@ -41,14 +41,14 @@ paths: description: The page number to return schema: type: integer - minimum: 0 + minimum: 1 - name: per_page in: query required: false description: The number of exception lists to return per page schema: type: integer - minimum: 0 + minimum: 1 - name: sort_field in: query required: false @@ -76,10 +76,10 @@ paths: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionList' page: type: integer - minimum: 0 + minimum: 1 per_page: type: integer - minimum: 0 + minimum: 1 total: type: integer minimum: 0 diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts index 125bb23311385..8342bcdf2b5fc 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts @@ -71,8 +71,8 @@ export type FindExceptionListItemsRequestQueryInput = z.input< export type FindExceptionListItemsResponse = z.infer; export const FindExceptionListItemsResponse = z.object({ data: z.array(ExceptionListItem), - page: z.number().int().min(0), - per_page: z.number().int().min(0), + page: z.number().int().min(1), + per_page: z.number().int().min(1), total: z.number().int().min(0), pit: z.string().optional(), }); diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml index c5b65bd27389c..617d4c98e53d7 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml @@ -88,10 +88,10 @@ paths: $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItem' page: type: integer - minimum: 0 + minimum: 1 per_page: type: integer - minimum: 0 + minimum: 1 total: type: integer minimum: 0 From 957a5ef8385d91e44899c9202fe21b060b283891 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Wed, 10 Jul 2024 07:01:51 +0200 Subject: [PATCH 12/15] fix description's misprint --- .../find_exception_list_item/find_exception_list_item.gen.ts | 2 +- .../find_exception_list_item.schema.yaml | 2 +- .../api/find_list_item/find_list_item.gen.ts | 2 +- .../api/find_list_item/find_list_item.schema.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts index 8342bcdf2b5fc..3c89952682847 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.gen.ts @@ -31,7 +31,7 @@ export const FindExceptionListItemsFilter = NonEmptyString; export type FindExceptionListItemsRequestQuery = z.infer; export const FindExceptionListItemsRequestQuery = z.object({ /** - * List's ide + * List's id */ list_id: ArrayFromString(ExceptionListHumanId), /** diff --git a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml index 617d4c98e53d7..2fae12499d513 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/find_exception_list_item/find_exception_list_item.schema.yaml @@ -15,7 +15,7 @@ paths: - name: list_id in: query required: true - description: List's ide + description: List's id schema: type: array items: diff --git a/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.gen.ts index 6288ece0cf179..adc9574833813 100644 --- a/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.gen.ts +++ b/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.gen.ts @@ -30,7 +30,7 @@ export const FindListItemsFilter = z.string(); export type FindListItemsRequestQuery = z.infer; export const FindListItemsRequestQuery = z.object({ /** - * List's ide + * List's id */ list_id: ListId, /** diff --git a/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.schema.yaml index 67df0f4e8d031..f08b2d1c6c0cd 100644 --- a/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.schema.yaml +++ b/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.schema.yaml @@ -15,7 +15,7 @@ paths: - name: list_id in: query required: true - description: List's ide + description: List's id schema: $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' - name: page From 9809758c7ccf5a8aeba9c93eb7f23fadf57889b2 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Wed, 10 Jul 2024 07:11:36 +0200 Subject: [PATCH 13/15] remove unused camel case schemas --- .../create_exception_list_item.gen.ts | 18 -------- .../create_exception_list_item.schema.yaml | 39 ----------------- .../update_exception_list_item.gen.ts | 26 ----------- .../update_exception_list_item.schema.yaml | 43 ------------------- 4 files changed, 126 deletions(-) diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen.ts index 55c39811147d6..a11dd91aedd44 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.gen.ts @@ -42,24 +42,6 @@ export type CreateExceptionListItemCommentArray = z.infer< >; export const CreateExceptionListItemCommentArray = z.array(CreateExceptionListItemComment); -export type CreateExceptionListItemRequestBodyCamelCase = z.infer< - typeof CreateExceptionListItemRequestBodyCamelCase ->; -export const CreateExceptionListItemRequestBodyCamelCase = z.object({ - itemId: ExceptionListItemHumanId.optional(), - listId: ExceptionListHumanId, - type: ExceptionListItemType, - name: ExceptionListItemName, - description: ExceptionListItemDescription, - entries: ExceptionListItemEntryArray, - namespaceType: ExceptionNamespaceType.optional().default('single'), - osTypes: ExceptionListItemOsTypeArray.optional().default([]), - tags: ExceptionListItemTags.optional().default([]), - meta: ExceptionListItemMeta.optional(), - expireTime: z.string().datetime().optional(), - comments: CreateExceptionListItemCommentArray.optional().default([]), -}); - export type CreateExceptionListItemRequestBody = z.infer; export const CreateExceptionListItemRequestBody = z.object({ item_id: ExceptionListItemHumanId.optional(), diff --git a/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.schema.yaml index 1832d3f7ddbbf..6ee00569336e0 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/create_exception_list_item/create_exception_list_item.schema.yaml @@ -109,42 +109,3 @@ components: type: array items: $ref: '#/components/schemas/CreateExceptionListItemComment' - - CreateExceptionListItemRequestBodyCamelCase: - type: object - properties: - itemId: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' - listId: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' - type: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' - name: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' - description: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' - entries: - $ref: '../model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' - namespaceType: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' - default: 'single' - osTypes: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' - default: [] - tags: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' - default: [] - meta: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' - expireTime: - type: string - format: date-time - comments: - $ref: '#/components/schemas/CreateExceptionListItemCommentArray' - default: [] - required: - - listId - - type - - name - - description - - entries diff --git a/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen.ts b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen.ts index dab1d3a14c616..963628a7be5c5 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen.ts +++ b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.gen.ts @@ -44,32 +44,6 @@ export type UpdateExceptionListItemCommentArray = z.infer< >; export const UpdateExceptionListItemCommentArray = z.array(UpdateExceptionListItemComment); -export type UpdateExceptionListItemRequestBodyCamelCase = z.infer< - typeof UpdateExceptionListItemRequestBodyCamelCase ->; -export const UpdateExceptionListItemRequestBodyCamelCase = z.object({ - /** - * Either `id` or `item_id` must be specified - */ - id: ExceptionListItemId.optional(), - /** - * Either `id` or `item_id` must be specified - */ - itemId: ExceptionListItemHumanId.optional(), - listId: ExceptionListHumanId.optional(), - type: ExceptionListItemType, - name: ExceptionListItemName, - description: ExceptionListItemDescription, - entries: ExceptionListItemEntryArray, - namespaceType: ExceptionNamespaceType.optional().default('single'), - osTypes: ExceptionListItemOsTypeArray.optional().default([]), - tags: ExceptionListItemTags.optional(), - meta: ExceptionListItemMeta.optional(), - expireTime: z.string().datetime().optional(), - comments: UpdateExceptionListItemCommentArray.optional().default([]), - _version: z.string().optional(), -}); - export type UpdateExceptionListItemRequestBody = z.infer; export const UpdateExceptionListItemRequestBody = z.object({ /** diff --git a/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.schema.yaml b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.schema.yaml index 549bbabdf08b1..02ff5e2d01711 100644 --- a/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/api/update_exception_list_item/update_exception_list_item.schema.yaml @@ -115,46 +115,3 @@ components: type: array items: $ref: '#/components/schemas/UpdateExceptionListItemComment' - - UpdateExceptionListItemRequestBodyCamelCase: - type: object - properties: - id: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemId' - description: Either `id` or `item_id` must be specified - itemId: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemHumanId' - description: Either `id` or `item_id` must be specified - listId: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListHumanId' - type: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemType' - name: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemName' - description: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemDescription' - entries: - $ref: '../model/exception_list_item_entry.schema.yaml#/components/schemas/ExceptionListItemEntryArray' - namespaceType: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionNamespaceType' - default: 'single' - osTypes: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemOsTypeArray' - default: [] - tags: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemTags' - meta: - $ref: '../model/exception_list_common.schema.yaml#/components/schemas/ExceptionListItemMeta' - expireTime: - type: string - format: date-time - comments: - $ref: '#/components/schemas/UpdateExceptionListItemCommentArray' - default: [] - _version: - type: string - required: - - type - - name - - description - - entries From 1757ec0bcbe8ae9f44706a489c64bb27a6840457 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Wed, 10 Jul 2024 14:27:13 +0200 Subject: [PATCH 14/15] add an example --- .../shared/path_params_replacer.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/kbn-openapi-common/shared/path_params_replacer.ts b/packages/kbn-openapi-common/shared/path_params_replacer.ts index 3716a818633ad..bc0bedd011356 100644 --- a/packages/kbn-openapi-common/shared/path_params_replacer.ts +++ b/packages/kbn-openapi-common/shared/path_params_replacer.ts @@ -12,6 +12,25 @@ * @param path Path string with placeholders for params * @param params Object with params to replace * @returns Path string with params replaced + * + * @example + * Having a path string `my/path/{param1}/to/{param2}` and params object + * + * ```ts + * const params = { + * param1: 'value1', + * param2: 'value2, + * } + * ``` + * + * and invoking the function + * + * ```ts + * replaceParams('my/path/{param1}/to/{param2}', params); + * ``` + * + * it will return `my/path/value1/to/value2`. + * */ export function replaceParams(path: string, params: Record): string { let output = path; From a93fe4ed2b61dcf88bfacc750d982a881a56596f Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Wed, 10 Jul 2024 14:29:19 +0200 Subject: [PATCH 15/15] specify explicit ownership for security_solution_codegen.sh --- .github/CODEOWNERS | 1 + x-pack/test/tsconfig.json | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c275ffce3e224..36e3b0f10d4ca 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1237,6 +1237,7 @@ x-pack/test/observability_ai_assistant_functional @elastic/obs-ai-assistant /.buildkite/scripts/steps/esql_grammar_sync.sh @elastic/kibana-esql /.buildkite/scripts/steps/esql_generate_function_metadata.sh @elastic/kibana-esql /.buildkite/pipelines/esql_grammar_sync.yml @elastic/kibana-esql +/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh @elastic/security-detection-rule-management /kbn_pm/ @elastic/kibana-operations /x-pack/dev-tools @elastic/kibana-operations /catalog-info.yaml @elastic/kibana-operations @elastic/kibana-tech-leads diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index c362343fbccef..3b525dfc316ec 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -169,15 +169,10 @@ "@kbn/alerting-state-types", "@kbn/reporting-server", "@kbn/data-quality-plugin", -<<<<<<< HEAD "@kbn/securitysolution-io-ts-list-types", "@kbn/ml-trained-models-utils", - "@kbn/securitysolution-exceptions-common", - "@kbn/securitysolution-lists-common" -======= "@kbn/openapi-common", "@kbn/securitysolution-lists-common", "@kbn/securitysolution-exceptions-common" ->>>>>>> 1b41cda820b (fix a problem of unused replaceParams helper in API client) ] }