Skip to content

Commit

Permalink
Move startup logic over to server plugin file and call from index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Nov 19, 2019
1 parent 7593926 commit afcfe02
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
45 changes: 19 additions & 26 deletions x-pack/legacy/plugins/file_upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +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 { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
import { getImportRouteHandler } from './server/routes/file_upload';
import { getTelemetry, initTelemetry } from './server/telemetry/telemetry';
import { MAX_BYTES } from './common/constants/file_import';
import { FileUploadPlugin } from './server/plugin';
import { mappings } from './mappings';

export const fileUpload = kibana => {
Expand All @@ -24,31 +21,27 @@ export const fileUpload = kibana => {
},

init(server) {
const elasticsearchPlugin = server.plugins.elasticsearch;
const getSavedObjectsRepository = server.savedObjects.getSavedObjectsRepository;
const xpackMainPlugin = server.plugins.xpack_main;
const makeUsageCollector = server.usage.collectorSet.makeUsageCollector;
const coreSetup = server.newPlatform.setup.core;
const pluginsSetup = {};

mirrorPluginStatus(xpackMainPlugin, this);

// Set up route
server.route({
method: 'POST',
path: '/api/fileupload/import',
handler: getImportRouteHandler(elasticsearchPlugin, getSavedObjectsRepository),
config: {
payload: { maxBytes: MAX_BYTES },
// legacy dependencies
const __LEGACY = {
route: server.route.bind(server),
plugins: {
elasticsearch: server.plugins.elasticsearch,
},
savedObjects: {
getSavedObjectsRepository:
server.savedObjects.getSavedObjectsRepository
},
usage: {
collectorSet: {
makeUsageCollector: server.usage.collectorSet.makeUsageCollector
}
}
});
};

// Make usage collector
const TELEMETRY_TYPE = 'fileUploadTelemetry';
makeUsageCollector({
type: TELEMETRY_TYPE,
isReady: () => true,
fetch: async () =>
(await getTelemetry(elasticsearchPlugin, getSavedObjectsRepository)) || initTelemetry()
});
new FileUploadPlugin().setup(coreSetup, pluginsSetup, __LEGACY);
}
});
};
37 changes: 37 additions & 0 deletions x-pack/legacy/plugins/file_upload/server/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 { getImportRouteHandler } from './routes/file_upload';
import { getTelemetry, initTelemetry } from './telemetry/telemetry';
import { MAX_BYTES } from '../common/constants/file_import';

const TELEMETRY_TYPE = 'fileUploadTelemetry';

export class FileUploadPlugin {
setup(core, plugins, __LEGACY) {
const elasticsearchPlugin = __LEGACY.plugins.elasticsearch;
const getSavedObjectsRepository = __LEGACY.savedObjects.getSavedObjectsRepository;
const makeUsageCollector = __LEGACY.usage.collectorSet.makeUsageCollector;

// Set up route
__LEGACY.route({
method: 'POST',
path: '/api/fileupload/import',
handler: getImportRouteHandler(elasticsearchPlugin, getSavedObjectsRepository),
config: {
payload: { maxBytes: MAX_BYTES },
}
});

// Make usage collector
makeUsageCollector({
type: TELEMETRY_TYPE,
isReady: () => true,
fetch: async () =>
(await getTelemetry(elasticsearchPlugin, getSavedObjectsRepository)) || initTelemetry()
});
}
}

0 comments on commit afcfe02

Please sign in to comment.