Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into feature-renam…
Browse files Browse the repository at this point in the history
…e-fleet-plugin
  • Loading branch information
nchaulet committed Nov 6, 2020
2 parents 7f7db47 + 715d43b commit 5b8e306
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 167 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@
"vinyl-fs": "^3.0.3",
"wait-on": "^5.0.1",
"watchpack": "^1.6.0",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.8.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0",
"webpack-merge": "^4.2.2",
"write-pkg": "^4.0.0",
"xml-crypto": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { pkgToPkgKey } from './index';
import { pkgToPkgKey } from '../registry/index';

const cache: Map<string, Buffer> = new Map();
export const cacheGet = (key: string) => cache.get(key);
Expand Down
22 changes: 21 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 @@ -6,10 +6,18 @@

import { ArchivePackage } from '../../../../common/types';
import { PackageInvalidArchiveError, PackageUnsupportedMediaTypeError } from '../../../errors';
import { cacheSet, setArchiveFilelist } from '../registry/cache';
import {
cacheSet,
cacheDelete,
getArchiveFilelist,
setArchiveFilelist,
deleteArchiveFilelist,
} from './cache';
import { ArchiveEntry, getBufferExtractor } from '../registry/extract';
import { parseAndVerifyArchive } from './validation';

export * from './cache';

export async function loadArchivePackage({
archiveBuffer,
contentType,
Expand Down Expand Up @@ -64,3 +72,15 @@ export async function unpackArchiveToCache(
}
return paths;
}

export const deletePackageCache = (name: string, version: string) => {
// get cached archive filelist
const paths = getArchiveFilelist(name, version);

// delete cached archive filelist
deleteArchiveFilelist(name, version);

// delete cached archive files
// this has been populated in unpackArchiveToCache()
paths?.forEach((path) => cacheDelete(path));
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../../../common/types';
import { PackageInvalidArchiveError } from '../../../errors';
import { pkgToPkgKey } from '../registry';
import { cacheGet } from '../registry/cache';
import { cacheGet } from './cache';

// TODO: everything below performs verification of manifest.yml files, and hence duplicates functionality already implemented in the
// package registry. At some point this should probably be replaced (or enhanced) with verification based on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import { InstallablePackage } from '../../../types';
import { getAssets } from './assets';
import { getArchiveFilelist } from '../registry/cache';
import { getArchiveFilelist } from '../archive/cache';

jest.mock('../registry/cache', () => {
jest.mock('../archive/cache', () => {
return {
getArchiveFilelist: jest.fn(),
};
Expand Down
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 '../registry/cache';
import { getArchiveFilelist } from '../archive/cache';

// 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
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/server/services/epm/packages/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { deletePipeline } from '../elasticsearch/ingest_pipeline/';
import { installIndexPatterns } from '../kibana/index_pattern/install';
import { deleteTransforms } from '../elasticsearch/transform/remove';
import { packagePolicyService, appContextService } from '../..';
import { splitPkgKey, deletePackageCache } from '../registry';
import { splitPkgKey } from '../registry';
import { deletePackageCache } from '../archive';

export async function removeInstallation(options: {
savedObjectsClient: SavedObjectsClientContract;
Expand Down
20 changes: 1 addition & 19 deletions x-pack/plugins/fleet/server/services/epm/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ import {
RegistrySearchResult,
} from '../../../types';
import { unpackArchiveToCache } from '../archive';
import {
cacheGet,
cacheDelete,
getArchiveFilelist,
setArchiveFilelist,
deleteArchiveFilelist,
} from './cache';
import { cacheGet, getArchiveFilelist, setArchiveFilelist } from '../archive';
import { ArchiveEntry } from './extract';
import { fetchUrl, getResponse, getResponseStream } from './requests';
import { streamToBuffer } from './streams';
Expand Down Expand Up @@ -247,15 +241,3 @@ export function groupPathsByService(paths: string[]): AssetsGroupedByServiceByTy
// elasticsearch: assets.elasticsearch,
};
}

export const deletePackageCache = (name: string, version: string) => {
// get cached archive filelist
const paths = getArchiveFilelist(name, version);

// delete cached archive filelist
deleteArchiveFilelist(name, version);

// delete cached archive files
// this has been populated in unpackRegistryPackageToCache()
paths?.forEach((path) => cacheDelete(path));
};
Loading

0 comments on commit 5b8e306

Please sign in to comment.