File tree Expand file tree Collapse file tree
x-pack/plugins/ingest_manager/server/services/epm/packages Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77import { SavedObjectsClientContract } from 'src/core/server' ;
88import Boom from 'boom' ;
9- import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants' ;
9+ import { PACKAGES_SAVED_OBJECT_TYPE , DATASOURCE_SAVED_OBJECT_TYPE } from '../../../constants' ;
1010import { AssetReference , AssetType , ElasticsearchAssetType } from '../../../types' ;
1111import { CallESAsCurrentUser } from '../../../types' ;
1212import { getInstallation , savedObjectTypes } from './index' ;
1313import { installIndexPatterns } from '../kibana/index_pattern/install' ;
14+ import { datasourceService } from '../..' ;
1415
1516export 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 ) ;
You can’t perform that action at this time.
0 commit comments