From 6b920aba72f963cc0d42820e12cfad2202e6f235 Mon Sep 17 00:00:00 2001 From: Patryk Kopycinski Date: Sun, 7 Jun 2020 17:06:53 +0200 Subject: [PATCH] Fix case and security_solution types --- x-pack/plugins/case/server/routes/api/utils.ts | 2 +- .../detection_engine/schemas/common/schemas.ts | 6 +++--- .../anomalies/anomalies_query_tab_body/types.ts | 17 +++++++++++++---- .../models/process_event_test_helpers.ts | 4 ++-- .../signals/search_after_bulk_create.ts | 3 ++- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/case/server/routes/api/utils.ts b/x-pack/plugins/case/server/routes/api/utils.ts index fb199442f9425a..b7f3c68d1662fa 100644 --- a/x-pack/plugins/case/server/routes/api/utils.ts +++ b/x-pack/plugins/case/server/routes/api/utils.ts @@ -132,8 +132,8 @@ export const flattenCaseSavedObject = ({ version: savedObject.version ?? '0', comments: flattenCommentSavedObjects(comments), totalComment, - connector_id: savedObject.attributes.connector_id ?? caseConfigureConnectorId, ...savedObject.attributes, + connector_id: savedObject.attributes.connector_id ?? caseConfigureConnectorId, }); export const transformComments = ( diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts index 9eb2d9abccbd3c..b9f30101b148b3 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts @@ -23,7 +23,7 @@ export const file_name = t.string; * TODO: Right now the filters is an "unknown", when it could more than likely * become the actual ESFilter as a type. */ -export const filters = t.array(t.unknown); // Filters are not easily type-able yet +export const filters = t.array(t.record(t.string, t.unknown)); // Filters are not easily type-able yet /** * Params is an "object", since it is a type of AlertActionParams which is action templates. @@ -32,7 +32,7 @@ export const filters = t.array(t.unknown); // Filters are not easily type-able y export const action_group = t.string; export const action_id = t.string; export const action_action_type_id = t.string; -export const action_params = t.object; +export const action_params = t.record(t.string, t.union([t.string, t.array(t.string)])); export const action = t.exact( t.type({ group: action_group, @@ -75,7 +75,7 @@ export const machine_learning_job_id = t.string; * TODO: Strip away extra information and possibly even "freeze" this object * so we have tighter control over 3rd party data structures. */ -export const meta = t.object; +export const meta = t.record(t.string, t.string); export const max_signals = PositiveIntegerGreaterThanZero; export const name = t.string; export const risk_score = RiskScore; diff --git a/x-pack/plugins/security_solution/public/common/containers/anomalies/anomalies_query_tab_body/types.ts b/x-pack/plugins/security_solution/public/common/containers/anomalies/anomalies_query_tab_body/types.ts index ecf4c3590a42c2..19f6e2fb367d3c 100644 --- a/x-pack/plugins/security_solution/public/common/containers/anomalies/anomalies_query_tab_body/types.ts +++ b/x-pack/plugins/security_solution/public/common/containers/anomalies/anomalies_query_tab_body/types.ts @@ -5,14 +5,16 @@ */ import { ESTermQuery } from '../../../../../common/typed_json'; -import { NarrowDateRange } from '../../../components/ml/types'; +import { + AnomaliesHostTableProps, + AnomaliesNetworkTableProps, + NarrowDateRange, +} from '../../../components/ml/types'; import { UpdateDateRange } from '../../../components/charts/common'; import { SetQuery } from '../../../../hosts/pages/navigation/types'; import { FlowTarget } from '../../../../graphql/types'; import { HostsType } from '../../../../hosts/store/model'; import { NetworkType } from '../../../../network/store//model'; -import { AnomaliesHostTable } from '../../../components/ml/tables/anomalies_host_table'; -import { AnomaliesNetworkTable } from '../../../components/ml/tables/anomalies_network_table'; interface QueryTabBodyProps { type: HostsType | NetworkType; @@ -21,7 +23,14 @@ interface QueryTabBodyProps { export type AnomaliesQueryTabBodyProps = QueryTabBodyProps & { anomaliesFilterQuery?: object; - AnomaliesTableComponent: typeof AnomaliesHostTable | typeof AnomaliesNetworkTable; + AnomaliesTableComponent: React.NamedExoticComponent< + | (AnomaliesHostTableProps & { + type: HostsType & NetworkType; + }) + | (AnomaliesNetworkTableProps & { + type: HostsType & NetworkType; + }) + >; deleteQuery?: ({ id }: { id: string }) => void; endDate: number; flowTarget?: FlowTarget; diff --git a/x-pack/plugins/security_solution/public/resolver/models/process_event_test_helpers.ts b/x-pack/plugins/security_solution/public/resolver/models/process_event_test_helpers.ts index be0895dbec4fe1..568b7ddd27b226 100644 --- a/x-pack/plugins/security_solution/public/resolver/models/process_event_test_helpers.ts +++ b/x-pack/plugins/security_solution/public/resolver/models/process_event_test_helpers.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { defaults } from 'lodash/fp'; +import { defaultsDeep } from 'lodash/fp'; import { LegacyEndpointEvent } from '../../../common/endpoint/types'; type DeepPartial = { [K in keyof T]?: DeepPartial }; @@ -15,7 +15,7 @@ type DeepPartial = { [K in keyof T]?: DeepPartial }; * The other fields are populated by the function unless provided in 'parts' */ export function mockProcessEvent(parts: DeepPartial): LegacyEndpointEvent { - return defaults( + return defaultsDeep( { endgame: { event_timestamp: 1, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.ts index e44b82224d1cee..038a75d7f3ac18 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.ts @@ -103,6 +103,7 @@ export const searchAfterAndBulkCreate = async ({ try { logger.debug(`sortIds: ${sortId}`); const { + // @ts-ignore https://github.com/microsoft/TypeScript/issues/35546 searchResult, searchDuration, }: { searchResult: SignalSearchResponse; searchDuration: string } = await singleSearchAfter({ @@ -140,7 +141,7 @@ export const searchAfterAndBulkCreate = async ({ // filter out the search results that match with the values found in the list. // the resulting set are valid signals that are not on the allowlist. - const filteredEvents = + const filteredEvents: SignalSearchResponse = listClient != null ? await filterEventsAgainstList({ listClient,