Skip to content

Commit 7a4e2e8

Browse files
committed
update endpoint to restrict removing with datasources
1 parent ffe5166 commit 7a4e2e8

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • x-pack/plugins/ingest_manager/server/services/epm/packages

x-pack/plugins/ingest_manager/server/services/epm/packages/remove.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import { SavedObjectsClientContract } from 'src/core/server';
88
import Boom from 'boom';
9-
import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants';
9+
import { PACKAGES_SAVED_OBJECT_TYPE, DATASOURCE_SAVED_OBJECT_TYPE } from '../../../constants';
1010
import { AssetReference, AssetType, ElasticsearchAssetType } from '../../../types';
1111
import { CallESAsCurrentUser } from '../../../types';
1212
import { getInstallation, savedObjectTypes } from './index';
1313
import { installIndexPatterns } from '../kibana/index_pattern/install';
14+
import { datasourceService } from '../..';
1415

1516
export async function removeInstallation(options: {
1617
savedObjectsClient: SavedObjectsClientContract;
@@ -26,6 +27,17 @@ export async function removeInstallation(options: {
2627
throw Boom.badRequest(`${pkgName} is installed by default and cannot be removed`);
2728
const installedObjects = installation.installed || [];
2829

30+
const { total } = await datasourceService.list(savedObjectsClient, {
31+
kuery: `${DATASOURCE_SAVED_OBJECT_TYPE}.package.name:${pkgName}`,
32+
page: 0,
33+
perPage: 0,
34+
});
35+
36+
if (total > 0)
37+
throw Boom.badRequest(
38+
`unable to remove package with existing datasource(s) in use by agent(s)`
39+
);
40+
2941
// Delete the manager saved object with references to the asset objects
3042
// could also update with [] or some other state
3143
await savedObjectsClient.delete(PACKAGES_SAVED_OBJECT_TYPE, pkgName);

0 commit comments

Comments
 (0)