Skip to content

Commit

Permalink
[Security Solution] Move remaining timeline route schemas to /common/…
Browse files Browse the repository at this point in the history
…api (elastic#162857)

Closes elastic/security-team#7099
Follow up to elastic#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.
  • Loading branch information
marshallmain authored Aug 9, 2023
1 parent fd28152 commit db0996f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }),
]);
Original file line number Diff line number Diff line change
@@ -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) });
Original file line number Diff line number Diff line change
@@ -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 });
10 changes: 10 additions & 0 deletions x-pack/plugins/security_solution/common/api/tags/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -28,7 +25,7 @@ export const getDashboardsByTagsRoute = (
router.post(
{
path: INTERNAL_DASHBOARDS_URL,
validate: { body: getDashboardsParamsSchema },
validate: { body: buildRouteValidationWithExcess(getDashboardsRequest) },
options: {
tags: ['access:securitySolution'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,7 +25,7 @@ export const createTagRoute = (
router.put(
{
path: INTERNAL_TAGS_URL,
validate: { body: createTagBodySchema },
validate: { body: buildRouteValidationWithExcess(createTagRequest) },
options: {
tags: ['access:securitySolution'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,7 +25,7 @@ export const getTagsByNameRoute = (
router.get(
{
path: INTERNAL_TAGS_URL,
validate: { query: getTagsParamsSchema },
validate: { query: buildRouteValidationWithExcess(getTagsByNameRequest) },
options: {
tags: ['access:securitySolution'],
},
Expand Down

0 comments on commit db0996f

Please sign in to comment.