From 1c94bf90c9fdc732d5dacdedad9cceb1c26e1a5b Mon Sep 17 00:00:00 2001 From: John Schulz Date: Fri, 6 Nov 2020 14:40:09 -0500 Subject: [PATCH] Move single use function in line --- .../server/services/epm/packages/get.ts | 2 +- .../server/services/epm/packages/install.ts | 2 +- .../server/services/epm/registry/index.ts | 26 ++++++------------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts index 2021b353f1a27..893df1733c58b 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts @@ -116,7 +116,7 @@ export async function getPackageInfo(options: { ] = await Promise.all([ getInstallationObject({ savedObjectsClient, pkgName }), Registry.fetchFindLatestPackage(pkgName), - Registry.loadRegistryPackage(pkgName, pkgVersion), + Registry.getRegistryPackage(pkgName, pkgVersion), ]); // add properties that aren't (or aren't yet) on Registry response diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/install.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/install.ts index 0496a6e9aeef1..e7d8c8d4695d4 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/install.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/install.ts @@ -248,7 +248,7 @@ export async function installPackageFromRegistry({ throw new PackageOutdatedError(`${pkgkey} is out-of-date and cannot be installed or updated`); } - const { paths, registryPackageInfo } = await Registry.loadRegistryPackage(pkgName, pkgVersion); + const { paths, registryPackageInfo } = await Registry.getRegistryPackage(pkgName, pkgVersion); const removable = !isRequiredPackage(pkgName); const { internal = false } = registryPackageInfo; diff --git a/x-pack/plugins/ingest_manager/server/services/epm/registry/index.ts b/x-pack/plugins/ingest_manager/server/services/epm/registry/index.ts index b1dd9a8c3c3f1..7357130e57bbd 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/registry/index.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/registry/index.ts @@ -26,7 +26,6 @@ import { setArchiveFilelist, deleteArchiveFilelist, } from './cache'; -import { ArchiveEntry } from './extract'; import { fetchUrl, getResponse, getResponseStream } from './requests'; import { streamToBuffer } from './streams'; import { getRegistryUrl } from './registry_url'; @@ -132,27 +131,18 @@ export async function fetchCategories(params?: CategoriesParams): Promise true -): Promise { - const { archiveBuffer, archivePath } = await fetchArchiveBuffer(pkgName, pkgVersion); - const contentType = mime.lookup(archivePath); - if (!contentType) { - throw new Error(`Unknown compression format for '${archivePath}'. Please use .zip or .gz`); - } - const paths: string[] = await unpackArchiveToCache(archiveBuffer, contentType); - return paths; -} - -export async function loadRegistryPackage( +export async function getRegistryPackage( pkgName: string, pkgVersion: string ): Promise<{ paths: string[]; registryPackageInfo: RegistryPackage }> { let paths = getArchiveFilelist(pkgName, pkgVersion); if (!paths || paths.length === 0) { - paths = await unpackRegistryPackageToCache(pkgName, pkgVersion); + const { archiveBuffer, archivePath } = await fetchArchiveBuffer(pkgName, pkgVersion); + const contentType = mime.lookup(archivePath); + if (!contentType) { + throw new Error(`Unknown compression format for '${archivePath}'. Please use .zip or .gz`); + } + paths = await unpackArchiveToCache(archiveBuffer, contentType); setArchiveFilelist(pkgName, pkgVersion, paths); } @@ -200,7 +190,7 @@ export async function ensureCachedArchiveInfo( const paths = getArchiveFilelist(name, version); if (!paths || paths.length === 0) { if (installSource === 'registry') { - await loadRegistryPackage(name, version); + await getRegistryPackage(name, version); } else { throw new PackageCacheError( `Package ${name}-${version} not cached. If it was uploaded, try uninstalling and reinstalling manually.`