mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
update endpoint to restrict removing with datasources (#64978)
This commit is contained in:
parent
5bcf2c8b89
commit
3356a19294
1 changed files with 13 additions and 1 deletions
|
@ -6,11 +6,12 @@
|
|||
|
||||
import { SavedObjectsClientContract } from 'src/core/server';
|
||||
import Boom from 'boom';
|
||||
import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants';
|
||||
import { PACKAGES_SAVED_OBJECT_TYPE, DATASOURCE_SAVED_OBJECT_TYPE } from '../../../constants';
|
||||
import { AssetReference, AssetType, ElasticsearchAssetType } from '../../../types';
|
||||
import { CallESAsCurrentUser } from '../../../types';
|
||||
import { getInstallation, savedObjectTypes } from './index';
|
||||
import { installIndexPatterns } from '../kibana/index_pattern/install';
|
||||
import { datasourceService } from '../..';
|
||||
|
||||
export async function removeInstallation(options: {
|
||||
savedObjectsClient: SavedObjectsClientContract;
|
||||
|
@ -26,6 +27,17 @@ export async function removeInstallation(options: {
|
|||
throw Boom.badRequest(`${pkgName} is installed by default and cannot be removed`);
|
||||
const installedObjects = installation.installed || [];
|
||||
|
||||
const { total } = await datasourceService.list(savedObjectsClient, {
|
||||
kuery: `${DATASOURCE_SAVED_OBJECT_TYPE}.package.name:${pkgName}`,
|
||||
page: 0,
|
||||
perPage: 0,
|
||||
});
|
||||
|
||||
if (total > 0)
|
||||
throw Boom.badRequest(
|
||||
`unable to remove package with existing datasource(s) in use by agent(s)`
|
||||
);
|
||||
|
||||
// Delete the manager saved object with references to the asset objects
|
||||
// could also update with [] or some other state
|
||||
await savedObjectsClient.delete(PACKAGES_SAVED_OBJECT_TYPE, pkgName);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue