diff --git a/x-pack/legacy/plugins/integrations_manager/index.ts b/x-pack/legacy/plugins/integrations_manager/index.ts index 02afc133928dafb..39ee722c0e61b51 100644 --- a/x-pack/legacy/plugins/integrations_manager/index.ts +++ b/x-pack/legacy/plugins/integrations_manager/index.ts @@ -9,8 +9,9 @@ import { LegacyPluginInitializer, LegacyPluginOptions } from 'src/legacy/types'; import KbnServer, { Server } from 'src/legacy/server/kbn_server'; import { Feature } from '../xpack_main/server/lib/feature_registry'; import { PLUGIN } from './common/constants'; +import { API_ROOT } from './common/routes'; import manifest from './kibana.json'; -import { CoreSetup, Plugin as ServerPlugin, PluginInitializerContext } from './server/plugin'; +import { CoreSetup, Plugin as ServerPlugin } from './server/plugin'; import { mappings, savedObjectSchemas } from './server/saved_objects'; const ROOT = `plugins/${PLUGIN.ID}`; @@ -74,10 +75,12 @@ const pluginOptions: LegacyPluginOptions = { // `kbnServer.server` is the same hapi instance // `kbnServer.newPlatform` has important values const kbnServer = (server as unknown) as KbnServer; - const initializerContext: PluginInitializerContext = {}; - const coreSetup: CoreSetup = kbnServer.newPlatform.setup.core; - new ServerPlugin(initializerContext).setup(coreSetup); + const kbnCore = kbnServer.newPlatform.setup.core; + const router = kbnCore.http.createRouter(API_ROOT); + const coreSetup: CoreSetup = { router }; + + new ServerPlugin().setup(coreSetup); }, postInit: undefined, isEnabled: false, diff --git a/x-pack/legacy/plugins/integrations_manager/server/plugin.ts b/x-pack/legacy/plugins/integrations_manager/server/plugin.ts index f713a5be46cfbe8..3d09d3e0c6e3b1a 100644 --- a/x-pack/legacy/plugins/integrations_manager/server/plugin.ts +++ b/x-pack/legacy/plugins/integrations_manager/server/plugin.ts @@ -4,19 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - ClusterClient, - CoreStart, - ElasticsearchServiceSetup, - HttpServiceSetup, -} from 'src/core/server'; -import { PLUGIN } from '../common/constants'; +import { IRouter } from 'src/core/server'; import { fetchList } from './registry'; import { routes } from './routes'; export interface CoreSetup { - elasticsearch: ElasticsearchServiceSetup; - http: HttpServiceSetup; + router: IRouter; } // eslint-disable-next-line @typescript-eslint/no-empty-interface @@ -29,34 +22,17 @@ export interface PluginContext { } export class Plugin { - constructor(initializerContext: PluginInitializerContext) {} + constructor() {} public setup(core: CoreSetup) { - const { http, elasticsearch } = core; - const { server } = http; - const pluginContext: PluginContext = { - esClient: elasticsearch.createClient(PLUGIN.ID), - }; - - // make pluginContext entries available to handlers via h.context - // https://github.com/hapijs/hapi/blob/master/API.md#route.options.bind - // aligns closely with approach proposed in handler RFC - // https://github.com/epixa/kibana/blob/rfc-handlers/rfcs/text/0003_handler_interface.md - const routesWithContext = routes.map(function injectRouteContext(route) { - // merge route.options.bind, defined or otherwise, into pluginContext - // routes can add extra values or override pluginContext values (e.g. spies, etc) - if (!route.options) route.options = {}; - route.options.bind = Object.assign({}, pluginContext, route.options.bind); - - return route; - }); + const { router } = core; - // map routes to handlers - server.route(routesWithContext); + router.route(routes); // the JS API for other consumers return { getList: fetchList, }; } - public start(core: CoreStart) {} + public start() {} + public stop() {} }