-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution]
DetectionRulesClient
: various refactorings (#18…
…4954) **Partially addresses: #184364 ## Summary This PR contains various smaller-scale refactorings for the recently added `DetectionsRuleClient`. **Changes**: - Renamed `DetectionRulesClient` containing directory from `rule_management` to `detection_rules_client` - Moved `DetectionRulesClient` methods into the `detection_rules_client/methods` dir - Moved the TS interface of `DetectionRulesClient` into a separate file `detection_rules_client_interface.ts` - Simplified `importRule` method parameters - Added memoization to `getDetectionRulesClient` --------- Co-authored-by: Georgii Gorbachev <banderror@gmail.com>
- Loading branch information
1 parent
87f6c1d
commit 41c34e0
Showing
48 changed files
with
519 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...b/detection_engine/rule_management/logic/detection_rules_client/detection_rules_client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 type { RulesClient } from '@kbn/alerting-plugin/server'; | ||
import type { MlAuthz } from '../../../../machine_learning/authz'; | ||
|
||
import type { RuleAlertType } from '../../../rule_schema'; | ||
import type { | ||
IDetectionRulesClient, | ||
CreateCustomRuleArgs, | ||
CreatePrebuiltRuleArgs, | ||
UpdateRuleArgs, | ||
PatchRuleArgs, | ||
DeleteRuleArgs, | ||
UpgradePrebuiltRuleArgs, | ||
ImportRuleArgs, | ||
} from './detection_rules_client_interface'; | ||
|
||
import { createCustomRule } from './methods/create_custom_rule'; | ||
import { createPrebuiltRule } from './methods/create_prebuilt_rule'; | ||
import { updateRule } from './methods/update_rule'; | ||
import { patchRule } from './methods/patch_rule'; | ||
import { deleteRule } from './methods/delete_rule'; | ||
import { upgradePrebuiltRule } from './methods/upgrade_prebuilt_rule'; | ||
import { importRule } from './methods/import_rule'; | ||
|
||
import { withSecuritySpan } from '../../../../../utils/with_security_span'; | ||
|
||
export const createDetectionRulesClient = ( | ||
rulesClient: RulesClient, | ||
mlAuthz: MlAuthz | ||
): IDetectionRulesClient => ({ | ||
async createCustomRule(args: CreateCustomRuleArgs): Promise<RuleAlertType> { | ||
return withSecuritySpan('DetectionRulesClient.createCustomRule', async () => { | ||
return createCustomRule(rulesClient, args, mlAuthz); | ||
}); | ||
}, | ||
|
||
async createPrebuiltRule(args: CreatePrebuiltRuleArgs): Promise<RuleAlertType> { | ||
return withSecuritySpan('DetectionRulesClient.createPrebuiltRule', async () => { | ||
return createPrebuiltRule(rulesClient, args, mlAuthz); | ||
}); | ||
}, | ||
|
||
async updateRule(args: UpdateRuleArgs): Promise<RuleAlertType> { | ||
return withSecuritySpan('DetectionRulesClient.updateRule', async () => { | ||
return updateRule(rulesClient, args, mlAuthz); | ||
}); | ||
}, | ||
|
||
async patchRule(args: PatchRuleArgs): Promise<RuleAlertType> { | ||
return withSecuritySpan('DetectionRulesClient.patchRule', async () => { | ||
return patchRule(rulesClient, args, mlAuthz); | ||
}); | ||
}, | ||
|
||
async deleteRule(args: DeleteRuleArgs): Promise<void> { | ||
return withSecuritySpan('DetectionRulesClient.deleteRule', async () => { | ||
return deleteRule(rulesClient, args); | ||
}); | ||
}, | ||
|
||
async upgradePrebuiltRule(args: UpgradePrebuiltRuleArgs): Promise<RuleAlertType> { | ||
return withSecuritySpan('DetectionRulesClient.upgradePrebuiltRule', async () => { | ||
return upgradePrebuiltRule(rulesClient, args, mlAuthz); | ||
}); | ||
}, | ||
|
||
async importRule(args: ImportRuleArgs): Promise<RuleAlertType> { | ||
return withSecuritySpan('DetectionRulesClient.importRule', async () => { | ||
return importRule(rulesClient, args, mlAuthz); | ||
}); | ||
}, | ||
}); |
Oops, something went wrong.