Skip to content

Commit

Permalink
[EPM] handle unremovable packages (#64096)
Browse files Browse the repository at this point in the history
* remove endpoint handles unremovable packages

* adjust UI to disallow removing of unremovable packages
  • Loading branch information
neptunian authored Apr 22, 2020
1 parent ed3c94b commit db642f0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface RegistryPackage {
icons?: RegistryImage[];
assets?: string[];
internal?: boolean;
removable?: boolean;
format_version: string;
datasets?: Dataset[];
datasources?: RegistryDatasource[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ export function Content(props: ContentProps) {

type ContentPanelProps = PackageInfo & Pick<DetailParams, 'panel'>;
export function ContentPanel(props: ContentPanelProps) {
const { panel, name, version, assets, title } = props;
const { panel, name, version, assets, title, removable } = props;
switch (panel) {
case 'settings':
return <SettingsPanel name={name} version={version} assets={assets} title={title} />;
return (
<SettingsPanel
name={name}
version={version}
assets={assets}
title={title}
removable={removable}
/>
);
case 'data-sources':
return <DataSourcesPanel name={name} version={version} />;
case 'overview':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ import { InstallStatus, PackageInfo } from '../../../../types';
import { InstallationButton } from './installation_button';
import { useGetDatasources } from '../../../../hooks';

const NoteLabel = () => (
<FormattedMessage
id="xpack.ingestManager.integrations.settings.packageUninstallNoteDescription.packageUninstallNoteLabel"
defaultMessage="Note:"
/>
);
export const SettingsPanel = (
props: Pick<PackageInfo, 'assets' | 'name' | 'title' | 'version'>
props: Pick<PackageInfo, 'assets' | 'name' | 'title' | 'version' | 'removable'>
) => {
const getPackageInstallStatus = useGetPackageInstallStatus();
const { data: datasourcesData } = useGetDatasources({
perPage: 0,
page: 1,
kuery: `datasources.package.name:${props.name}`,
});
const { name, title } = props;
const { name, title, removable } = props;
const packageInstallStatus = getPackageInstallStatus(name);
const packageHasDatasources = !!datasourcesData?.total;

return (
<EuiText>
<EuiTitle>
Expand Down Expand Up @@ -89,12 +94,12 @@ export const SettingsPanel = (
<p>
<InstallationButton
{...props}
disabled={!datasourcesData ? true : packageHasDatasources}
disabled={!datasourcesData || removable === false ? true : packageHasDatasources}
/>
</p>
</EuiFlexItem>
</EuiFlexGroup>
{packageHasDatasources && (
{packageHasDatasources && removable === true && (
<p>
<FormattedMessage
id="xpack.ingestManager.integrations.settings.packageUninstallNoteDescription.packageUninstallNoteDetail"
Expand All @@ -103,10 +108,23 @@ export const SettingsPanel = (
title,
strongNote: (
<strong>
<FormattedMessage
id="xpack.ingestManager.integrations.settings.packageUninstallNoteDescription.packageUninstallNoteLabel"
defaultMessage="Note:"
/>
<NoteLabel />
</strong>
),
}}
/>
</p>
)}
{removable === false && (
<p>
<FormattedMessage
id="xpack.ingestManager.integrations.settings.packageUninstallNoteDescription.packageUninstallUninstallableNoteDetail"
defaultMessage="{strongNote} The {title} integration is installed by default and cannot be removed."
values={{
title,
strongNote: (
<strong>
<NoteLabel />
</strong>
),
}}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/server/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const savedObjectMappings = {
name: { type: 'keyword' },
version: { type: 'keyword' },
internal: { type: 'boolean' },
removable: { type: 'boolean' },
es_index_patterns: {
dynamic: false,
type: 'object',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function installPackage(options: {
const reinstall = pkgVersion === installedPkg?.attributes.version;

const registryPackageInfo = await Registry.fetchInfo(pkgName, pkgVersion);
const { internal = false } = registryPackageInfo;
const { internal = false, removable = true } = registryPackageInfo;

// delete the previous version's installation's SO kibana assets before installing new ones
// in case some assets were removed in the new version
Expand Down Expand Up @@ -170,6 +170,7 @@ export async function installPackage(options: {
pkgName,
pkgVersion,
internal,
removable,
toSaveAssetRefs,
toSaveESIndexPatterns,
});
Expand Down Expand Up @@ -200,6 +201,7 @@ export async function saveInstallationReferences(options: {
pkgName: string;
pkgVersion: string;
internal: boolean;
removable: boolean;
toSaveAssetRefs: AssetReference[];
toSaveESIndexPatterns: Record<string, string>;
}) {
Expand All @@ -208,6 +210,7 @@ export async function saveInstallationReferences(options: {
pkgName,
pkgVersion,
internal,
removable,
toSaveAssetRefs,
toSaveESIndexPatterns,
} = options;
Expand All @@ -220,6 +223,7 @@ export async function saveInstallationReferences(options: {
name: pkgName,
version: pkgVersion,
internal,
removable,
},
{ id: pkgName, overwrite: true }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export async function removeInstallation(options: {
// TODO: the epm api should change to /name/version so we don't need to do this
const [pkgName] = pkgkey.split('-');
const installation = await getInstallation({ savedObjectsClient, pkgName });
const installedObjects = installation?.installed || [];
if (!installation) throw new Error('integration does not exist');
if (installation.removable === false)
throw new Error(`The ${pkgName} integration is installed by default and cannot be removed`);
const installedObjects = installation.installed || [];

// Delete the manager saved object with references to the asset objects
// could also update with [] or some other state
Expand Down

0 comments on commit db642f0

Please sign in to comment.