From bb89371c766b8cd0975bdedf1395bdec1b79e088 Mon Sep 17 00:00:00 2001 From: jpdjere Date: Thu, 11 Jul 2024 12:02:45 +0200 Subject: [PATCH 1/2] Remove remaining usage of rule_schema_legacy types --- .../rule_schema_legacy/common_attributes.ts | 60 ------------------- .../model/rule_schema_legacy/index.ts | 8 --- .../find_exception_references_route.ts | 13 +++- .../common/api/timeline/model/api.ts | 31 ++++++++-- 4 files changed, 35 insertions(+), 77 deletions(-) delete mode 100644 x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/common_attributes.ts delete mode 100644 x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/index.ts diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/common_attributes.ts b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/common_attributes.ts deleted file mode 100644 index ba07c49a7b130..0000000000000 --- a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/common_attributes.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 t from 'io-ts'; -import { NonEmptyString, UUID } from '@kbn/securitysolution-io-ts-types'; - -/* -IMPORTANT NOTE ON THIS FILE: - -This file contains the remaining rule schema types created manually via io-ts. They have been -migrated to Zod schemas created via code generation out of OpenAPI schemas -(found in x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema/common_attributes.gen.ts) - -The remaining types here couldn't easily be deleted/replaced because they are dependencies in -complex derived schemas in two files: - -- x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts -- x-pack/plugins/security_solution/common/api/timeline/model/api.ts - -Once those two files are migrated to Zod, the /common/api/detection_engine/model/rule_schema_legacy -folder can be removed. -*/ - -export type RuleObjectId = t.TypeOf; -export const RuleObjectId = UUID; - -/** - * NOTE: Never make this a strict uuid, we allow the rule_id to be any string at the moment - * in case we encounter 3rd party rule systems which might be using auto incrementing numbers - * or other different things. - */ -export type RuleSignatureId = t.TypeOf; -export const RuleSignatureId = t.string; // should be non-empty string? - -export type RuleName = t.TypeOf; -export const RuleName = NonEmptyString; - -/** - * Outcome is a property of the saved object resolve api - * will tell us info about the rule after 8.0 migrations - */ -export type SavedObjectResolveOutcome = t.TypeOf; -export const SavedObjectResolveOutcome = t.union([ - t.literal('exactMatch'), - t.literal('aliasMatch'), - t.literal('conflict'), -]); - -export type SavedObjectResolveAliasTargetId = t.TypeOf; -export const SavedObjectResolveAliasTargetId = t.string; - -export type SavedObjectResolveAliasPurpose = t.TypeOf; -export const SavedObjectResolveAliasPurpose = t.union([ - t.literal('savedObjectConversion'), - t.literal('savedObjectImport'), -]); diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/index.ts b/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/index.ts deleted file mode 100644 index a112f6ca1b29f..0000000000000 --- a/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema_legacy/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * 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 './common_attributes'; diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts b/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts index cbef9a41de718..de052e2a8b1aa 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts @@ -12,10 +12,17 @@ import { list_id, DefaultNamespaceArray, } from '@kbn/securitysolution-io-ts-list-types'; -import { NonEmptyStringArray } from '@kbn/securitysolution-io-ts-types'; +import { NonEmptyStringArray, NonEmptyString, UUID } from '@kbn/securitysolution-io-ts-types'; + // TODO https://github.com/elastic/security-team/issues/7491 -// eslint-disable-next-line no-restricted-imports -import { RuleName, RuleObjectId, RuleSignatureId } from '../../model/rule_schema_legacy'; +export type RuleObjectId = t.TypeOf; +export const RuleObjectId = UUID; + +export type RuleSignatureId = t.TypeOf; +export const RuleSignatureId = t.string; + +export type RuleName = t.TypeOf; +export const RuleName = NonEmptyString; // If ids and list_ids are undefined, route will fetch all lists matching the // specified namespace type diff --git a/x-pack/plugins/security_solution/common/api/timeline/model/api.ts b/x-pack/plugins/security_solution/common/api/timeline/model/api.ts index 3e69bd14b646c..10b12aee32f2f 100644 --- a/x-pack/plugins/security_solution/common/api/timeline/model/api.ts +++ b/x-pack/plugins/security_solution/common/api/timeline/model/api.ts @@ -15,12 +15,31 @@ import { Direction } from '../../../search_strategy'; import type { PinnedEvent } from '../pinned_events/pinned_events_route'; import { PinnedEventRuntimeType } from '../pinned_events/pinned_events_route'; // TODO https://github.com/elastic/security-team/issues/7491 -// eslint-disable-next-line no-restricted-imports -import { - SavedObjectResolveAliasPurpose, - SavedObjectResolveAliasTargetId, - SavedObjectResolveOutcome, -} from '../../detection_engine/model/rule_schema_legacy'; + +/** + * Outcome is a property of the saved object resolve api + * will tell us info about the rule after 8.0 migrations + */ +export type SavedObjectResolveOutcome = runtimeTypes.TypeOf; +export const SavedObjectResolveOutcome = runtimeTypes.union([ + runtimeTypes.literal('exactMatch'), + runtimeTypes.literal('aliasMatch'), + runtimeTypes.literal('conflict'), +]); + +export type SavedObjectResolveAliasTargetId = runtimeTypes.TypeOf< + typeof SavedObjectResolveAliasTargetId +>; +export const SavedObjectResolveAliasTargetId = runtimeTypes.string; + +export type SavedObjectResolveAliasPurpose = runtimeTypes.TypeOf< + typeof SavedObjectResolveAliasPurpose +>; +export const SavedObjectResolveAliasPurpose = runtimeTypes.union([ + runtimeTypes.literal('savedObjectConversion'), + runtimeTypes.literal('savedObjectImport'), +]); + import { ErrorSchema } from './error_schema'; export const BareNoteSchema = runtimeTypes.intersection([ From 218adc416103f42684e666885d9ad8a86bfba918 Mon Sep 17 00:00:00 2001 From: jpdjere Date: Fri, 19 Jul 2024 10:14:32 +0200 Subject: [PATCH 2/2] remove export --- .../find_exception_references_route.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts b/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts index de052e2a8b1aa..63b9363bb97c4 100644 --- a/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts +++ b/x-pack/plugins/security_solution/common/api/detection_engine/rule_exceptions/find_exception_references/find_exception_references_route.ts @@ -15,14 +15,14 @@ import { import { NonEmptyStringArray, NonEmptyString, UUID } from '@kbn/securitysolution-io-ts-types'; // TODO https://github.com/elastic/security-team/issues/7491 -export type RuleObjectId = t.TypeOf; -export const RuleObjectId = UUID; +type RuleObjectId = t.TypeOf; +const RuleObjectId = UUID; -export type RuleSignatureId = t.TypeOf; -export const RuleSignatureId = t.string; +type RuleSignatureId = t.TypeOf; +const RuleSignatureId = t.string; -export type RuleName = t.TypeOf; -export const RuleName = NonEmptyString; +type RuleName = t.TypeOf; +const RuleName = NonEmptyString; // If ids and list_ids are undefined, route will fetch all lists matching the // specified namespace type