Skip to content

Commit

Permalink
fix delete asset check on force upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hop-dev committed Dec 3, 2021
1 parent db43daa commit 8382974
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions x-pack/plugins/fleet/server/services/epm/packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import type { SavedObject } from 'src/core/server';

import { unremovablePackages, installationStatuses } from '../../../../common';
import {
unremovablePackages,
installationStatuses,
KibanaSavedObjectType,
} from '../../../../common';
import { KibanaAssetType } from '../../../types';
import type { AssetType, Installable, Installation } from '../../../types';

Expand Down Expand Up @@ -40,7 +44,7 @@ export class PackageNotInstalledError extends Error {

// only Kibana Assets use Saved Objects at this point
export const savedObjectTypes: AssetType[] = Object.values(KibanaAssetType);

export const kibanaSavedObjectTypes: KibanaSavedObjectType[] = Object.values(KibanaSavedObjectType);
export function createInstallableFrom<T>(
from: T,
savedObject?: SavedObject<Installation>
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/fleet/server/services/epm/packages/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { deletePackageCache } from '../archive';
import { deleteIlms } from '../elasticsearch/datastream_ilm/remove';
import { removeArchiveEntries } from '../archive/storage';

import { getInstallation, savedObjectTypes } from './index';
import { getInstallation, kibanaSavedObjectTypes } from './index';

export async function removeInstallation(options: {
savedObjectsClient: SavedObjectsClientContract;
Expand Down Expand Up @@ -191,14 +191,14 @@ async function deleteComponentTemplate(esClient: ElasticsearchClient, name: stri

export async function deleteKibanaSavedObjectsAssets(
savedObjectsClient: SavedObjectsClientContract,
installedRefs: AssetReference[]
installedRefs: KibanaAssetReference[]
) {
if (!installedRefs.length) return;

const logger = appContextService.getLogger();
const assetsToDelete = installedRefs
.filter(({ type }) => savedObjectTypes.includes(type as AssetType))
.map(({ id, type }) => ({ id, type } as KibanaAssetReference));
.filter(({ type }) => kibanaSavedObjectTypes.includes(type))
.map(({ id, type }) => ({ id, type }));

try {
await deleteKibanaAssets(assetsToDelete, savedObjectsClient);
Expand Down

0 comments on commit 8382974

Please sign in to comment.