Skip to content

Commit

Permalink
[EPM] fix /packages response to return older packages (#62623) (#62693)
Browse files Browse the repository at this point in the history
* compare package list by name

* use the internal property, adding as saved object attribute

* remove HiddenPackages type
  • Loading branch information
neptunian authored Apr 6, 2020
1 parent c6eea56 commit 8c6f0c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
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 @@ -148,6 +148,7 @@ export const savedObjectMappings = {
properties: {
name: { type: 'keyword' },
version: { type: 'keyword' },
internal: { type: 'boolean' },
installed: {
type: 'nested',
properties: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ export async function getPackages(
Object.assign({}, item, { title: item.title || nameAsTitle(item.name) })
);
});
const searchObjects = registryItems.map(({ name, version }) => ({
// get the installed packages
const results = await savedObjectsClient.find<Installation>({
type: PACKAGES_SAVED_OBJECT_TYPE,
id: `${name}-${version}`,
}));
const results = await savedObjectsClient.bulkGet<Installation>(searchObjects);
const savedObjects = results.saved_objects.filter(o => !o.error); // ignore errors for now
});
// filter out any internal packages
const savedObjectsVisible = results.saved_objects.filter(o => !o.attributes.internal);
const packageList = registryItems
.map(item =>
createInstallableFrom(
item,
savedObjects.find(({ id }) => id === `${item.name}-${item.version}`)
savedObjectsVisible.find(({ attributes }) => attributes.name === item.name)
)
)
.sort(sortByName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function installPackage(options: {
}): Promise<AssetReference[]> {
const { savedObjectsClient, pkgkey, callCluster } = options;
const registryPackageInfo = await Registry.fetchInfo(pkgkey);
const { name: pkgName, version: pkgVersion } = registryPackageInfo;
const { name: pkgName, version: pkgVersion, internal = false } = registryPackageInfo;

const installKibanaAssetsPromise = installKibanaAssets({
savedObjectsClient,
Expand Down Expand Up @@ -116,6 +116,7 @@ export async function installPackage(options: {
pkgkey,
pkgName,
pkgVersion,
internal,
toSave,
});
return toSave;
Expand Down Expand Up @@ -145,9 +146,10 @@ export async function saveInstallationReferences(options: {
pkgkey: string;
pkgName: string;
pkgVersion: string;
internal: boolean;
toSave: AssetReference[];
}) {
const { savedObjectsClient, pkgkey, pkgName, pkgVersion, toSave } = options;
const { savedObjectsClient, pkgkey, pkgName, pkgVersion, internal, toSave } = options;
const installation = await getInstallation({ savedObjectsClient, pkgkey });
const savedRefs = installation?.installed || [];
const mergeRefsReducer = (current: AssetReference[], pending: AssetReference) => {
Expand All @@ -159,7 +161,7 @@ export async function saveInstallationReferences(options: {
const toInstall = toSave.reduce(mergeRefsReducer, savedRefs);
await savedObjectsClient.create<Installation>(
PACKAGES_SAVED_OBJECT_TYPE,
{ installed: toInstall, name: pkgName, version: pkgVersion },
{ installed: toInstall, name: pkgName, version: pkgVersion, internal },
{ id: pkgkey, overwrite: true }
);

Expand Down

0 comments on commit 8c6f0c2

Please sign in to comment.