Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

48654 files from registry #49580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { InstallationAttributes } from '../../common/types';
import * as Registry from '../registry';
import { createInstallableFrom } from './index';

export { SearchParams } from '../registry';
export { SearchParams, fetchFile as getFile } from '../registry';

function nameAsTitle(name: string) {
return name.charAt(0).toUpperCase() + name.substr(1).toLowerCase();
Expand Down Expand Up @@ -68,9 +68,6 @@ export async function getPackageInfo(options: {
return createInstallableFrom(updated, savedObject);
}

export const getImage = async (options: Registry.ImageRequestParams) =>
Registry.fetchImage(options);

export async function getInstallationObject(options: {
savedObjectsClient: SavedObjectsClientContract;
pkgkey: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*/

import { AssetType, Request, ResponseToolkit } from '../../common/types';
import { API_ROOT } from '../../common/routes';
import { PluginContext } from '../plugin';
import { getClient } from '../saved_objects';
import {
SearchParams,
getCategories,
getClusterAccessor,
getImage,
getFile,
getPackageInfo,
getPackages,
installPackage,
removeInstallation,
} from './index';
import { ImageRequestParams } from '../registry';

interface Extra extends ResponseToolkit {
context: PluginContext;
Expand All @@ -33,10 +33,6 @@ interface PackageRequest extends Request {
};
}

interface ImageRequest extends Request {
params: Request['params'] & ImageRequestParams;
}

interface InstallAssetRequest extends Request {
params: AssetRequestParams;
}
Expand Down Expand Up @@ -71,12 +67,18 @@ export async function handleGetInfo(req: PackageRequest, extra: Extra) {
return packageInfo;
}

export const handleGetImage = async (req: ImageRequest, extra: Extra) => {
const response = await getImage(req.params);
const newResponse = extra.response(response.body);
// set the content type from the registry response
newResponse.header('Content-Type', response.headers.get('content-type') || '');
return newResponse;
export const handleGetFile = async (req: Request, extra: Extra) => {
if (!req.url.path) throw new Error('path is required');
const filePath = req.url.path.replace(API_ROOT, '');
const registryResponse = await getFile(filePath);
const epmResponse = extra.response(registryResponse.body);
const proxiedHeaders = ['Content-Type'];
proxiedHeaders.forEach(key => {
const value = registryResponse.headers.get(key);
if (value !== null) epmResponse.header(key, value);
});

return epmResponse;
};

export async function handleRequestInstall(req: InstallAssetRequest, extra: Extra) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ export interface SearchParams {
category?: CategoryId;
}

export interface ImageRequestParams {
pkgkey: string;
imgPath: string;
}

export async function fetchList(params?: SearchParams): Promise<RegistryList> {
const { registryUrl } = epmConfigStore.getConfig();
const url = new URL(`${registryUrl}/search`);
Expand All @@ -46,10 +41,9 @@ export async function fetchInfo(key: string): Promise<RegistryPackage> {
return fetchUrl(`${registryUrl}/package/${key}`).then(JSON.parse);
}

export async function fetchImage(params: ImageRequestParams): Promise<Response> {
export async function fetchFile(filePath: string): Promise<Response> {
const { registryUrl } = epmConfigStore.getConfig();
const { pkgkey, imgPath } = params;
return getResponse(`${registryUrl}/package/${pkgkey}/img/${imgPath}`);
return getResponse(`${registryUrl}${filePath}`);
}

export async function fetchCategories(): Promise<CategorySummaryList> {
Expand Down
8 changes: 3 additions & 5 deletions x-pack/legacy/plugins/integrations_manager/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { ServerRoute } from '../common/types';
import * as CommonRoutes from '../common/routes';
import * as Packages from './packages/handlers';

const API_IMG_PATTERN = `${CommonRoutes.API_ROOT}/package/{pkgkey}/img/{imgPath*}`;

// Manager public API paths
export const routes: ServerRoute[] = [
{
Expand All @@ -26,9 +24,9 @@ export const routes: ServerRoute[] = [
},
{
method: 'GET',
path: API_IMG_PATTERN,
options: { tags: [`access:${PLUGIN.ID}`], json: { space: 2 } },
handler: Packages.handleGetImage,
path: `${CommonRoutes.API_INFO_PATTERN}/{filePath*}`,
options: { tags: [`access:${PLUGIN.ID}`] },
handler: Packages.handleGetFile,
},
{
method: 'GET',
Expand Down
147 changes: 147 additions & 0 deletions x-pack/test/epm_api_integration/apis/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import ServerMock from 'mock-http-server';
import { FtrProviderContext } from '../../api_integration/ftr_provider_context';

export default function({ getService }: FtrProviderContext) {
describe('package file', () => {
const server = new ServerMock({ host: 'localhost', port: 6666 });
beforeEach(() => {
server.start(() => {});
});
afterEach(() => {
server.stop(() => {});
});
it('fetches a .png screenshot image', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/img/screenshots/auditbeat-file-integrity-dashboard.png',
reply: {
headers: { 'content-type': 'image/png' },
},
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/img/screenshots/auditbeat-file-integrity-dashboard.png')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'image/png')
.expect(200);
});

it('fetches an .svg icon image', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/img/icon.svg',
reply: {
headers: { 'content-type': 'image/svg' },
},
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/img/icon.svg')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'image/svg');
});

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',
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/auditbeat/rules/sample-rules-linux-32bit.conf')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});

it('fetches an auditbeat .yml config file', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/auditbeat/config/config.yml',
reply: {
headers: { 'content-type': 'text/yaml; charset=UTF-8' },
},
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/auditbeat/config/config.yml')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'text/yaml; charset=UTF-8')
.expect(200);
});

it('fetches a .json kibana visualization file', async () => {
server.on({
method: 'GET',
path:
'/package/auditd-2.0.4/kibana/visualization/b21e0c70-c252-11e7-8692-232bd1143e8a-ecs.json',
});

const supertest = getService('supertest');
await supertest
.get(
'/api/epm/package/auditd-2.0.4/kibana/visualization/b21e0c70-c252-11e7-8692-232bd1143e8a-ecs.json'
)
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});

it('fetches a .json kibana dashboard file', async () => {
server.on({
method: 'GET',
path:
'/package/auditd-2.0.4/kibana/dashboard/7de391b0-c1ca-11e7-8995-936807a28b16-ecs.json',
});

const supertest = getService('supertest');
await supertest
.get(
'/api/epm/package/auditd-2.0.4/kibana/dashboard/7de391b0-c1ca-11e7-8995-936807a28b16-ecs.json'
)
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});

it('fetches an .json index pattern file', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/kibana/index-pattern/auditbeat-*.json',
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/kibana/index-pattern/auditbeat-*.json')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});

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',
});

const supertest = getService('supertest');
await supertest
.get(
'/api/epm/package/auditd-2.0.4/kibana/search/0f10c430-c1c3-11e7-8995-936807a28b16-ecs.json'
)
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});
});
}
61 changes: 0 additions & 61 deletions x-pack/test/epm_api_integration/apis/image.ts

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/test/epm_api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default function ({ loadTestFile }) {
describe('EPM Endpoints', function () {
this.tags('ciGroup7');
loadTestFile(require.resolve('./list'));
loadTestFile(require.resolve('./image'));
loadTestFile(require.resolve('./file'));
});
}