[Ingest Manager] Lift up registry/{stream,extract} functions (#83239)

## Summary

  * Move stream utility functions from `server/services/epm/registry/streams.ts` to `server/services/epm/streams.ts`
    * They're only used in registry at the moment but aren't specific to registry 
  * Move archive extraction functions from `server/services/epm/registry/extract.ts` to `server/services/epm/archive.ts`
    * The Registry isn't the only service/code which needs to extract packages. Continue consolidating archive-related code under archive vs registry
This commit is contained in:
John Schulz 2020-11-12 11:05:17 -05:00 committed by GitHub
parent 4932dc55a6
commit 208e86e66a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 19 additions and 20 deletions

View file

@ -6,12 +6,8 @@
import tar from 'tar';
import yauzl from 'yauzl';
import { bufferToStream, streamToBuffer } from './streams';
export interface ArchiveEntry {
path: string;
buffer?: Buffer;
}
import { bufferToStream, streamToBuffer } from '../streams';
import { ArchiveEntry } from './index';
export async function untarBuffer(
buffer: Buffer,

View file

@ -14,10 +14,16 @@ import {
setArchiveFilelist,
deleteArchiveFilelist,
} from './cache';
import { ArchiveEntry, getBufferExtractor } from '../registry/extract';
import { getBufferExtractor } from './extract';
import { parseAndVerifyArchiveEntries } from './validation';
export * from './cache';
export { untarBuffer, unzipBuffer, getBufferExtractor } from './extract';
export interface ArchiveEntry {
path: string;
buffer?: Buffer;
}
export async function getArchivePackage({
archiveBuffer,

View file

@ -15,7 +15,8 @@ import {
RegistryVarsEntry,
} from '../../../../common/types';
import { PackageInvalidArchiveError } from '../../../errors';
import { ArchiveEntry, pkgToPkgKey } from '../registry';
import { ArchiveEntry } from './index';
import { pkgToPkgKey } from '../registry';
const MANIFESTS: Record<string, Buffer> = {};
const MANIFEST_NAME = 'manifest.yml';

View file

@ -11,8 +11,7 @@ import {
ElasticsearchAssetType,
InstallablePackage,
} from '../../../../types';
import { ArchiveEntry } from '../../registry';
import { getAsset, getPathParts } from '../../archive';
import { ArchiveEntry, getAsset, getPathParts } from '../../archive';
import { CallESAsCurrentUser } from '../../../../types';
import { saveInstalledEsRefs } from '../../packages/install';
import { getInstallationObject } from '../../packages';

View file

@ -6,7 +6,7 @@
import { InstallablePackage } from '../../../types';
import * as Registry from '../registry';
import { getArchiveFilelist, getAsset } from '../archive';
import { ArchiveEntry, getArchiveFilelist, getAsset } from '../archive';
// paths from RegistryPackage are routes to the assets on EPR
// e.g. `/package/nginx/1.2.0/data_stream/access/fields/fields.yml`
@ -51,14 +51,14 @@ export async function getAssetsData(
packageInfo: InstallablePackage,
filter = (path: string): boolean => true,
datasetName?: string
): Promise<Registry.ArchiveEntry[]> {
): Promise<ArchiveEntry[]> {
// TODO: Needs to be called to fill the cache but should not be required
await Registry.ensureCachedArchiveInfo(packageInfo.name, packageInfo.version, 'registry');
// Gather all asset data
const assets = getAssets(packageInfo, filter, datasetName);
const entries: Registry.ArchiveEntry[] = assets.map((path) => {
const entries: ArchiveEntry[] = assets.map((path) => {
const buffer = getAsset(path);
return { path, buffer };

View file

@ -5,9 +5,8 @@
*/
import { AssetParts } from '../../../types';
import { getPathParts } from '../archive';
import { getBufferExtractor, splitPkgKey } from './index';
import { untarBuffer, unzipBuffer } from './extract';
import { getBufferExtractor, getPathParts, untarBuffer, unzipBuffer } from '../archive';
import { splitPkgKey } from './index';
const testPaths = [
{

View file

@ -24,13 +24,11 @@ import {
unpackArchiveToCache,
} from '../archive';
import { fetchUrl, getResponse, getResponseStream } from './requests';
import { streamToBuffer } from './streams';
import { streamToBuffer } from '../streams';
import { getRegistryUrl } from './registry_url';
import { appContextService } from '../..';
import { PackageNotFoundError, PackageCacheError } from '../../../errors';
export { ArchiveEntry, getBufferExtractor } from './extract';
export interface SearchParams {
category?: CategoryId;
experimental?: boolean;

View file

@ -6,7 +6,7 @@
import fetch, { FetchError, Response, RequestInit } from 'node-fetch';
import pRetry from 'p-retry';
import { streamToString } from './streams';
import { streamToString } from '../streams';
import { appContextService } from '../../app_context';
import { RegistryError, RegistryConnectionError, RegistryResponseError } from '../../../errors';
import { getProxyAgent, getRegistryProxyUrl } from './proxy';