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

[Serverless] Add schema validation to Search Strategies in security solution & timelines #162539

Merged
merged 29 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
da809b0
[Serverless] Search strategy request schema validation
lgestc Jul 26, 2023
7e9b761
make query schema less strict
lgestc Aug 3, 2023
abb41c6
make sort optional by default
lgestc Aug 3, 2023
a2f200a
typing fixes
lgestc Aug 23, 2023
0bfb917
further type fixes
lgestc Aug 23, 2023
ab5f59a
more type changes
lgestc Aug 23, 2023
584fac9
separate input types
lgestc Aug 23, 2023
9d2940d
fix network sort by field
lgestc Aug 24, 2023
6c2fbec
remove unused types
lgestc Aug 25, 2023
30506ff
factory query type exports
lgestc Aug 28, 2023
4e0ae8a
strict enum type for factory query type
lgestc Aug 28, 2023
527d095
discriminated union for factory request type
lgestc Aug 30, 2023
2158481
improve parsing
lgestc Aug 30, 2023
208c78a
remove parse_options helpers
lgestc Aug 30, 2023
11f3049
fix unit tests
lgestc Aug 30, 2023
b2995aa
pr suggestions
lgestc Sep 13, 2023
4aa5d7f
pr requested changes
lgestc Sep 13, 2023
9dff579
pr changes
lgestc Sep 13, 2023
444ca97
Merge branch 'main' into hosts_api_schema
lgestc Sep 13, 2023
1a1932b
pr changes
lgestc Sep 13, 2023
5944944
remove passthroughs
lgestc Sep 13, 2023
766e198
improve types for useSearchStrategy
lgestc Sep 13, 2023
8a6e639
fix use_first_last_seen tests
lgestc Sep 14, 2023
9736cf3
Merge branch 'main' into hosts_api_schema
lgestc Sep 14, 2023
e855070
sorting non optinal in hostDetailsSchema
lgestc Sep 14, 2023
2b3c3e2
improve timelines schemas
lgestc Sep 18, 2023
8ccba2f
improve timeline types
lgestc Sep 19, 2023
fb2555d
Merge branch 'main' into hosts_api_schema
lgestc Sep 19, 2023
01ba165
remove non-public import
lgestc Sep 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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 './event_enrichment';

export * from './threat_intel_source';
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { z } from 'zod';
import { CtiQueries } from '../model/factory_query_type';
import { requestBasicOptionsSchema } from '../model/request_basic_options';
import { timerange } from '../model/timerange';

export const eventEnrichmentRequestOptionsSchema = requestBasicOptionsSchema.extend({
eventFields: z.record(z.unknown()),
lgestc marked this conversation as resolved.
Show resolved Hide resolved
timerange,
factoryQueryType: z.literal(CtiQueries.eventEnrichment),
});

export type EventEnrichmentRequestOptionsInput = z.input<
typeof eventEnrichmentRequestOptionsSchema
>;

export type EventEnrichmentRequestOptions = z.infer<typeof eventEnrichmentRequestOptionsSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { z } from 'zod';
import { CtiQueries } from '../model/factory_query_type';
import { requestBasicOptionsSchema } from '../model/request_basic_options';

export const threatIntelSourceRequestOptionsSchema = requestBasicOptionsSchema.extend({
factoryQueryType: z.literal(CtiQueries.dataSource),
});

export type ThreatIntelSourceRequestOptionsInput = z.input<
typeof threatIntelSourceRequestOptionsSchema
>;

export type ThreatIntelSourceRequestOptions = z.infer<typeof threatIntelSourceRequestOptionsSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ export const endpointFieldsRequestSchema = z.object({
onlyCheckIfIndicesExist: z.boolean(),
});

export type EndpointFieldsRequestSchemaInput = z.input<typeof endpointFieldsRequestSchema>;

export type EndpointFieldsRequestSchema = z.infer<typeof endpointFieldsRequestSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ import type { IKibanaSearchResponse } from '@kbn/data-plugin/common';

import { order } from '../model/order';
import { requestBasicOptionsSchema } from '../model/request_basic_options';
import { inspect } from '../model/inspect';
import { FirstLastSeenQuery } from '../model/factory_query_type';

export const firstLastSeenRequestOptionsSchema = requestBasicOptionsSchema.extend({
order,
field: z.string(),
value: z.string(),
factoryQueryType: z.literal(FirstLastSeenQuery),
});

export const firstLastSeenRequestOptionsSchema = z
.object({
order,
field: z.string(),
value: z.string(),
})
.extend(requestBasicOptionsSchema.partial().shape);
export type FirstLastSeenRequestOptionsInput = z.input<typeof firstLastSeenRequestOptionsSchema>;

export type FirstLastSeenRequestOptions = z.infer<typeof firstLastSeenRequestOptionsSchema>;

const inspectSchema = z.object({
dsl: z.array(z.string()),
});

export const firstLastSeenResponseSchema = z
.object({
firstSeen: z.string().nullable(),
lastSeen: z.string().nullable(),
inspect: inspectSchema,
inspect,
})
.partial();

export type FirstLastSeenStrategyResponse = z.infer<typeof firstLastSeenResponseSchema> &
export type FirstLastSeenStrategyResponse = z.input<typeof firstLastSeenResponseSchema> &
IKibanaSearchResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { z } from 'zod';
import { HostsQueries } from '../model/factory_query_type';
import { pagination } from '../model/pagination';
import { requestBasicOptionsSchema } from '../model/request_basic_options';
import { timerange } from '../model/timerange';
import { sort } from './model/sort';

export const allHostsSchema = requestBasicOptionsSchema.extend({
sort,
pagination,
timerange,
isNewRiskScoreModuleAvailable: z.boolean().default(false),
factoryQueryType: z.literal(HostsQueries.hosts),
});

export type HostsRequestOptionsInput = z.input<typeof allHostsSchema>;

export type HostsRequestOptions = z.infer<typeof allHostsSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { z } from 'zod';
import { HostsQueries } from '../model/factory_query_type';
import { inspect } from '../model/inspect';
import { pagination } from '../model/pagination';
import { requestBasicOptionsSchema } from '../model/request_basic_options';
import { timerange } from '../model/timerange';
import { sort } from './model/sort';

export const hostDetailsSchema = requestBasicOptionsSchema.extend({
hostName: z.string(),
skip: z.boolean().optional(),
inspect,
pagination: pagination.optional(),
timerange,
sort,
factoryQueryType: z.literal(HostsQueries.details),
});

export type HostDetailsRequestOptionsInput = z.input<typeof hostDetailsSchema>;

export type HostDetailsRequestOptions = z.infer<typeof hostDetailsSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 './all';

export * from './details';

export * from './overview';

export * from './uncommon_processes';

export * from './kpi_hosts';

export * from './kpi_unique_ips';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { z } from 'zod';
import { HostsKpiQueries } from '../model/factory_query_type';
import { pagination } from '../model/pagination';
import { requestBasicOptionsSchema } from '../model/request_basic_options';
import { timerange } from '../model/timerange';
import { sort } from './model/sort';

export const kpiHostsSchema = requestBasicOptionsSchema.extend({
sort,
pagination,
timerange,
factoryQueryType: z.literal(HostsKpiQueries.kpiHosts),
});

export type KpiHostsRequestOptionsInput = z.input<typeof kpiHostsSchema>;

export type KpiHostsRequestOptions = z.infer<typeof kpiHostsSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { z } from 'zod';
import { HostsKpiQueries } from '../model/factory_query_type';
import { pagination } from '../model/pagination';
import { requestBasicOptionsSchema } from '../model/request_basic_options';
import { timerange } from '../model/timerange';
import { sort } from './model/sort';

export const kpiUniqueIpsSchema = requestBasicOptionsSchema.extend({
sort,
pagination,
timerange,
factoryQueryType: z.literal(HostsKpiQueries.kpiUniqueIps),
});

export type KpiUniqueIpsRequestOptionsInput = z.input<typeof kpiUniqueIpsSchema>;

export type KpiUniqueIpsRequestOptions = z.infer<typeof kpiUniqueIpsSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 enum HostsFields {
lastSeen = 'lastSeen',
hostName = 'hostName',
success = 'success',
}

import { sort as baseSort } from '../../model/sort';

export const sort = baseSort;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { z } from 'zod';
import { HostsQueries } from '../model/factory_query_type';
import { requestBasicOptionsSchema } from '../model/request_basic_options';
import { timerange } from '../model/timerange';

export const hostOverviewSchema = requestBasicOptionsSchema.extend({
factoryQueryType: z.literal(HostsQueries.overview),
timerange,
});

export type HostOverviewRequestOptionsInput = z.input<typeof hostOverviewSchema>;

export type HostOverviewRequestOptions = z.infer<typeof hostOverviewSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { z } from 'zod';
import { HostsQueries } from '../model/factory_query_type';
import { pagination } from '../model/pagination';
import { requestBasicOptionsSchema } from '../model/request_basic_options';
import { sort } from '../model/sort';
import { timerange } from '../model/timerange';

export const hostUncommonProcessesSchema = requestBasicOptionsSchema.extend({
sort,
pagination,
timerange,
factoryQueryType: z.literal(HostsQueries.uncommonProcesses),
});

export type HostUncommonProcessesRequestOptionsInput = z.input<typeof hostUncommonProcessesSchema>;

export type HostUncommonProcessesRequestOptions = z.infer<typeof hostUncommonProcessesSchema>;
Loading