Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ingest Manager] Move single use function into getRegistryPackage #82885

Merged
merged 2 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '../../../types';
import { unpackArchiveToCache } from '../archive';
import { cacheGet, getArchiveFilelist, setArchiveFilelist } from '../archive';
import { ArchiveEntry } from './extract';
import { fetchUrl, getResponse, getResponseStream } from './requests';
import { streamToBuffer } from './streams';
import { getRegistryUrl } from './registry_url';
Expand Down Expand Up @@ -126,27 +125,18 @@ export async function fetchCategories(params?: CategoriesParams): Promise<Catego
return fetchUrl(url.toString()).then(JSON.parse);
}

export async function unpackRegistryPackageToCache(
pkgName: string,
pkgVersion: string,
filter = (entry: ArchiveEntry): boolean => true
): Promise<string[]> {
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);
}

Expand Down Expand Up @@ -194,7 +184,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.`
Expand Down