Skip to content

Commit

Permalink
x-pack/watcher: use Elasticsearch from CoreStart
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Mar 17, 2020
1 parent 7d12b76 commit b621af9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions x-pack/plugins/watcher/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,26 @@ export class WatcherServerPlugin implements Plugin<void, void, any, any> {
this.log = ctx.logger.get();
}

async setup(
{ http, elasticsearch: elasticsearchService }: CoreSetup,
{ licensing }: Dependencies
) {
async setup({ http, getStartServices }: CoreSetup, { licensing }: Dependencies) {
const router = http.createRouter();
const routeDependencies: RouteDependencies = {
router,
getLicenseStatus: () => this.licenseStatus,
};

const config = { plugins: [elasticsearchJsPlugin] };
const watcherESClient = elasticsearchService.createClient('watcher', config);
const getWatcherEsClient = async () => {
const [coreStart] = await getStartServices();
const config = { plugins: [elasticsearchJsPlugin] };
return coreStart.elasticsearch.legacy.createClient('watcher', config);
};
http.registerRouteHandlerContext('watcher', (ctx, request) => {
return {
client: watcherESClient.asScoped(request),
client: {
callAsCurrentUser: async (...args) =>
(await getWatcherEsClient()).asScoped(request).callAsCurrentUser(...args),
callAsInternalUser: async (...args) =>
(await getWatcherEsClient()).asScoped(request).callAsInternalUser(...args),
},
};
});

Expand Down

0 comments on commit b621af9

Please sign in to comment.