-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Security Solution][Alerts] Remove legacy rules schema #137605
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
Changes from 14 commits
845f152
38317c1
07c2e3c
4c01f5b
7a79e6e
44ab4a9
5a0a141
63f7ed1
b64f9fa
9b8ffc6
9ca181f
17cddda
147b8bd
f43bedc
2e7f0bc
5d3bd8a
0ecb956
560bb8e
1649b84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,18 @@ | |
| */ | ||
|
|
||
| import { DEFAULT_INDICATOR_SOURCE_PATH } from '../../../constants'; | ||
| import type { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the changes, now we have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The tests and mocks in each folder still correspond to the Since
I think we can consolidate by moving most of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, thank you for clarifying this! Could you please add a few comments to those files to explain this:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
++ Makes total sense. I added this to #138606 as a sub-task. |
||
| EqlResponseSchema, | ||
| MachineLearningResponseSchema, | ||
| QueryResponseSchema, | ||
| SavedQueryResponseSchema, | ||
| ThreatMatchResponseSchema, | ||
| } from '../request'; | ||
| import { getListArrayMock } from '../types/lists.mock'; | ||
|
|
||
| import type { RulesSchema } from './rules_schema'; | ||
|
|
||
| export const ANCHOR_DATE = '2020-02-20T03:57:54.037Z'; | ||
|
|
||
| export const getRulesSchemaMock = (anchorDate: string = ANCHOR_DATE): RulesSchema => ({ | ||
| const getResponseBaseParams = (anchorDate: string = ANCHOR_DATE) => ({ | ||
banderror marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| author: [], | ||
| id: '7a7065d7-6e8b-4aae-8d20-c93613dec9f9', | ||
| created_at: new Date(anchorDate).toISOString(), | ||
|
|
@@ -24,45 +29,83 @@ export const getRulesSchemaMock = (anchorDate: string = ANCHOR_DATE): RulesSchem | |
| from: 'now-6m', | ||
| immutable: false, | ||
| name: 'Query with a rule id', | ||
| query: 'user.name: root or user.name: admin', | ||
| references: ['test 1', 'test 2'], | ||
| severity: 'high', | ||
| severity: 'high' as const, | ||
| severity_mapping: [], | ||
| updated_by: 'elastic_kibana', | ||
| tags: ['some fake tag 1', 'some fake tag 2'], | ||
| to: 'now', | ||
| type: 'query', | ||
| threat: [], | ||
| version: 1, | ||
| output_index: '.siem-signals-default', | ||
| max_signals: 100, | ||
| risk_score: 55, | ||
| risk_score_mapping: [], | ||
| language: 'kuery', | ||
| rule_id: 'query-rule-id', | ||
| interval: '5m', | ||
| exceptions_list: getListArrayMock(), | ||
| related_integrations: [], | ||
| required_fields: [], | ||
| setup: '', | ||
| throttle: 'no_actions', | ||
| actions: [], | ||
| building_block_type: undefined, | ||
| note: undefined, | ||
| license: undefined, | ||
| outcome: undefined, | ||
| alias_target_id: undefined, | ||
| alias_purpose: undefined, | ||
| timeline_id: undefined, | ||
| timeline_title: undefined, | ||
| meta: undefined, | ||
| rule_name_override: undefined, | ||
| timestamp_override: undefined, | ||
| timestamp_override_fallback_disabled: undefined, | ||
| namespace: undefined, | ||
| }); | ||
|
|
||
| export const getRulesMlSchemaMock = (anchorDate: string = ANCHOR_DATE): RulesSchema => { | ||
| const basePayload = getRulesSchemaMock(anchorDate); | ||
| const { filters, index, query, language, ...rest } = basePayload; | ||
| export const getRulesSchemaMock = (anchorDate: string = ANCHOR_DATE): QueryResponseSchema => ({ | ||
| ...getResponseBaseParams(anchorDate), | ||
| query: 'user.name: root or user.name: admin', | ||
| type: 'query', | ||
| language: 'kuery', | ||
| index: undefined, | ||
| data_view_id: undefined, | ||
| filters: undefined, | ||
| saved_id: undefined, | ||
| }); | ||
| export const getSavedQuerySchemaMock = ( | ||
| anchorDate: string = ANCHOR_DATE | ||
| ): SavedQueryResponseSchema => ({ | ||
| ...getResponseBaseParams(anchorDate), | ||
| query: 'user.name: root or user.name: admin', | ||
| type: 'saved_query', | ||
| saved_id: 'save id 123', | ||
| language: 'kuery', | ||
| index: undefined, | ||
| data_view_id: undefined, | ||
| filters: undefined, | ||
| }); | ||
|
|
||
| export const getRulesMlSchemaMock = ( | ||
| anchorDate: string = ANCHOR_DATE | ||
| ): MachineLearningResponseSchema => { | ||
| return { | ||
| ...rest, | ||
| ...getResponseBaseParams(anchorDate), | ||
| type: 'machine_learning', | ||
| anomaly_threshold: 59, | ||
| machine_learning_job_id: 'some_machine_learning_job_id', | ||
| }; | ||
| }; | ||
|
|
||
| export const getThreatMatchingSchemaMock = (anchorDate: string = ANCHOR_DATE): RulesSchema => { | ||
| export const getThreatMatchingSchemaMock = ( | ||
| anchorDate: string = ANCHOR_DATE | ||
| ): ThreatMatchResponseSchema => { | ||
| return { | ||
| ...getRulesSchemaMock(anchorDate), | ||
| ...getResponseBaseParams(anchorDate), | ||
| type: 'threat_match', | ||
| query: 'user.name: root or user.name: admin', | ||
| language: 'kuery', | ||
| threat_index: ['index-123'], | ||
| threat_mapping: [{ entries: [{ field: 'host.name', type: 'mapping', value: 'host.name' }] }], | ||
| threat_query: '*:*', | ||
|
|
@@ -84,14 +127,24 @@ export const getThreatMatchingSchemaMock = (anchorDate: string = ANCHOR_DATE): R | |
| }, | ||
| }, | ||
| ], | ||
| index: undefined, | ||
| data_view_id: undefined, | ||
| filters: undefined, | ||
| saved_id: undefined, | ||
| threat_indicator_path: undefined, | ||
| threat_language: undefined, | ||
| concurrent_searches: undefined, | ||
| items_per_search: undefined, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Useful for e2e backend tests where it doesn't have date time and other | ||
| * server side properties attached to it. | ||
| */ | ||
| export const getThreatMatchingSchemaPartialMock = (enabled = false): Partial<RulesSchema> => { | ||
| export const getThreatMatchingSchemaPartialMock = ( | ||
| enabled = false | ||
| ): Partial<ThreatMatchResponseSchema> => { | ||
| return { | ||
| author: [], | ||
| created_by: 'elastic', | ||
|
|
@@ -160,11 +213,17 @@ export const getThreatMatchingSchemaPartialMock = (enabled = false): Partial<Rul | |
| }; | ||
| }; | ||
|
|
||
| export const getRulesEqlSchemaMock = (anchorDate: string = ANCHOR_DATE): RulesSchema => { | ||
| export const getRulesEqlSchemaMock = (anchorDate: string = ANCHOR_DATE): EqlResponseSchema => { | ||
| return { | ||
| ...getRulesSchemaMock(anchorDate), | ||
| ...getResponseBaseParams(anchorDate), | ||
| language: 'eql', | ||
| type: 'eql', | ||
| query: 'process where true', | ||
| index: undefined, | ||
| data_view_id: undefined, | ||
| filters: undefined, | ||
| timestamp_field: undefined, | ||
| event_category_override: undefined, | ||
| tiebreaker_field: undefined, | ||
| }; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's use either
baseorsharednaming but not bothThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharedResponseSchemahere is equivalent tosharedCreateSchemaorsharedUpdateSchemabut for the response instead, whereasbasecomes from thebaseParamsthat form the basis of the create, update, patch, and response schemas. What do you think we should rename here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably rename
baseParamstosharedParamsetc. But I'm nitpicking here, the naming as it is now is clear enough, so feel free to ignore the suggestion.