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

[8.x] [Rules migration] ES|QL query editing and validation in translation tab in the flyout (#11381) (#203601) #204078

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
import { z } from '@kbn/zod';
import { ArrayFromString } from '@kbn/zod-helpers';

import { NonEmptyString } from '../../../../api/model/primitives.gen';
import {
ElasticRulePartial,
RuleMigrationTranslationResult,
RuleMigrationComments,
UpdateRuleMigrationData,
RuleMigrationTaskStats,
OriginalRule,
RuleMigration,
Expand All @@ -31,6 +28,7 @@ import {
RuleMigrationResourceType,
RuleMigrationResource,
} from '../../rule_migration.gen';
import { NonEmptyString } from '../../../../api/model/primitives.gen';
import { ConnectorId, LangSmithOptions } from '../../common.gen';

export type CreateRuleMigrationRequestParams = z.infer<typeof CreateRuleMigrationRequestParams>;
Expand Down Expand Up @@ -62,6 +60,7 @@ export const GetRuleMigrationRequestQuery = z.object({
sort_field: NonEmptyString.optional(),
sort_direction: z.enum(['asc', 'desc']).optional(),
search_term: z.string().optional(),
ids: ArrayFromString(NonEmptyString).optional(),
});
export type GetRuleMigrationRequestQueryInput = z.input<typeof GetRuleMigrationRequestQuery>;

Expand Down Expand Up @@ -231,26 +230,7 @@ export const StopRuleMigrationResponse = z.object({
});

export type UpdateRuleMigrationRequestBody = z.infer<typeof UpdateRuleMigrationRequestBody>;
export const UpdateRuleMigrationRequestBody = z.array(
z.object({
/**
* The rule migration id
*/
id: NonEmptyString,
/**
* The migrated elastic rule attributes to update.
*/
elastic_rule: ElasticRulePartial.optional(),
/**
* The rule translation result.
*/
translation_result: RuleMigrationTranslationResult.optional(),
/**
* The comments for the migration including a summary from the LLM in markdown.
*/
comments: RuleMigrationComments.optional(),
})
);
export const UpdateRuleMigrationRequestBody = z.array(UpdateRuleMigrationData);
export type UpdateRuleMigrationRequestBodyInput = z.input<typeof UpdateRuleMigrationRequestBody>;

export type UpdateRuleMigrationResponse = z.infer<typeof UpdateRuleMigrationResponse>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,7 @@ paths:
schema:
type: array
items:
type: object
required:
- id
properties:
id:
description: The rule migration id
$ref: '../../../../../common/api/model/primitives.schema.yaml#/components/schemas/NonEmptyString'
elastic_rule:
description: The migrated elastic rule attributes to update.
$ref: '../../rule_migration.schema.yaml#/components/schemas/ElasticRulePartial'
translation_result:
description: The rule translation result.
$ref: '../../rule_migration.schema.yaml#/components/schemas/RuleMigrationTranslationResult'
comments:
description: The comments for the migration including a summary from the LLM in markdown.
$ref: '../../rule_migration.schema.yaml#/components/schemas/RuleMigrationComments'
$ref: '../../rule_migration.schema.yaml#/components/schemas/UpdateRuleMigrationData'
responses:
200:
description: Indicates rules migrations have been updated correctly.
Expand Down Expand Up @@ -151,6 +136,14 @@ paths:
required: false
schema:
type: string
- name: ids
in: query
required: false
schema:
type: array
items:
description: The rule migration id
$ref: '../../../../../common/api/model/primitives.schema.yaml#/components/schemas/NonEmptyString'

responses:
200:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,29 @@ export const RuleMigrationTranslationStats = z.object({
}),
});

/**
* The rule migration data object for rule update operation
*/
export type UpdateRuleMigrationData = z.infer<typeof UpdateRuleMigrationData>;
export const UpdateRuleMigrationData = z.object({
/**
* The rule migration id
*/
id: NonEmptyString,
/**
* The migrated elastic rule attributes to update.
*/
elastic_rule: ElasticRulePartial.optional(),
/**
* The rule translation result.
*/
translation_result: RuleMigrationTranslationResult.optional(),
/**
* The comments for the migration including a summary from the LLM in markdown.
*/
comments: RuleMigrationComments.optional(),
});

/**
* The type of the rule migration resource.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ components:
items:
type: string

UpdateRuleMigrationData:
type: object
description: The rule migration data object for rule update operation
required:
- id
properties:
id:
description: The rule migration id
$ref: '../../../common/api/model/primitives.schema.yaml#/components/schemas/NonEmptyString'
elastic_rule:
description: The migrated elastic rule attributes to update.
$ref: '#/components/schemas/ElasticRulePartial'
translation_result:
description: The rule translation result.
$ref: '#/components/schemas/RuleMigrationTranslationResult'
comments:
description: The comments for the migration including a summary from the LLM in markdown.
$ref: '#/components/schemas/RuleMigrationComments'

## Rule migration resources

RuleMigrationResourceType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { replaceParams } from '@kbn/openapi-common/shared';

import type { UpdateRuleMigrationData } from '../../../../common/siem_migrations/model/rule_migration.gen';
import type { LangSmithOptions } from '../../../../common/siem_migrations/model/common.gen';
import { KibanaServices } from '../../../common/lib/kibana';

Expand All @@ -32,6 +33,7 @@ import type {
StartRuleMigrationRequestBody,
GetRuleMigrationStatsResponse,
GetRuleMigrationPrebuiltRulesResponse,
UpdateRuleMigrationResponse,
} from '../../../../common/siem_migrations/model/api/rules/rule_migration.gen';

export interface GetRuleMigrationStatsParams {
Expand Down Expand Up @@ -126,6 +128,8 @@ export interface GetRuleMigrationParams {
sortDirection?: 'asc' | 'desc';
/** Optional search term to filter documents */
searchTerm?: string;
/** Optional rules ids to filter documents */
ids?: string[];
/** Optional AbortSignal for cancelling request */
signal?: AbortSignal;
}
Expand All @@ -137,6 +141,7 @@ export const getRuleMigrations = async ({
sortField,
sortDirection,
searchTerm,
ids,
signal,
}: GetRuleMigrationParams): Promise<GetRuleMigrationResponse> => {
return KibanaServices.get().http.get<GetRuleMigrationResponse>(
Expand All @@ -149,6 +154,7 @@ export const getRuleMigrations = async ({
sort_field: sortField,
sort_direction: sortDirection,
search_term: searchTerm,
ids,
},
signal,
}
Expand Down Expand Up @@ -230,3 +236,21 @@ export const getRuleMigrationsPrebuiltRules = async ({
{ version: '1', signal }
);
};

export interface UpdateRulesParams {
/** The list of migration rules data to update */
rulesToUpdate: UpdateRuleMigrationData[];
/** Optional AbortSignal for cancelling request */
signal?: AbortSignal;
}
/** Updates provided migration rules. */
export const updateMigrationRules = async ({
rulesToUpdate,
signal,
}: UpdateRulesParams): Promise<UpdateRuleMigrationResponse> => {
return KibanaServices.get().http.put<UpdateRuleMigrationResponse>(SIEM_RULE_MIGRATIONS_PATH, {
version: '1',
body: JSON.stringify(rulesToUpdate),
signal,
});
};
Loading
Loading