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

[Threat Hunting Investigations] Migrate all timeline routes to OpenAPI types #190238

Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
a636ce9
migrate delete timelines route to zod
janmonschke Jul 31, 2024
c8c23d5
clean draft timeline, delete/persist note, delete timeline
janmonschke Aug 2, 2024
c2a5c9d
export timelines
janmonschke Aug 2, 2024
96ce48a
persist timeline favorite
janmonschke Aug 2, 2024
cb64f0e
other routes
janmonschke Aug 6, 2024
3df3a2e
clean up types
janmonschke Aug 6, 2024
9581dec
Merge branch 'main' into securitySolution/openAPI/migrateSimpleRoutes2
janmonschke Aug 6, 2024
8a6c833
get notes route
janmonschke Aug 6, 2024
3bc8d83
`timelineId` is not nullabled
janmonschke Aug 6, 2024
093c41f
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Aug 6, 2024
e86eaf7
re-introduce BarePinnedEventWithoutExternalRefs
janmonschke Aug 7, 2024
e808a9e
fix tests
janmonschke Aug 7, 2024
b29f60a
fix tests
janmonschke Aug 7, 2024
829d465
fix tests
janmonschke Aug 7, 2024
12a4646
be -> equal
janmonschke Aug 7, 2024
210888b
fix tests
janmonschke Aug 7, 2024
6afe200
prevent API breaking change
janmonschke Aug 8, 2024
36e942c
Merge branch 'main' into securitySolution/openAPI/migrateSimpleRoutes2
janmonschke Aug 8, 2024
c8e1786
copy timeline route
janmonschke Aug 8, 2024
31bc0e1
create timelines routes
janmonschke Aug 8, 2024
402c1d0
properly type routes
janmonschke Aug 8, 2024
5f15e27
post -> get
janmonschke Aug 8, 2024
1dfa46a
patch timeline route
janmonschke Aug 8, 2024
ff183d9
import timeline route
janmonschke Aug 8, 2024
a8096b7
import / install timelines
janmonschke Aug 9, 2024
c63cdab
draft timeline
janmonschke Aug 9, 2024
feab218
fix brooken export
janmonschke Aug 9, 2024
a8e7b54
resolve timeline
janmonschke Aug 9, 2024
55aef91
get timeline route
janmonschke Aug 9, 2024
59fae7b
get timelines route
janmonschke Aug 9, 2024
d4c56b8
remove some types
janmonschke Aug 9, 2024
f693470
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Aug 9, 2024
6e9dd48
clean up route parameters
janmonschke Aug 9, 2024
a863c4b
fix errors
janmonschke Aug 9, 2024
ec8f140
Merge branch 'securitySolution/openAPI/migrateTimelineRoutes' of http…
janmonschke Aug 9, 2024
ddf3e6a
fix types
janmonschke Aug 9, 2024
33b738e
Merge branch 'main' into securitySolution/openAPI/migrateTimelineRoutes
janmonschke Sep 19, 2024
c0850b1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 19, 2024
6b9ed52
Merge branch 'main' into securitySolution/openAPI/migrateTimelineRoutes
janmonschke Sep 20, 2024
ea245e4
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Sep 20, 2024
85541bb
add missing `type` to `DataProviderQueryMatch`
janmonschke Sep 24, 2024
9964362
Merge branch 'main' into securitySolution/openAPI/migrateTimelineRoutes
janmonschke Sep 24, 2024
7a39d88
Fix types
janmonschke Sep 25, 2024
316d1e3
Update docs
janmonschke Sep 25, 2024
4ea7007
Merge branch 'main' into securitySolution/openAPI/migrateTimelineRoutes
janmonschke Sep 25, 2024
51c05ba
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Sep 25, 2024
05b11f1
[CI] Auto-commit changed files from 'make api-docs && make api-docs-s…
kibanamachine Sep 25, 2024
cfd3c16
use zod-generated types for resolved timeline types
janmonschke Sep 25, 2024
2fc6922
fix type error
janmonschke Sep 25, 2024
294b831
remove unused types
janmonschke Sep 25, 2024
493b95c
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Sep 25, 2024
f080b00
AllTimelesResponse -> GetTimelinesResponse,
janmonschke Sep 25, 2024
33f918d
fix types
janmonschke Sep 25, 2024
8902525
Merge branch 'securitySolution/openAPI/migrateTimelineRoutes' of http…
janmonschke Sep 25, 2024
2846e0d
[CI] Auto-commit changed files from 'make api-docs && make api-docs-s…
kibanamachine Sep 25, 2024
f3795b3
add PersistTimelineResponse
janmonschke Sep 25, 2024
5848ea1
Merge branch 'securitySolution/openAPI/migrateTimelineRoutes' of http…
janmonschke Sep 25, 2024
a1ee806
fix types and update type bundle
janmonschke Sep 25, 2024
34d0dcd
update docs build
janmonschke Sep 25, 2024
fc7c68b
move zod parsing and error handling to its own file
janmonschke Sep 25, 2024
19368d9
migrate more types
janmonschke Sep 25, 2024
aabe71c
clean up more types
janmonschke Sep 25, 2024
2e87b8c
fix more types
janmonschke Sep 26, 2024
eeb83e4
remove GetAllTimelineVariables
janmonschke Sep 26, 2024
5c46bfd
TimelineResponse -> PatchTimelineResponse
janmonschke Sep 26, 2024
c9851b3
fix fetching all timelines
janmonschke Sep 26, 2024
e4e4e7c
Migrate more types
janmonschke Sep 26, 2024
e4c97b4
remove unused types
janmonschke Sep 26, 2024
d27f8a4
remove remaining runtime types from model/api.ts
janmonschke Sep 26, 2024
71f511a
Remove unused route file
janmonschke Sep 26, 2024
b74128b
Remove comments
janmonschke Sep 26, 2024
1ca9ef5
fix types
janmonschke Sep 26, 2024
3c19531
fix and remove more types
janmonschke Sep 26, 2024
39255f9
fix types
janmonschke Sep 27, 2024
5a4114d
Merge branch 'main' into securitySolution/openAPI/migrateTimelineRoutes
janmonschke Sep 27, 2024
2acec55
remove more types
janmonschke Sep 27, 2024
d96a1de
add types to clean draft timeline route
janmonschke Sep 27, 2024
c73b45b
Merge branch 'main' into securitySolution/openAPI/migrateTimelineRoutes
elasticmachine Sep 30, 2024
c4de6df
remove servers prop from yaml files
janmonschke Sep 30, 2024
dd48e1a
remove full stops from summary
janmonschke Sep 30, 2024
bd68dc7
make sure the schema only accepts empty objects
janmonschke Sep 30, 2024
746a1ac
simplify the expression
janmonschke Sep 30, 2024
3e192bb
move zod_errors
janmonschke Sep 30, 2024
6ffce63
generate docs & OAS
janmonschke Sep 30, 2024
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
423 changes: 237 additions & 186 deletions oas_docs/output/kibana.serverless.staging.yaml

Large diffs are not rendered by default.

423 changes: 237 additions & 186 deletions oas_docs/output/kibana.staging.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ import type {
CleanDraftTimelinesRequestBodyInput,
CleanDraftTimelinesResponse,
} from './timeline/clean_draft_timelines/clean_draft_timelines_route.gen';
import type {
CopyTimelineRequestBodyInput,
CopyTimelineResponse,
} from './timeline/copy_timeline/copy_timeline_route.gen';
import type {
CreateTimelinesRequestBodyInput,
CreateTimelinesResponse,
Expand Down Expand Up @@ -556,6 +560,23 @@ If asset criticality records already exist for the specified entities, those rec
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Copies and returns a timeline or timeline template.

*/
async copyTimeline(props: CopyTimelineProps) {
this.log.info(`${new Date().toISOString()} Calling API CopyTimeline`);
return this.kbnClient
.request<CopyTimelineResponse>({
path: '/api/timeline/_copy',
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '2023-10-31',
},
method: 'GET',
body: props.body,
})
.catch(catchAxiosErrorFormatAndThrow);
}
async createAlertsIndex() {
this.log.info(`${new Date().toISOString()} Calling API CreateAlertsIndex`);
return this.kbnClient
Expand Down Expand Up @@ -1993,6 +2014,9 @@ export interface BulkUpsertAssetCriticalityRecordsProps {
export interface CleanDraftTimelinesProps {
body: CleanDraftTimelinesRequestBodyInput;
}
export interface CopyTimelineProps {
body: CopyTimelineRequestBodyInput;
}
export interface CreateAlertsMigrationProps {
body: CreateAlertsMigrationRequestBodyInput;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { z } from '@kbn/zod';

import { TimelineType, TimelineResponse } from '../model/components.gen';
import { TimelineType, PersistTimelineResponse } from '../model/components.gen';

export type CleanDraftTimelinesRequestBody = z.infer<typeof CleanDraftTimelinesRequestBody>;
export const CleanDraftTimelinesRequestBody = z.object({
Expand All @@ -25,10 +25,4 @@ export const CleanDraftTimelinesRequestBody = z.object({
export type CleanDraftTimelinesRequestBodyInput = z.input<typeof CleanDraftTimelinesRequestBody>;

export type CleanDraftTimelinesResponse = z.infer<typeof CleanDraftTimelinesResponse>;
export const CleanDraftTimelinesResponse = z.object({
data: z.object({
persistTimeline: z.object({
timeline: TimelineResponse,
}),
}),
});
export const CleanDraftTimelinesResponse = PersistTimelineResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,7 @@ paths:
content:
application/json:
schema:
type: object
required: [data]
properties:
data:
type: object
required: [persistTimeline]
properties:
persistTimeline:
type: object
required: [timeline]
properties:
timeline:
$ref: '../model/components.schema.yaml#/components/schemas/TimelineResponse'
$ref: '../model/components.schema.yaml#/components/schemas/PersistTimelineResponse'
'403':
description: Indicates that the user does not have the required permissions to create a draft Timeline.
content:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

/*
* NOTICE: Do not edit this file manually.
* This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator.
*
* info:
* title: Elastic Security - Timeline - Copy Timeline API
* version: 2023-10-31
*/

import { z } from '@kbn/zod';

import { SavedTimeline, PersistTimelineResponse } from '../model/components.gen';

export type CopyTimelineRequestBody = z.infer<typeof CopyTimelineRequestBody>;
export const CopyTimelineRequestBody = z.object({
timeline: SavedTimeline,
timelineIdToCopy: z.string(),
});
export type CopyTimelineRequestBodyInput = z.input<typeof CopyTimelineRequestBody>;

export type CopyTimelineResponse = z.infer<typeof CopyTimelineResponse>;
export const CopyTimelineResponse = PersistTimelineResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
openapi: 3.0.0
info:
title: Elastic Security - Timeline - Copy Timeline API
version: '2023-10-31'
servers:
janmonschke marked this conversation as resolved.
Show resolved Hide resolved
- url: 'http://{kibana_host}:{port}'
variables:
kibana_host:
default: localhost
port:
default: '5601'
paths:
/api/timeline/_copy:
get:
x-labels: [serverless, ess]
x-codegen-enabled: true
operationId: CopyTimeline
summary: Copies timeline or timeline template.
janmonschke marked this conversation as resolved.
Show resolved Hide resolved
description: |
Copies and returns a timeline or timeline template.
tags:
- access:securitySolution
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [timeline, timelineIdToCopy]
properties:
timeline:
$ref: '../model/components.schema.yaml#/components/schemas/SavedTimeline'
timelineIdToCopy:
type: string
responses:
'200':
description: Indicates that the timeline has been successfully copied.
content:
application/json:
schema:
$ref: '../model/components.schema.yaml#/components/schemas/PersistTimelineResponse'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,23 @@
import { z } from '@kbn/zod';

import {
SavedTimeline,
TimelineStatus,
TimelineType,
SavedTimeline,
TimelineResponse,
PersistTimelineResponse,
} from '../model/components.gen';

export type CreateTimelinesRequestBody = z.infer<typeof CreateTimelinesRequestBody>;
export const CreateTimelinesRequestBody = z.object({
timeline: SavedTimeline,
status: TimelineStatus.nullable().optional(),
timelineId: z.string().nullable().optional(),
templateTimelineId: z.string().nullable().optional(),
templateTimelineVersion: z.number().nullable().optional(),
timelineType: TimelineType.nullable().optional(),
version: z.string().nullable().optional(),
timeline: SavedTimeline,
});
export type CreateTimelinesRequestBodyInput = z.input<typeof CreateTimelinesRequestBody>;

export type CreateTimelinesResponse = z.infer<typeof CreateTimelinesResponse>;
export const CreateTimelinesResponse = z.object({
data: z.object({
persistTimeline: z.object({
timeline: TimelineResponse.optional(),
}),
}),
});
export const CreateTimelinesResponse = PersistTimelineResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ paths:
application/json:
schema:
type: object
required:
- timeline
required: [timeline]
properties:
timeline:
$ref: '../model/components.schema.yaml#/components/schemas/SavedTimeline'
status:
$ref: '../model/components.schema.yaml#/components/schemas/TimelineStatus'
nullable: true
Expand All @@ -50,26 +51,13 @@ paths:
version:
type: string
nullable: true
timeline:
$ref: '../model/components.schema.yaml#/components/schemas/SavedTimeline'
responses:
'200':
description: Indicates the Timeline was successfully created.
content:
application/json:
schema:
type: object
required: [data]
properties:
data:
type: object
required: [persistTimeline]
properties:
persistTimeline:
type: object
properties:
timeline:
$ref: '../model/components.schema.yaml#/components/schemas/TimelineResponse'
$ref: '../model/components.schema.yaml#/components/schemas/PersistTimelineResponse'
'405':
description: Indicates that there was an error in the Timeline creation.
content:
Expand Down

This file was deleted.

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

import { z } from '@kbn/zod';

import { TimelineType, TimelineResponse } from '../model/components.gen';
import { TimelineType, PersistTimelineResponse } from '../model/components.gen';

export type GetDraftTimelinesRequestQuery = z.infer<typeof GetDraftTimelinesRequestQuery>;
export const GetDraftTimelinesRequestQuery = z.object({
Expand All @@ -25,10 +25,4 @@ export const GetDraftTimelinesRequestQuery = z.object({
export type GetDraftTimelinesRequestQueryInput = z.input<typeof GetDraftTimelinesRequestQuery>;

export type GetDraftTimelinesResponse = z.infer<typeof GetDraftTimelinesResponse>;
export const GetDraftTimelinesResponse = z.object({
data: z.object({
persistTimeline: z.object({
timeline: TimelineResponse,
}),
}),
});
export const GetDraftTimelinesResponse = PersistTimelineResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,7 @@ paths:
content:
application/json:
schema:
type: object
required: [data]
properties:
data:
type: object
required: [persistTimeline]
properties:
persistTimeline:
type: object
required: [timeline]
properties:
timeline:
$ref: '../model/components.schema.yaml#/components/schemas/TimelineResponse'
$ref: '../model/components.schema.yaml#/components/schemas/PersistTimelineResponse'
'403':
description: If a draft Timeline was not found and we attempted to create one, it indicates that the user does not have the required permissions to create a draft Timeline.
content:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export const GetTimelineRequestQuery = z.object({
export type GetTimelineRequestQueryInput = z.input<typeof GetTimelineRequestQuery>;

export type GetTimelineResponse = z.infer<typeof GetTimelineResponse>;
export const GetTimelineResponse = z.object({
data: z.object({
getOneTimeline: TimelineResponse.nullable(),
export const GetTimelineResponse = z.union([
z.object({
data: z.object({
getOneTimeline: TimelineResponse,
}),
}),
});
z.object({}),
]);
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ paths:
content:
application/json:
schema:
type: object
required: [data]
properties:
data:
type: object
required: [getOneTimeline]
oneOf:
- type: object
required: [data]
properties:
getOneTimeline:
$ref: '../model/components.schema.yaml#/components/schemas/TimelineResponse'
nullable: true
data:
type: object
required: [getOneTimeline]
properties:
getOneTimeline:
$ref: '../model/components.schema.yaml#/components/schemas/TimelineResponse'
- type: object
janmonschke marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Loading