Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Jan 13, 2020
1 parent 4cb4e5e commit c6e6712
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 40 deletions.
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/painless_playground/public/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/

import { i18n } from '@kbn/i18n';
// @ts-ignore
import { xpackInfo } from 'plugins/xpack_main/services/xpack_info';
import { npSetup, npStart } from 'ui/new_platform';

// !xpackInfo.get('features.painless_playground.enableLink', false)

npSetup.plugins.dev_tools.register({
order: 7,
title: i18n.translate('xpack.painlessPlayground.displayName', {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/

import Boom from 'boom';
import { ServerFacade } from '../../../types';
import { PLUGIN } from '../../../common/constants';

export const licensePreRoutingFactory = server => {
export const licensePreRoutingFactory = (server: ServerFacade) => {
const xpackMainPlugin = server.plugins.xpack_main;

// License checking and enable/disable logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@
*/

import { wrapEsError } from '../../lib/error_wrappers';
import { callWithRequestFactory } from '../../lib/call_with_request_factory';
import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory';
import { ServerFacade, RequestFacade } from '../../../types';

function executeScript(callWithRequest: any, painlessJson: any) {
return callWithRequest('scriptsPainlessExecute', {
body: painlessJson,
});
}

export function registerPainlessPlaygroundSimulateRoute(server: any) {
export function registerPainlessPlaygroundSimulateRoute(server: ServerFacade) {
const licensePreRouting = licensePreRoutingFactory(server);

server.route({
path: '/api/painless_playground/simulate',
method: 'POST',
handler: (request: any) => {
const callWithRequest = callWithRequestFactory(server, request);

return executeScript(callWithRequest, request.payload).catch((e: any) => wrapEsError(e));
handler: (request: RequestFacade) => {
const cluster = server.plugins.elasticsearch.getCluster('data');
return cluster
.callWithRequest(request, 'scriptsPainlessExecute', {
body: request.payload,
})
.catch((e: any) => wrapEsError(e));
},
config: {
pre: [licensePreRouting],
Expand Down

0 comments on commit c6e6712

Please sign in to comment.