-
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] Fix prebuilt rules installation when the detectio…
…n engine package is missing (#150181)
- Loading branch information
Showing
10 changed files
with
304 additions
and
186 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
113 changes: 0 additions & 113 deletions
113
x-pack/plugins/security_solution/public/common/hooks/use_upgrade_security_packages.ts
This file was deleted.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
...ic/detection_engine/rule_management/api/hooks/use_bulk_install_fleet_packages_mutation.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,44 @@ | ||
/* | ||
* 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 { EPM_API_ROUTES } from '@kbn/fleet-plugin/common'; | ||
import type { BulkInstallPackagesResponse } from '@kbn/fleet-plugin/common/types'; | ||
import type { UseMutationOptions } from '@tanstack/react-query'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { PREBUILT_RULES_PACKAGE_NAME } from '../../../../../common/detection_engine/constants'; | ||
import type { BulkInstallFleetPackagesProps } from '../api'; | ||
import { bulkInstallFleetPackages } from '../api'; | ||
import { useInvalidateFetchPrebuiltRulesStatusQuery } from './use_fetch_prebuilt_rules_status_query'; | ||
|
||
export const BULK_INSTALL_FLEET_PACKAGES_MUTATION_KEY = [ | ||
'POST', | ||
EPM_API_ROUTES.BULK_INSTALL_PATTERN, | ||
]; | ||
|
||
export const useBulkInstallFleetPackagesMutation = ( | ||
options?: UseMutationOptions<BulkInstallPackagesResponse, Error, BulkInstallFleetPackagesProps> | ||
) => { | ||
const invalidatePrePackagedRulesStatus = useInvalidateFetchPrebuiltRulesStatusQuery(); | ||
|
||
return useMutation((props: BulkInstallFleetPackagesProps) => bulkInstallFleetPackages(props), { | ||
...options, | ||
mutationKey: BULK_INSTALL_FLEET_PACKAGES_MUTATION_KEY, | ||
onSettled: (...args) => { | ||
const response = args[0]; | ||
const rulesPackage = response?.items.find( | ||
(item) => item.name === PREBUILT_RULES_PACKAGE_NAME | ||
); | ||
if (rulesPackage && 'result' in rulesPackage && rulesPackage.result.status === 'installed') { | ||
// The rules package was installed/updated, so invalidate the pre-packaged rules status query | ||
invalidatePrePackagedRulesStatus(); | ||
} | ||
|
||
if (options?.onSettled) { | ||
options.onSettled(...args); | ||
} | ||
}, | ||
}); | ||
}; |
41 changes: 41 additions & 0 deletions
41
...n/public/detection_engine/rule_management/api/hooks/use_install_fleet_package_mutation.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,41 @@ | ||
/* | ||
* 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 { EPM_API_ROUTES } from '@kbn/fleet-plugin/common'; | ||
import type { InstallPackageResponse } from '@kbn/fleet-plugin/common/types'; | ||
import type { UseMutationOptions } from '@tanstack/react-query'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { PREBUILT_RULES_PACKAGE_NAME } from '../../../../../common/detection_engine/constants'; | ||
import type { InstallFleetPackageProps } from '../api'; | ||
import { installFleetPackage } from '../api'; | ||
import { useInvalidateFetchPrebuiltRulesStatusQuery } from './use_fetch_prebuilt_rules_status_query'; | ||
|
||
export const INSTALL_FLEET_PACKAGE_MUTATION_KEY = [ | ||
'POST', | ||
EPM_API_ROUTES.INSTALL_FROM_REGISTRY_PATTERN, | ||
]; | ||
|
||
export const useInstallFleetPackageMutation = ( | ||
options?: UseMutationOptions<InstallPackageResponse, Error, InstallFleetPackageProps> | ||
) => { | ||
const invalidatePrePackagedRulesStatus = useInvalidateFetchPrebuiltRulesStatusQuery(); | ||
|
||
return useMutation((props: InstallFleetPackageProps) => installFleetPackage(props), { | ||
...options, | ||
mutationKey: INSTALL_FLEET_PACKAGE_MUTATION_KEY, | ||
onSettled: (...args) => { | ||
const { packageName } = args[2]; | ||
if (packageName === PREBUILT_RULES_PACKAGE_NAME) { | ||
// Invalidate the pre-packaged rules status query as there might be new rules to install | ||
invalidatePrePackagedRulesStatus(); | ||
} | ||
|
||
if (options?.onSettled) { | ||
options.onSettled(...args); | ||
} | ||
}, | ||
}); | ||
}; |
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
Oops, something went wrong.