Skip to content

Commit

Permalink
[7.x] [EPM] update registry path structure (#61621) (#61889)
Browse files Browse the repository at this point in the history
* update registry path structure

* temporarily remove fleet tests

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
neptunian and elasticmachine committed Mar 30, 2020
1 parent bc93f27 commit 760ef4c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export const getFileHandler: RequestHandler<TypeOf<typeof GetFileRequestSchema.p
) => {
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<typeof registryResponse.body> = {
body: registryResponse.body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
},
{
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export async function fetchFindLatestPackage(

export async function fetchInfo(pkgkey: string): Promise<RegistryPackage> {
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<Response> {
Expand Down
1 change: 0 additions & 1 deletion x-pack/test/api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
16 changes: 8 additions & 8 deletions x-pack/test/epm_api_integration/apis/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
},
Expand All @@ -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' },
},
Expand All @@ -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');
Expand All @@ -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' },
},
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 760ef4c

Please sign in to comment.