Skip to content

Commit

Permalink
[Serverless] #7099 Move install prepackaged timelines schema (#162314)
Browse files Browse the repository at this point in the history
## Summary

This PR moves the last remaining timeline api schema to a common
location as per elastic/security-team#7099

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
lgestc authored Jul 25, 2023
1 parent 3d6dbd4 commit 586afe9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './patch_timelines/patch_timelines_schema';
export * from './persist_favorite/persist_favorite_schema';
export * from './persist_note/persist_note_route';
export * from './pinned_events/pinned_events_route';
export * from './install_prepackaged_timelines/install_prepackaged_timelines';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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';

import { unionWithNullType } from '../../../utility_types';
import { ImportTimelinesSchemaRt, TimelineSavedToReturnObjectRuntimeType } from '..';

export const checkTimelineStatusRt = rt.type({
timelinesToInstall: rt.array(unionWithNullType(ImportTimelinesSchemaRt)),
timelinesToUpdate: rt.array(unionWithNullType(ImportTimelinesSchemaRt)),
prepackagedTimelines: rt.array(unionWithNullType(TimelineSavedToReturnObjectRuntimeType)),
});

export type CheckTimelineStatusRt = rt.TypeOf<typeof checkTimelineStatusRt>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { transformError } from '@kbn/securitysolution-es-utils';
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { checkTimelineStatusRt } from '../../../../../../common/api/timeline';
import { buildSiemResponse } from '../../../routes/utils';
import type { SetupPlugins } from '../../../../../plugin';
import type { SecuritySolutionPluginRouter } from '../../../../../types';
Expand All @@ -24,10 +25,7 @@ import { createPrebuiltRuleAssetsClient } from '../../logic/rule_assets/prebuilt
import { rulesToMap } from '../../logic/utils';

import { buildFrameworkRequest } from '../../../../timeline/utils/common';
import {
checkTimelinesStatus,
checkTimelineStatusRt,
} from '../../../../timeline/utils/check_timelines_status';
import { checkTimelinesStatus } from '../../../../timeline/utils/check_timelines_status';

export const getPrebuiltRulesAndTimelinesStatusRoute = (
router: SecuritySolutionPluginRouter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { transformError } from '@kbn/securitysolution-es-utils';
import { validate } from '@kbn/securitysolution-io-ts-utils';
import { checkTimelineStatusRt } from '../../../../../../common/api/timeline';
import type { SecuritySolutionPluginRouter } from '../../../../../types';

import { TIMELINE_PREPACKAGED_URL } from '../../../../../../common/constants';
Expand All @@ -18,7 +19,7 @@ import { buildSiemResponse } from '../../../../detection_engine/routes/utils';

import { installPrepackagedTimelines } from './helpers';

import { checkTimelinesStatus, checkTimelineStatusRt } from '../../../utils/check_timelines_status';
import { checkTimelinesStatus } from '../../../utils/check_timelines_status';

import { buildFrameworkRequest } from '../../../utils/common';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,18 @@
*/

import path, { join, resolve } from 'path';
import * as rt from 'io-ts';
import type { TimelineSavedObject, ImportTimelinesSchema } from '../../../../common/api/timeline';
import {
TimelineSavedToReturnObjectRuntimeType,
ImportTimelinesSchemaRt,
import type {
CheckTimelineStatusRt,
TimelineSavedObject,
ImportTimelinesSchema,
} from '../../../../common/api/timeline';

import { unionWithNullType } from '../../../../common/utility_types';

import type { FrameworkRequest } from '../../framework';

import { getExistingPrepackagedTimelines } from '../saved_object/timelines';

import { loadData, getReadables } from './common';

export const checkTimelineStatusRt = rt.type({
timelinesToInstall: rt.array(unionWithNullType(ImportTimelinesSchemaRt)),
timelinesToUpdate: rt.array(unionWithNullType(ImportTimelinesSchemaRt)),
prepackagedTimelines: rt.array(unionWithNullType(TimelineSavedToReturnObjectRuntimeType)),
});

export type CheckTimelineStatusRt = rt.TypeOf<typeof checkTimelineStatusRt>;

export const getTimelinesToUpdate = (
timelinesFromFileSystem: ImportTimelinesSchema[],
installedTimelines: TimelineSavedObject[]
Expand Down

0 comments on commit 586afe9

Please sign in to comment.