diff --git a/packages/kbn-openapi-generator/src/template_service/templates/zod_schema_item.handlebars b/packages/kbn-openapi-generator/src/template_service/templates/zod_schema_item.handlebars index 7ad0abaf1cad8..8e4c5aef616fb 100644 --- a/packages/kbn-openapi-generator/src/template_service/templates/zod_schema_item.handlebars +++ b/packages/kbn-openapi-generator/src/template_service/templates/zod_schema_item.handlebars @@ -68,7 +68,6 @@ z.unknown() {{~#*inline "type_boolean"~}} z.boolean() - {{~#if nullable}}.nullable(){{/if~}} {{~/inline~}} {{~#*inline "type_integer"~}} diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.gen.ts new file mode 100644 index 0000000000000..9de8855a091a6 --- /dev/null +++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.gen.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; 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: Create an alerts index API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +export type CreateAlertsIndexResponse = z.infer; +export const CreateAlertsIndexResponse = z.object({ + acknowledged: z.boolean(), +}); diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.schema.yaml b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.schema.yaml new file mode 100644 index 0000000000000..63213117bd9fb --- /dev/null +++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index.schema.yaml @@ -0,0 +1,47 @@ +openapi: 3.0.0 +info: + title: Create an alerts index API endpoint + version: '2023-10-31' +paths: + /api/detection_engine/index: + post: + x-labels: [ess] + operationId: CreateAlertsIndex + x-codegen-enabled: true + summary: Create an alerts index + tags: + - Alert index API + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + acknowledged: + type: boolean + required: [acknowledged] + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough permissions response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 404: + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index_route.ts b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index_route.ts deleted file mode 100644 index 7ed58c18f4e96..0000000000000 --- a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/create_index/create_index_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. - */ - -export interface CreateIndexResponse { - acknowledged: boolean; -} diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index.gen.ts new file mode 100644 index 0000000000000..e2bfef33d6167 --- /dev/null +++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index.gen.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; 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: Delete an alerts index API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +export type DeleteAlertsIndexResponse = z.infer; +export const DeleteAlertsIndexResponse = z.object({ + acknowledged: z.boolean(), +}); diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index.schema.yaml b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index.schema.yaml new file mode 100644 index 0000000000000..7cdb02632535e --- /dev/null +++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index.schema.yaml @@ -0,0 +1,48 @@ +openapi: 3.0.0 +info: + title: Delete an alerts index API endpoint + version: '2023-10-31' +paths: + /api/detection_engine/index: + delete: + x-labels: [ess] + operationId: DeleteAlertsIndex + x-codegen-enabled: true + summary: Delete an alerts index + tags: + - Alert index API + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + acknowledged: + type: boolean + required: [acknowledged] + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough permissions response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 404: + description: Index does not exist response + content: + application/json: + schema: + type: string + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index_route.ts b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index_route.ts deleted file mode 100644 index ce01b06537ee1..0000000000000 --- a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/delete_index/delete_index_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. - */ - -export interface DeleteIndexResponse { - acknowledged: boolean; -} diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/index.ts b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/index.ts index f0accac2fc01e..b64bea9e974b3 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/index.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/index.ts @@ -5,8 +5,8 @@ * 2.0. */ -export * from './create_index/create_index_route'; -export * from './delete_index/delete_index_route'; +export * from './create_index/create_index.gen'; +export * from './delete_index/delete_index.gen'; export * from './read_alerts_index_exists/read_alerts_index_exists_route'; -export * from './read_index/read_index_route'; +export * from './read_index/read_index.gen'; export * from './read_privileges/read_privileges_route'; diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.gen.ts b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.gen.ts new file mode 100644 index 0000000000000..071d96b89fe9c --- /dev/null +++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.gen.ts @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; 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: Get alerts index name API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +export type GetAlertsIndexResponse = z.infer; +export const GetAlertsIndexResponse = z.object({ + name: z.string(), + index_mapping_outdated: z.boolean().nullable(), +}); diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.schema.yaml b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.schema.yaml new file mode 100644 index 0000000000000..4c38c57da7592 --- /dev/null +++ b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index.schema.yaml @@ -0,0 +1,50 @@ +openapi: 3.0.0 +info: + title: Get alerts index name API endpoint + version: '2023-10-31' +paths: + /api/detection_engine/index: + get: + x-labels: [ess] + operationId: GetAlertsIndex + x-codegen-enabled: true + summary: Gets the alert index name if it exists + tags: + - Alert index API + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + name: + type: string + index_mapping_outdated: + type: boolean + nullable: true + required: [name, index_mapping_outdated] + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough permissions response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 404: + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../model/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index_route.ts b/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index_route.ts deleted file mode 100644 index 43daea9be9fe1..0000000000000 --- a/x-pack/plugins/security_solution/common/api/detection_engine/index_management/read_index/read_index_route.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export interface ReadIndexResponse { - name: string; - index_mapping_outdated: boolean | null; -} diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/create_index_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/create_index_route.ts index 7053c913e4a3e..b5c61bb82c29e 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/create_index_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/create_index_route.ts @@ -15,12 +15,12 @@ import { setPolicy, createBootstrapIndex, } from '@kbn/securitysolution-es-utils'; +import type { CreateAlertsIndexResponse } from '../../../../../common/api/detection_engine/index_management'; import type { SecuritySolutionApiRequestHandlerContext, SecuritySolutionPluginRouter, } from '../../../../types'; import { DETECTION_ENGINE_INDEX_URL } from '../../../../../common/constants'; -import type { CreateIndexResponse } from '../../../../../common/api/detection_engine'; import { buildSiemResponse } from '../utils'; import { getSignalsTemplate, @@ -49,7 +49,7 @@ export const createIndexRoute = (router: SecuritySolutionPluginRouter) => { version: '2023-10-31', validate: false, }, - async (context, _, response): Promise> => { + async (context, _, response): Promise> => { const siemResponse = buildSiemResponse(response); try { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/delete_index_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/delete_index_route.ts index 4bad93c04edc0..49b14944633cc 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/delete_index_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/delete_index_route.ts @@ -14,10 +14,10 @@ import { } from '@kbn/securitysolution-es-utils'; import type { IKibanaResponse } from '@kbn/core/server'; +import type { DeleteAlertsIndexResponse } from '../../../../../common/api/detection_engine/index_management'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_INDEX_URL } from '../../../../../common/constants'; import { buildSiemResponse } from '../utils'; -import type { DeleteIndexResponse } from '../../../../../common/api/detection_engine'; /** * Deletes all of the indexes, template, ilm policies, and aliases. You can check @@ -44,7 +44,7 @@ export const deleteIndexRoute = (router: SecuritySolutionPluginRouter) => { version: '2023-10-31', validate: false, }, - async (context, _, response): Promise> => { + async (context, _, response): Promise> => { const siemResponse = buildSiemResponse(response); try { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/read_index_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/read_index_route.ts index 27adbd71be823..1f7b62ee5209f 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/read_index_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/read_index_route.ts @@ -8,6 +8,7 @@ import { transformError, getBootstrapIndexExists } from '@kbn/securitysolution-es-utils'; import type { RuleDataPluginService } from '@kbn/rule-registry-plugin/server'; import type { IKibanaResponse } from '@kbn/core/server'; +import type { GetAlertsIndexResponse } from '../../../../../common/api/detection_engine/index_management'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_INDEX_URL } from '../../../../../common/constants'; @@ -16,7 +17,6 @@ import { fieldAliasesOutdated } from './check_template_version'; import { getIndexVersion } from './get_index_version'; import { isOutdated } from '../../migrations/helpers'; import { SIGNALS_TEMPLATE_VERSION } from './get_signals_template'; -import type { ReadIndexResponse } from '../../../../../common/api/detection_engine'; export const readIndexRoute = ( router: SecuritySolutionPluginRouter, @@ -35,7 +35,7 @@ export const readIndexRoute = ( version: '2023-10-31', validate: false, }, - async (context, _, response): Promise> => { + async (context, _, response): Promise> => { const siemResponse = buildSiemResponse(response); try { 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 4bc611e50bba2..9f6d717ea9dff 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 @@ -127,6 +127,13 @@ after 30 days. It also deletes other artifacts specific to the migration impleme .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') .send(props.body as object); }, + createAlertsIndex() { + return supertest + .post('/api/detection_engine/index') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana'); + }, createAlertsMigration(props: CreateAlertsMigrationProps) { return supertest .post('/api/detection_engine/signals/migration') @@ -146,6 +153,13 @@ after 30 days. It also deletes other artifacts specific to the migration impleme .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') .send(props.body as object); }, + deleteAlertsIndex() { + return supertest + .delete('/api/detection_engine/index') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana'); + }, /** * Deletes a single rule using the `rule_id` or `id` field. */ @@ -202,6 +216,13 @@ finalize it. .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') .query(props.query); }, + getAlertsIndex() { + return supertest + .get('/api/detection_engine/index') + .set('kbn-xsrf', 'true') + .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana'); + }, getAlertsMigrationStatus(props: GetAlertsMigrationStatusProps) { return supertest .post('/api/detection_engine/signals/migration_status')