Skip to content

Commit

Permalink
[Security Solution] Add missing Alert index API OpenAPI specs (elasti…
Browse files Browse the repository at this point in the history
…c#186401)

**Addresses:** elastic#183661

## Summary

This PR adds missing OpenAPI specs for the Alert Index API endpoints available in ESS

- `POST /api/detection_engine/index`
- `GET /api/detection_engine/index`
- `DELETE /api/detection_engine/index`
  • Loading branch information
maximpn authored and bhapas committed Jun 24, 2024
1 parent c79adcf commit f566dbc
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ z.unknown()

{{~#*inline "type_boolean"~}}
z.boolean()
{{~#if nullable}}.nullable(){{/if~}}
{{~/inline~}}

{{~#*inline "type_integer"~}}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<typeof CreateAlertsIndexResponse>;
export const CreateAlertsIndexResponse = z.object({
acknowledged: z.boolean(),
});
Original file line number Diff line number Diff line change
@@ -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'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<typeof DeleteAlertsIndexResponse>;
export const DeleteAlertsIndexResponse = z.object({
acknowledged: z.boolean(),
});
Original file line number Diff line number Diff line change
@@ -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'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
@@ -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<typeof GetAlertsIndexResponse>;
export const GetAlertsIndexResponse = z.object({
name: z.string(),
index_mapping_outdated: z.boolean().nullable(),
});
Original file line number Diff line number Diff line change
@@ -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'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -49,7 +49,7 @@ export const createIndexRoute = (router: SecuritySolutionPluginRouter) => {
version: '2023-10-31',
validate: false,
},
async (context, _, response): Promise<IKibanaResponse<CreateIndexResponse>> => {
async (context, _, response): Promise<IKibanaResponse<CreateAlertsIndexResponse>> => {
const siemResponse = buildSiemResponse(response);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,7 +44,7 @@ export const deleteIndexRoute = (router: SecuritySolutionPluginRouter) => {
version: '2023-10-31',
validate: false,
},
async (context, _, response): Promise<IKibanaResponse<DeleteIndexResponse>> => {
async (context, _, response): Promise<IKibanaResponse<DeleteAlertsIndexResponse>> => {
const siemResponse = buildSiemResponse(response);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand All @@ -35,7 +35,7 @@ export const readIndexRoute = (
version: '2023-10-31',
validate: false,
},
async (context, _, response): Promise<IKibanaResponse<ReadIndexResponse>> => {
async (context, _, response): Promise<IKibanaResponse<GetAlertsIndexResponse>> => {
const siemResponse = buildSiemResponse(response);

try {
Expand Down
21 changes: 21 additions & 0 deletions x-pack/test/api_integration/services/security_solution_api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit f566dbc

Please sign in to comment.