mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Add a new GET script languages API endpoint
To provide additional language options for scripted fields, Kibana needs to know what languages are available for inline scripting in Elasticsearch. This new Kibana API grabs up to date information from Elasticsearch and provides it in an easy to digest format for the UI. The response body from the API is a simple JSON array with a list of languages that are enabled for inline scripting. The API also filters out languages that don't make sense in scripted fields, like 'mustache'. An example request might look like this: `GET /api/kibana/scripts/languages` 200 OK `['expression', 'painless']`
This commit is contained in:
parent
99a30ee7ad
commit
6c8ec66b3a
6 changed files with 76 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import ingest from './server/routes/api/ingest';
|
||||
import search from './server/routes/api/search';
|
||||
import settings from './server/routes/api/settings';
|
||||
import scripts from './server/routes/api/scripts';
|
||||
|
||||
module.exports = function (kibana) {
|
||||
return new kibana.Plugin({
|
||||
|
@ -84,6 +85,7 @@ module.exports = function (kibana) {
|
|||
ingest(server);
|
||||
search(server);
|
||||
settings(server);
|
||||
scripts(server);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import { registerLanguages } from './register_languages';
|
||||
|
||||
export default function (server) {
|
||||
registerLanguages(server);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import _ from 'lodash';
|
||||
import handleESError from '../../../lib/handle_es_error';
|
||||
|
||||
export function registerLanguages(server) {
|
||||
server.route({
|
||||
path: '/api/kibana/scripts/languages',
|
||||
method: 'GET',
|
||||
handler: function (request, reply) {
|
||||
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
|
||||
|
||||
return callWithRequest(request, 'cluster.getSettings', {
|
||||
include_defaults: true,
|
||||
filter_path: '**.script.engine.*.inline'
|
||||
})
|
||||
.then((esResponse) => {
|
||||
const langs = _.get(esResponse, 'defaults.script.engine', {});
|
||||
const inlineLangs = _.pick(langs, (lang) => lang.inline === 'true');
|
||||
const supportedLangs = _.omit(inlineLangs, 'mustache');
|
||||
return _.keys(supportedLangs);
|
||||
})
|
||||
.then(reply)
|
||||
.catch((error) => {
|
||||
reply(handleESError(error));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
define({
|
||||
suites: [
|
||||
'test/unit/api/ingest/index',
|
||||
'test/unit/api/search/index'
|
||||
'test/unit/api/search/index',
|
||||
'test/unit/api/scripts/index'
|
||||
],
|
||||
excludeInstrumentation: /(fixtures|node_modules)\//,
|
||||
loaderOptions: {
|
||||
|
|
27
test/unit/api/scripts/_languages.js
Normal file
27
test/unit/api/scripts/_languages.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
define(function (require) {
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
|
||||
return function (bdd, request) {
|
||||
bdd.describe('Languages API', function getLanguages() {
|
||||
|
||||
bdd.it('should return 200 with an array of languages', function () {
|
||||
return request.get('/kibana/scripts/languages')
|
||||
.expect(200)
|
||||
.then(function (response) {
|
||||
expect(response.body).to.be.an('array');
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should only return langs enabled for inline scripting', function () {
|
||||
return request.get('/kibana/scripts/languages')
|
||||
.expect(200)
|
||||
.then(function (response) {
|
||||
expect(response.body).to.contain('expression');
|
||||
expect(response.body).to.contain('painless');
|
||||
|
||||
expect(response.body).to.not.contain('groovy');
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
13
test/unit/api/scripts/index.js
Normal file
13
test/unit/api/scripts/index.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
define(function (require) {
|
||||
var bdd = require('intern!bdd');
|
||||
var serverConfig = require('intern/dojo/node!../../../server_config');
|
||||
var request = require('intern/dojo/node!supertest-as-promised');
|
||||
var url = require('intern/dojo/node!url');
|
||||
var languages = require('./_languages');
|
||||
|
||||
bdd.describe('scripts API', function () {
|
||||
request = request(url.format(serverConfig.servers.kibana) + '/api');
|
||||
|
||||
languages(bdd, request);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue