From ee2cb3392fa18e1de6205a7312c18716d0c097ee Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Thu, 19 Dec 2024 17:52:14 +0100 Subject: [PATCH] Review feedback --- .../model/api/rules/rule_migration.gen.ts | 2 +- .../api/rules/rule_migration.schema.yaml | 40 +++++++++---------- .../rules/api/util/installation.ts | 8 +--- .../rules/api/util/prebuilt_rules.ts | 8 +--- .../siem_migrations_service.ts | 2 +- 5 files changed, 26 insertions(+), 34 deletions(-) diff --git a/x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.gen.ts b/x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.gen.ts index e8e642a894d8a..7a6cbec4d2d1d 100644 --- a/x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.gen.ts +++ b/x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.gen.ts @@ -28,9 +28,9 @@ import { RuleMigrationResourceType, RuleMigrationResource, } from '../../rule_migration.gen'; +import { RelatedIntegration } from '../../../../api/detection_engine/model/rule_schema/common_attributes.gen'; import { NonEmptyString } from '../../../../api/model/primitives.gen'; import { ConnectorId, LangSmithOptions } from '../../common.gen'; -import { RelatedIntegration } from '../../../../api/detection_engine/model/rule_schema/common_attributes.gen'; export type CreateRuleMigrationRequestParams = z.infer; export const CreateRuleMigrationRequestParams = z.object({ diff --git a/x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml b/x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml index d29efb82a060d..39feb3a51897c 100644 --- a/x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml +++ b/x-pack/solutions/security/plugins/security_solution/common/siem_migrations/model/api/rules/rule_migration.schema.yaml @@ -54,6 +54,26 @@ paths: items: $ref: '../../rule_migration.schema.yaml#/components/schemas/RuleMigrationTaskStats' + /internal/siem_migrations/rules/integrations: + get: + summary: Retrieves all related integrations for a specific migration + operationId: GetRuleMigrationIntegrations + x-codegen-enabled: true + x-internal: true + description: Retrieves all related integrations + tags: + - SIEM Rule Migrations + responses: + 200: + description: Indicates that related integrations have been retrieved correctly. + content: + application/json: + schema: + type: object + description: The map of related integrations, with the integration id as a key + additionalProperties: + $ref: '../../../../../common/api/detection_engine/model/rule_schema/common_attributes.schema.yaml#/components/schemas/RelatedIntegration' + ## Specific rule migration APIs /internal/siem_migrations/rules/{migration_id}: @@ -396,26 +416,6 @@ paths: additionalProperties: $ref: '../../rule_migration.schema.yaml#/components/schemas/PrebuiltRuleVersion' - /internal/siem_migrations/rules/{migration_id}/integrations: - get: - summary: Retrieves all related integrations for a specific migration - operationId: GetRuleMigrationIntegrations - x-codegen-enabled: true - x-internal: true - description: Retrieves all related integrations - tags: - - SIEM Rule Migrations - responses: - 200: - description: Indicates that related integrations have been retrieved correctly. - content: - application/json: - schema: - type: object - description: The map of related integrations, with the integration id as a key - additionalProperties: - $ref: '../../../../../common/api/detection_engine/model/rule_schema/common_attributes.schema.yaml#/components/schemas/RelatedIntegration' - # Rule migration resources APIs /internal/siem_migrations/rules/{migration_id}/resources: diff --git a/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/rules/api/util/installation.ts b/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/rules/api/util/installation.ts index aace5ed0ab356..de95d818dd18d 100644 --- a/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/rules/api/util/installation.ts +++ b/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/rules/api/util/installation.ts @@ -15,7 +15,7 @@ import { createPrebuiltRules } from '../../../../detection_engine/prebuilt_rules import type { IDetectionRulesClient } from '../../../../detection_engine/rule_management/logic/detection_rules_client/detection_rules_client_interface'; import type { RuleResponse } from '../../../../../../common/api/detection_engine'; import type { StoredRuleMigration } from '../../types'; -import { getPrebuiltRulesByIds, getUniquePrebuiltRuleIds } from './prebuilt_rules'; +import { getPrebuiltRules, getUniquePrebuiltRuleIds } from './prebuilt_rules'; import { MAX_CUSTOM_RULES_TO_CREATE_IN_PARALLEL, MAX_TRANSLATED_RULES_TO_INSTALL, @@ -35,11 +35,7 @@ const installPrebuiltRules = async ( ): Promise => { // Get required prebuilt rules const prebuiltRulesIds = getUniquePrebuiltRuleIds(rulesToInstall); - const prebuiltRules = await getPrebuiltRulesByIds( - rulesClient, - savedObjectsClient, - prebuiltRulesIds - ); + const prebuiltRules = await getPrebuiltRules(rulesClient, savedObjectsClient, prebuiltRulesIds); const { installed: alreadyInstalledRules, installable } = Object.values(prebuiltRules).reduce( (acc, item) => { diff --git a/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/rules/api/util/prebuilt_rules.ts b/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/rules/api/util/prebuilt_rules.ts index 64d7aa8bb5f56..cf7317f0bfde0 100644 --- a/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/rules/api/util/prebuilt_rules.ts +++ b/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/rules/api/util/prebuilt_rules.ts @@ -44,7 +44,7 @@ export interface PrebuiltRulesResults { * @param rulesIds The list of IDs to filter requested prebuilt rules. If not specified, all available prebuilt rules will be returned. * @returns */ -export const getPrebuiltRulesByIds = async ( +export const getPrebuiltRules = async ( rulesClient: RulesClient, savedObjectsClient: SavedObjectsClientContract, rulesIds?: string[] @@ -113,11 +113,7 @@ export const getPrebuiltRulesForMigration = async ( } const prebuiltRulesIds = Array.from(rulesIds); - const prebuiltRules = await getPrebuiltRulesByIds( - rulesClient, - savedObjectsClient, - prebuiltRulesIds - ); + const prebuiltRules = await getPrebuiltRules(rulesClient, savedObjectsClient, prebuiltRulesIds); return prebuiltRules; }; diff --git a/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/siem_migrations_service.ts b/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/siem_migrations_service.ts index 8d30ddeb1d51e..948ae89a39bb0 100644 --- a/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/siem_migrations_service.ts +++ b/x-pack/solutions/security/plugins/security_solution/server/lib/siem_migrations/siem_migrations_service.ts @@ -31,7 +31,7 @@ export class SiemMigrationsService { } createRulesClient(params: SiemRuleMigrationsCreateClientParams): SiemRuleMigrationsClient { - return this.rules.createClient({ ...params }); + return this.rules.createClient(params); } stop() {