[Security Solution] Move remaining timeline route schemas to /common/api (#162857)

Closes https://github.com/elastic/security-team/issues/7099
Follow up to https://github.com/elastic/kibana/pull/162314

I mislabeled 3 timeline-related internal APIs as detection engine APIs
on [this
spreadsheet](https://docs.google.com/spreadsheets/d/1VCoJ74EkyGuj59VwWj_3v2ecB84pNCpzGqkYnS0SUKw/edit?pli=1#gid=1102015677)
(create_tags, get_tags_by_name, get_dashboards_by_tags). The APIs are
now correctly categorized on the spreadsheet and this PR establishes
schemas for them in `/common/api`.

I also converted these 3 small schemas to io-ts to make it easier to
avoid pulling in `@kbn/config-schema` to `public`, as that increased the
async chunk size by a full 840KB.
This commit is contained in:
Marshall Main 2023-08-09 07:26:08 -07:00 committed by GitHub
parent fd28152348
commit db0996f4a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 20 deletions

1
.github/CODEOWNERS vendored
View file

@ -1098,6 +1098,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib
/x-pack/plugins/security_solution/server/lib/timeline @elastic/security-threat-hunting-investigations
## Security Solution sub teams - Threat Hunting Explore
/x-pack/plugins/security_solution/common/api/tags @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/common/api/risk_score @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/common/search_strategy/security_solution/hosts @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/common/search_strategy/security_solution/matrix_histogram @elastic/security-threat-hunting-explore

View file

@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
export const createTagRequest = rt.intersection([
rt.type({
name: rt.string,
description: rt.string,
}),
rt.partial({ color: rt.string }),
]);

View file

@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
export const getDashboardsRequest = rt.type({ tagIds: rt.array(rt.string) });

View file

@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
export const getTagsByNameRequest = rt.type({ name: rt.string });

View file

@ -0,0 +1,10 @@
/*
* 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 * from './create_tag/create_tag_route';
export * from './get_dashboards_by_tags/get_dashboards_by_tags_route';
export * from './get_tags_by_name/get_tags_by_name_route';

View file

@ -6,7 +6,6 @@
*/
import type { Logger } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';
import type { DashboardAttributes } from '@kbn/dashboard-plugin/common';
import { transformError } from '@kbn/securitysolution-es-utils';
@ -15,10 +14,8 @@ import type { SetupPlugins } from '../../../plugin';
import type { SecuritySolutionPluginRouter } from '../../../types';
import { buildSiemResponse } from '../../detection_engine/routes/utils';
import { buildFrameworkRequest } from '../../timeline/utils/common';
const getDashboardsParamsSchema = schema.object({
tagIds: schema.arrayOf(schema.string()),
});
import { getDashboardsRequest } from '../../../../common/api/tags';
import { buildRouteValidationWithExcess } from '../../../utils/build_validation/route_validation';
export const getDashboardsByTagsRoute = (
router: SecuritySolutionPluginRouter,
@ -28,7 +25,7 @@ export const getDashboardsByTagsRoute = (
router.post(
{
path: INTERNAL_DASHBOARDS_URL,
validate: { body: getDashboardsParamsSchema },
validate: { body: buildRouteValidationWithExcess(getDashboardsRequest) },
options: {
tags: ['access:securitySolution'],
},

View file

@ -6,22 +6,17 @@
*/
import type { Logger } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';
import { transformError } from '@kbn/securitysolution-es-utils';
import { createTagRequest } from '../../../../common/api/tags';
import { INTERNAL_TAGS_URL } from '../../../../common/constants';
import type { SetupPlugins } from '../../../plugin';
import type { SecuritySolutionPluginRouter } from '../../../types';
import { buildRouteValidationWithExcess } from '../../../utils/build_validation/route_validation';
import { buildSiemResponse } from '../../detection_engine/routes/utils';
import { buildFrameworkRequest } from '../../timeline/utils/common';
import { createTag } from '../saved_objects';
const createTagBodySchema = schema.object({
name: schema.string(),
description: schema.string(),
color: schema.maybe(schema.string()),
});
export const createTagRoute = (
router: SecuritySolutionPluginRouter,
logger: Logger,
@ -30,7 +25,7 @@ export const createTagRoute = (
router.put(
{
path: INTERNAL_TAGS_URL,
validate: { body: createTagBodySchema },
validate: { body: buildRouteValidationWithExcess(createTagRequest) },
options: {
tags: ['access:securitySolution'],
},

View file

@ -6,20 +6,17 @@
*/
import type { Logger } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';
import { transformError } from '@kbn/securitysolution-es-utils';
import { getTagsByNameRequest } from '../../../../common/api/tags';
import { INTERNAL_TAGS_URL } from '../../../../common/constants';
import type { SetupPlugins } from '../../../plugin';
import type { SecuritySolutionPluginRouter } from '../../../types';
import { buildRouteValidationWithExcess } from '../../../utils/build_validation/route_validation';
import { buildSiemResponse } from '../../detection_engine/routes/utils';
import { buildFrameworkRequest } from '../../timeline/utils/common';
import { findTagsByName } from '../saved_objects';
const getTagsParamsSchema = schema.object({
name: schema.string(),
});
export const getTagsByNameRoute = (
router: SecuritySolutionPluginRouter,
logger: Logger,
@ -28,7 +25,7 @@ export const getTagsByNameRoute = (
router.get(
{
path: INTERNAL_TAGS_URL,
validate: { query: getTagsParamsSchema },
validate: { query: buildRouteValidationWithExcess(getTagsByNameRequest) },
options: {
tags: ['access:securitySolution'],
},