Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better to rename it to checkPrepackagedTimelines or checkImportTimelines or something a little bit more specific.

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