From 760ef4cc2e8775bd67aa6aa503b131e484950e00 Mon Sep 17 00:00:00 2001 From: Sandra Gonzales Date: Mon, 30 Mar 2020 18:44:00 -0400 Subject: [PATCH] [7.x] [EPM] update registry path structure (#61621) (#61889) * update registry path structure * temporarily remove fleet tests Co-authored-by: Elastic Machine Co-authored-by: Elastic Machine --- .../ingest_manager/server/routes/epm/handlers.ts | 3 ++- .../server/services/epm/packages/assets.test.ts | 14 ++++++-------- .../server/services/epm/packages/assets.ts | 10 ++++++---- .../server/services/epm/registry/index.ts | 3 ++- x-pack/test/api_integration/apis/index.js | 1 - x-pack/test/epm_api_integration/apis/file.ts | 16 ++++++++-------- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts b/x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts index 8623d02e72862..727d26b5868de 100644 --- a/x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts +++ b/x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts @@ -76,7 +76,8 @@ export const getFileHandler: RequestHandler { try { const { pkgkey, filePath } = request.params; - const registryResponse = await getFile(`/package/${pkgkey}/${filePath}`); + const [pkgName, pkgVersion] = pkgkey.split('-'); + const registryResponse = await getFile(`/package/${pkgName}/${pkgVersion}/${filePath}`); const contentType = registryResponse.headers.get('Content-Type'); const customResponseObj: CustomHttpResponseOptions = { body: registryResponse.body, diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/assets.test.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/assets.test.ts index 5153f9205dde7..6d5ca036aeb13 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/assets.test.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/assets.test.ts @@ -11,19 +11,18 @@ const tests = [ { package: { assets: [ - '/package/coredns-1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-plaintext.json', - '/package/coredns-1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-json.json', + '/package/coredns/1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-plaintext.json', + '/package/coredns/1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-json.json', ], - name: 'coredns', - version: '1.0.1', + path: '/package/coredns/1.0.1', }, dataset: 'log', filter: (path: string) => { return true; }, expected: [ - '/package/coredns-1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-plaintext.json', - '/package/coredns-1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-json.json', + '/package/coredns/1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-plaintext.json', + '/package/coredns/1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-json.json', ], }, { @@ -32,8 +31,7 @@ const tests = [ '/package/coredns-1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-plaintext.json', '/package/coredns-1.0.1/dataset/log/elasticsearch/ingest-pipeline/pipeline-json.json', ], - name: 'coredns', - version: '1.0.1', + path: '/package/coredns/1.0.1', }, // Non existant dataset dataset: 'foo', diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/assets.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/assets.ts index e36c2de1b4e80..d7a5c5569986e 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/assets.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/assets.ts @@ -9,14 +9,16 @@ import * as Registry from '../registry'; import { cacheHas } from '../registry/cache'; // paths from RegistryPackage are routes to the assets on EPR -// e.g. `/package/nginx-1.2.0/dataset/access/fields/fields.yml` +// e.g. `/package/nginx/1.2.0/dataset/access/fields/fields.yml` // paths for ArchiveEntry are routes to the assets in the archive // e.g. `nginx-1.2.0/dataset/access/fields/fields.yml` // RegistryPackage paths have a `/package/` prefix compared to ArchiveEntry paths +// and different package and version structure const EPR_PATH_PREFIX = '/package'; function registryPathToArchivePath(registryPath: RegistryPackage['path']): string { - const archivePath = registryPath.replace(`${EPR_PATH_PREFIX}/`, ''); - return archivePath; + const path = registryPath.replace(`${EPR_PATH_PREFIX}/`, ''); + const [pkgName, pkgVersion] = path.split('/'); + return path.replace(`${pkgName}/${pkgVersion}`, `${pkgName}-${pkgVersion}`); } export function getAssets( @@ -35,7 +37,7 @@ export function getAssets( // if dataset, filter for them if (datasetName) { - const comparePath = `${EPR_PATH_PREFIX}/${packageInfo.name}-${packageInfo.version}/dataset/${datasetName}/`; + const comparePath = `${packageInfo.path}/dataset/${datasetName}/`; if (!path.includes(comparePath)) { continue; } 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 7c315f7616e1f..56bd79890784b 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 @@ -63,7 +63,8 @@ export async function fetchFindLatestPackage( export async function fetchInfo(pkgkey: string): Promise { const registryUrl = appContextService.getConfig()?.epm.registryUrl; - return fetchUrl(`${registryUrl}/package/${pkgkey}`).then(JSON.parse); + // change pkg-version to pkg/version + return fetchUrl(`${registryUrl}/package/${pkgkey.replace('-', '/')}`).then(JSON.parse); } export async function fetchFile(filePath: string): Promise { diff --git a/x-pack/test/api_integration/apis/index.js b/x-pack/test/api_integration/apis/index.js index 0a87dcb4b5bb0..10c06adea8564 100644 --- a/x-pack/test/api_integration/apis/index.js +++ b/x-pack/test/api_integration/apis/index.js @@ -27,7 +27,6 @@ export default function({ loadTestFile }) { loadTestFile(require.resolve('./siem')); loadTestFile(require.resolve('./short_urls')); loadTestFile(require.resolve('./lens')); - loadTestFile(require.resolve('./fleet')); loadTestFile(require.resolve('./ingest')); loadTestFile(require.resolve('./endpoint')); loadTestFile(require.resolve('./ml')); diff --git a/x-pack/test/epm_api_integration/apis/file.ts b/x-pack/test/epm_api_integration/apis/file.ts index 2989263af40a7..c67f472e8fb78 100644 --- a/x-pack/test/epm_api_integration/apis/file.ts +++ b/x-pack/test/epm_api_integration/apis/file.ts @@ -19,7 +19,7 @@ export default function({ getService }: FtrProviderContext) { it('fetches a .png screenshot image', async () => { server.on({ method: 'GET', - path: '/package/auditd-2.0.4/img/screenshots/auditbeat-file-integrity-dashboard.png', + path: '/package/auditd/2.0.4/img/screenshots/auditbeat-file-integrity-dashboard.png', reply: { headers: { 'content-type': 'image/png' }, }, @@ -38,7 +38,7 @@ export default function({ getService }: FtrProviderContext) { it('fetches an .svg icon image', async () => { server.on({ method: 'GET', - path: '/package/auditd-2.0.4/img/icon.svg', + path: '/package/auditd/2.0.4/img/icon.svg', reply: { headers: { 'content-type': 'image/svg' }, }, @@ -54,7 +54,7 @@ export default function({ getService }: FtrProviderContext) { it('fetches an auditbeat .conf rule file', async () => { server.on({ method: 'GET', - path: '/package/auditd-2.0.4/auditbeat/rules/sample-rules-linux-32bit.conf', + path: '/package/auditd/2.0.4/auditbeat/rules/sample-rules-linux-32bit.conf', }); const supertest = getService('supertest'); @@ -70,7 +70,7 @@ export default function({ getService }: FtrProviderContext) { it('fetches an auditbeat .yml config file', async () => { server.on({ method: 'GET', - path: '/package/auditd-2.0.4/auditbeat/config/config.yml', + path: '/package/auditd/2.0.4/auditbeat/config/config.yml', reply: { headers: { 'content-type': 'text/yaml; charset=UTF-8' }, }, @@ -88,7 +88,7 @@ export default function({ getService }: FtrProviderContext) { server.on({ method: 'GET', path: - '/package/auditd-2.0.4/kibana/visualization/b21e0c70-c252-11e7-8692-232bd1143e8a-ecs.json', + '/package/auditd/2.0.4/kibana/visualization/b21e0c70-c252-11e7-8692-232bd1143e8a-ecs.json', }); const supertest = getService('supertest'); @@ -105,7 +105,7 @@ export default function({ getService }: FtrProviderContext) { server.on({ method: 'GET', path: - '/package/auditd-2.0.4/kibana/dashboard/7de391b0-c1ca-11e7-8995-936807a28b16-ecs.json', + '/package/auditd/2.0.4/kibana/dashboard/7de391b0-c1ca-11e7-8995-936807a28b16-ecs.json', }); const supertest = getService('supertest'); @@ -121,7 +121,7 @@ export default function({ getService }: FtrProviderContext) { it('fetches an .json index pattern file', async () => { server.on({ method: 'GET', - path: '/package/auditd-2.0.4/kibana/index-pattern/auditbeat-*.json', + path: '/package/auditd/2.0.4/kibana/index-pattern/auditbeat-*.json', }); const supertest = getService('supertest'); @@ -135,7 +135,7 @@ export default function({ getService }: FtrProviderContext) { it('fetches a .json search file', async () => { server.on({ method: 'GET', - path: '/package/auditd-2.0.4/kibana/search/0f10c430-c1c3-11e7-8995-936807a28b16-ecs.json', + path: '/package/auditd/2.0.4/kibana/search/0f10c430-c1c3-11e7-8995-936807a28b16-ecs.json', }); const supertest = getService('supertest');