Skip to content

Commit

Permalink
Remove ingest pipelines on package deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
skh committed Oct 21, 2019
1 parent 92848d8 commit fc737b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export async function handleRequestInstall(req: InstallPackageRequest, extra: Ex
export async function handleRequestDelete(req: DeletePackageRequest, extra: Extra) {
const { pkgkey } = req.params;
const savedObjectsClient = getClient(req);
const deleted = await removeInstallation({ savedObjectsClient, pkgkey });
const callCluster = getClusterAccessor(extra.context.esClient, req);
const deleted = await removeInstallation({ savedObjectsClient, pkgkey, callCluster });

return deleted;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

import { SavedObjectsClientContract } from 'src/core/server/';
import { SAVED_OBJECT_TYPE } from '../../common/constants';
import { getInstallationObject } from './index';
import { getInstallationObject, assetUsesObjects, CallESAsCurrentUser } from './index';
import { AssetType } from '../../common/types';

export async function removeInstallation(options: {
savedObjectsClient: SavedObjectsClientContract;
pkgkey: string;
callCluster: CallESAsCurrentUser;
}) {
const { savedObjectsClient, pkgkey } = options;
const { savedObjectsClient, pkgkey, callCluster } = options;
const installation = await getInstallationObject({ savedObjectsClient, pkgkey });
const installedObjects = (installation && installation.attributes.installed) || [];

Expand All @@ -21,11 +23,22 @@ export async function removeInstallation(options: {
await savedObjectsClient.delete(SAVED_OBJECT_TYPE, pkgkey);

// Delete the installed assets
const deletePromises = installedObjects.map(async ({ id, type }) =>
savedObjectsClient.delete(type, id)
);
const deletePromises = installedObjects.map(async ({ id, type }) => {
if (assetUsesObjects(type as AssetType)) {
savedObjectsClient.delete(type, id);
} else if (type === AssetType.ingestPipeline) {
deletePipeline(callCluster, id);
}
});
await Promise.all(deletePromises);

// successful delete's in SO client return {}. return something more useful
return installedObjects;
}

async function deletePipeline(callCluster: CallESAsCurrentUser, id: string): Promise<any> {
// '*' shouldn't ever appear here, but it still would delete all ingest pipelines
if (id && id !== '*') {
await callCluster('ingest.deletePipeline', { id });
}
}

0 comments on commit fc737b1

Please sign in to comment.