Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Create template timeline #63136

Merged
merged 52 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d3b3ba6
init routes for template timeline
angorayc Apr 8, 2020
8a05dd9
create template timeline
angorayc Apr 9, 2020
79d53c8
Merge remote-tracking branch 'upstream/master' into template-timeline
angorayc Apr 9, 2020
99f0da5
add create/update timelines route
angorayc Apr 15, 2020
5a9b6ac
update api entry point
angorayc Apr 15, 2020
91798ee
fix types
angorayc Apr 15, 2020
dcae730
add template type
angorayc Apr 15, 2020
086996a
Merge remote-tracking branch 'upstream/master' into template-timeline
angorayc Apr 16, 2020
cab3e60
fix types
angorayc Apr 16, 2020
a33cbb6
add types and template timeline id
angorayc Apr 16, 2020
8243614
fix types
angorayc Apr 16, 2020
89f2b12
update import timeline to handle template timeline
angorayc Apr 16, 2020
464ee77
unit test
angorayc Apr 17, 2020
3a37628
sudo code
XavierM Apr 17, 2020
9bb3552
remove class for savedobject
angorayc Apr 20, 2020
aba9d8e
add template timeline version
angorayc Apr 20, 2020
e26a803
clean up arguments
angorayc Apr 20, 2020
5351219
fix types for framework request
XavierM Apr 20, 2020
7584715
show filter in find
XavierM Apr 20, 2020
d120d73
fix create template timeline
angorayc Apr 20, 2020
7aeb123
update mock data
angorayc Apr 20, 2020
7416fca
handle missing timeline when exporting
angorayc Apr 21, 2020
4b93431
update the order for timeline routes
angorayc Apr 21, 2020
3c51485
update schemas
angorayc Apr 21, 2020
c17ea0c
Merge remote-tracking branch 'upstream/master' into template-timeline
angorayc Apr 21, 2020
b94159f
Merge remote-tracking branch 'upstream/master' into template-timeline
angorayc Apr 21, 2020
0a7b275
move type to common folder so we can re-use them on UI and server side
XavierM Apr 21, 2020
0f22a03
fix types + integrate persist with epic timeline
XavierM Apr 21, 2020
bebb133
update all timeline when persit timeline
XavierM Apr 21, 2020
785ec34
add timeline api readme
angorayc Apr 22, 2020
2abe09b
fix validation error
angorayc Apr 22, 2020
8707b34
fix unit test
angorayc Apr 22, 2020
b7fa77a
Merge remote-tracking branch 'upstream/master' into template-timeline
angorayc Apr 23, 2020
8c56978
Merge branch 'master' into template-timeline
elasticmachine Apr 24, 2020
be2aea3
display error if unexpected format is given
angorayc Apr 27, 2020
7194dc5
Merge branch 'template-timeline' of github.com:angorayc/kibana into t…
angorayc Apr 27, 2020
21b535e
Merge remote-tracking branch 'upstream/master' into template-timeline
angorayc Apr 27, 2020
292c35e
Merge branch 'master' into template-timeline
elasticmachine Apr 27, 2020
f106ff4
fix issue with reftech all timeline query
XavierM Apr 27, 2020
a8c0501
fix flashing timeline while refetch
angorayc Apr 28, 2020
d1c851e
Merge branch 'template-timeline' of github.com:angorayc/kibana into t…
angorayc Apr 28, 2020
4eca630
fix types
angorayc Apr 28, 2020
7d3d120
Merge remote-tracking branch 'upstream/master' into template-timeline
angorayc Apr 28, 2020
5315cc7
fix types
angorayc Apr 28, 2020
1995a71
fix dependency
angorayc Apr 28, 2020
6413a11
fix timeline deletion
XavierM Apr 28, 2020
b1d54e7
Merge branch 'template-timeline' of github.com:angorayc/kibana into t…
XavierM Apr 28, 2020
48d43b7
remove redundant dependency
angorayc Apr 28, 2020
3993d5d
add i18n message
angorayc Apr 28, 2020
184711f
Merge branch 'master' into template-timeline
elasticmachine Apr 28, 2020
fd3a036
Merge branch 'master' into template-timeline
elasticmachine Apr 28, 2020
bdade71
fix unit test
angorayc Apr 29, 2020
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 @@ -7,14 +7,11 @@
/* eslint-disable @typescript-eslint/no-empty-interface */

import * as runtimeTypes from 'io-ts';
import { SavedObjectsClient } from 'kibana/server';

import { unionWithNullType } from '../framework';
import { NoteSavedObjectToReturnRuntimeType, NoteSavedObject } from '../note/types';
import {
PinnedEventToReturnSavedObjectRuntimeType,
PinnedEventSavedObject,
} from '../pinned_event/types';
import { SavedObjectsClient } from '../../../../../../src/core/server';
import { unionWithNullType } from '../../utility_types';
import { NoteSavedObject, NoteSavedObjectToReturnRuntimeType } from './note';
import { PinnedEventToReturnSavedObjectRuntimeType, PinnedEventSavedObject } from './pinned_event';

/*
* ColumnHeader Types
Expand Down Expand Up @@ -136,6 +133,17 @@ const SavedSortRuntimeType = runtimeTypes.partial({
/*
* Timeline Types
*/

export enum TimelineType {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit -> maybe interesting for this case gcanti/io-ts#67 (comment)

default = 'default',
template = 'template',
}

export const TimelineTypeLiteralRt = runtimeTypes.union([
runtimeTypes.literal(TimelineType.template),
runtimeTypes.literal(TimelineType.default),
]);

export const SavedTimelineRuntimeType = runtimeTypes.partial({
columns: unionWithNullType(runtimeTypes.array(SavedColumnHeaderRuntimeType)),
dataProviders: unionWithNullType(runtimeTypes.array(SavedDataProviderRuntimeType)),
Expand All @@ -146,6 +154,9 @@ export const SavedTimelineRuntimeType = runtimeTypes.partial({
kqlMode: unionWithNullType(runtimeTypes.string),
kqlQuery: unionWithNullType(SavedFilterQueryQueryRuntimeType),
title: unionWithNullType(runtimeTypes.string),
templateTimelineId: unionWithNullType(runtimeTypes.string),
templateTimelineVersion: unionWithNullType(runtimeTypes.number),
timelineType: unionWithNullType(TimelineTypeLiteralRt),
dateRange: unionWithNullType(SavedDateRangePickerRuntimeType),
savedQueryId: unionWithNullType(runtimeTypes.string),
sort: unionWithNullType(SavedSortRuntimeType),
Expand Down Expand Up @@ -192,6 +203,25 @@ export const TimelineSavedToReturnObjectRuntimeType = runtimeTypes.intersection(
export interface TimelineSavedObject
extends runtimeTypes.TypeOf<typeof TimelineSavedToReturnObjectRuntimeType> {}

/**
* All Timeline Saved object type with metadata
*/
export const TimelineResponseType = runtimeTypes.type({
data: runtimeTypes.type({
persistTimeline: runtimeTypes.intersection([
runtimeTypes.partial({
code: unionWithNullType(runtimeTypes.number),
message: unionWithNullType(runtimeTypes.string),
}),
runtimeTypes.type({
timeline: TimelineSavedToReturnObjectRuntimeType,
}),
]),
}),
});

export interface TimelineResponse extends runtimeTypes.TypeOf<typeof TimelineResponseType> {}

/**
* All Timeline Saved object type with metadata
*/
Expand Down Expand Up @@ -234,6 +264,11 @@ export type ExportedTimelines = TimelineSavedObject &
pinnedEventIds: string[];
};

export interface ExportTimelineNotFoundError {
statusCode: number;
message: string;
}

export interface BulkGetInput {
type: string;
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as runtimeTypes from 'io-ts';

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

/*
* Note Types
Expand Down Expand Up @@ -56,11 +56,7 @@ export const NoteSavedObjectToReturnRuntimeType = runtimeTypes.intersection([
version: runtimeTypes.string,
}),
runtimeTypes.partial({
timelineVersion: runtimeTypes.union([
runtimeTypes.string,
runtimeTypes.null,
runtimeTypes.undefined,
]),
timelineVersion: unionWithNullType(runtimeTypes.string),
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as runtimeTypes from 'io-ts';

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

/*
* Note Types
Expand Down Expand Up @@ -40,11 +40,7 @@ export const PinnedEventSavedObjectRuntimeType = runtimeTypes.intersection([
}),
runtimeTypes.partial({
pinnedEventId: unionWithNullType(runtimeTypes.string),
timelineVersion: runtimeTypes.union([
runtimeTypes.string,
runtimeTypes.null,
runtimeTypes.undefined,
]),
timelineVersion: unionWithNullType(runtimeTypes.string),
}),
]);

Expand All @@ -55,11 +51,7 @@ export const PinnedEventToReturnSavedObjectRuntimeType = runtimeTypes.intersecti
}),
SavedPinnedEventRuntimeType,
runtimeTypes.partial({
timelineVersion: runtimeTypes.union([
runtimeTypes.string,
runtimeTypes.null,
runtimeTypes.undefined,
]),
timelineVersion: unionWithNullType(runtimeTypes.string),
}),
]);

Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/siem/common/utility_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import * as runtimeTypes from 'io-ts';
import { ReactNode } from 'react';

// This type is for typing EuiDescriptionList
export interface DescriptionList {
title: NonNullable<ReactNode>;
description: NonNullable<ReactNode>;
}

export const unionWithNullType = <T extends runtimeTypes.Mixed>(type: T) =>
runtimeTypes.union([type, runtimeTypes.null]);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DeleteTimelines } from '../types';

import { TimelineDownloader } from './export_timeline';
import { DeleteTimelineModalOverlay } from '../delete_timeline_modal';
import { exportSelectedTimeline } from '../../../containers/timeline/all/api';
import { exportSelectedTimeline } from '../../../containers/timeline/api';

export interface ExportTimeline {
disableExportTimelineDownloader: () => void;
Expand Down
27 changes: 24 additions & 3 deletions x-pack/plugins/siem/public/components/open_timeline/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,34 @@ import { TestProviderWithoutDragAndDrop, apolloClient } from '../../mock/test_pr
import { mockOpenTimelineQueryResults } from '../../mock/timeline_results';
import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../pages/timelines/timelines_page';

import { StatefulOpenTimeline } from '.';
import { NotePreviews } from './note_previews';
import { OPEN_TIMELINE_CLASS_NAME } from './helpers';

import { StatefulOpenTimeline } from '.';
import { useGetAllTimeline, getAllTimeline } from '../../containers/timeline/all';
jest.mock('../../lib/kibana');
jest.mock('../../containers/timeline/all', () => {
const originalModule = jest.requireActual('../../containers/timeline/all');
return {
useGetAllTimeline: jest.fn(),
getAllTimeline: originalModule.getAllTimeline,
};
});

describe('StatefulOpenTimeline', () => {
const theme = () => ({ eui: euiDarkVars, darkMode: true });
const title = 'All Timelines / Open Timelines';
beforeEach(() => {
((useGetAllTimeline as unknown) as jest.Mock).mockReturnValue({
fetchAllTimeline: jest.fn(),
timelines: getAllTimeline(
'',
mockOpenTimelineQueryResults[0].result.data?.getAllTimeline?.timeline ?? []
),
loading: false,
totalCount: mockOpenTimelineQueryResults[0].result.data.getAllTimeline.totalCount,
refetch: jest.fn(),
});
});

test('it has the expected initial state', () => {
const wrapper = mount(
Expand Down Expand Up @@ -459,6 +478,8 @@ describe('StatefulOpenTimeline', () => {
.find('[data-test-subj="expand-notes"]')
.first()
.simulate('click');
expect(wrapper.find('[data-test-subj="note-previews-container"]').exists()).toEqual(true);
expect(wrapper.find('[data-test-subj="updated-by"]').exists()).toEqual(true);

expect(
wrapper
Expand Down Expand Up @@ -532,7 +553,7 @@ describe('StatefulOpenTimeline', () => {
test('it renders the expected count of matching timelines when no query has been entered', async () => {
const wrapper = mount(
<ThemeProvider theme={theme}>
<MockedProvider mocks={mockOpenTimelineQueryResults} addTypename={false}>
<MockedProvider addTypename={false}>
<TestProviderWithoutDragAndDrop>
<StatefulOpenTimeline
data-test-subj="stateful-timeline"
Expand Down
Loading