Skip to content

Commit

Permalink
Move registry/extract to archive/extract
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Nov 12, 2020
1 parent 4a137b6 commit 0d30e61
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
import tar from 'tar';
import yauzl from 'yauzl';
import { bufferToStream, streamToBuffer } from '../../../streams';

export interface ArchiveEntry {
path: string;
buffer?: Buffer;
}
import { ArchiveEntry } from './index';

export async function untarBuffer(
buffer: Buffer,
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/fleet/server/services/epm/archive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
InstallablePackage,
} from '../../../../types';
import * as Registry from '../../registry';
import { ArchiveEntry } from '../../archive';
import { CallESAsCurrentUser } from '../../../../types';
import { saveInstalledEsRefs } from '../../packages/install';
import { getInstallationObject } from '../../packages';
Expand Down Expand Up @@ -192,7 +193,7 @@ async function installPipeline({
return { id: pipeline.nameForInstallation, type: ElasticsearchAssetType.ingestPipeline };
}

const isDirectory = ({ path }: Registry.ArchiveEntry) => path.endsWith('/');
const isDirectory = ({ path }: ArchiveEntry) => path.endsWith('/');

const isDataStreamPipeline = (path: string, dataStreamDataset: string) => {
const pathParts = Registry.pathParts(path);
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/fleet/server/services/epm/packages/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { InstallablePackage } from '../../../types';
import * as Registry from '../registry';
import { getArchiveFilelist } from '../archive/cache';
import { ArchiveEntry, getArchiveFilelist } 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`
Expand Down Expand Up @@ -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 = Registry.getAsset(path);

return { path, buffer };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { AssetParts } from '../../../types';
import { getBufferExtractor, pathParts, splitPkgKey } from './index';
import { untarBuffer, unzipBuffer } from './extract';
import { pathParts, splitPkgKey } from './index';
import { getBufferExtractor, untarBuffer, unzipBuffer } from '../archive';

const testPaths = [
{
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/fleet/server/services/epm/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ 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;
Expand Down

0 comments on commit 0d30e61

Please sign in to comment.