Remove endpoints that we don't need for the Add Data UI
This commit is contained in:
parent
fe296b4b36
commit
a0ac2135d7
10 changed files with 7 additions and 243 deletions
|
@ -1,8 +0,0 @@
|
|||
module.exports = function createApiDocument(primary, included) {
|
||||
const doc = {data: primary};
|
||||
if (included) {
|
||||
doc.included = included;
|
||||
}
|
||||
|
||||
return doc;
|
||||
};
|
|
@ -1,8 +0,0 @@
|
|||
module.exports = function createRelationshipObject(type, id) {
|
||||
return {
|
||||
data: {
|
||||
type: type,
|
||||
id: id
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
module.exports = function createResourceObject(type, id, attributes, relationships) {
|
||||
const resource = {
|
||||
type: type,
|
||||
id: id,
|
||||
attributes: attributes
|
||||
};
|
||||
if (relationships) {
|
||||
resource.relationships = relationships;
|
||||
}
|
||||
|
||||
return resource;
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
const { convertToSnakeCase } = require('../../../lib/case_conversion');
|
||||
const _ = require('lodash');
|
||||
const createApiDocument = require('../../../lib/api_document_builders/create_api_document');
|
||||
const createResourceObject = require('../../../lib/api_document_builders/create_resource_object');
|
||||
|
||||
|
||||
module.exports = function getIndexPattern(patternId, boundCallWithRequest) {
|
||||
const params = {
|
||||
index: '.kibana',
|
||||
type: 'index-pattern',
|
||||
id: patternId
|
||||
};
|
||||
|
||||
return boundCallWithRequest('get', params)
|
||||
.then((result) => {
|
||||
if (result._source.fields) {
|
||||
result._source.fields = JSON.parse(result._source.fields);
|
||||
}
|
||||
if (result._source.fieldFormatMap) {
|
||||
result._source.fieldFormatMap = JSON.parse(result._source.fieldFormatMap);
|
||||
}
|
||||
|
||||
const snakeAttributes = convertToSnakeCase(result._source);
|
||||
return createApiDocument(createResourceObject('index_patterns', result._id, snakeAttributes));
|
||||
});
|
||||
};
|
|
@ -1,36 +0,0 @@
|
|||
const { convertToSnakeCase } = require('../../../lib/case_conversion');
|
||||
const _ = require('lodash');
|
||||
const createApiDocument = require('../../../lib/api_document_builders/create_api_document');
|
||||
const createResourceObject = require('../../../lib/api_document_builders/create_resource_object');
|
||||
const Promise = require('bluebird');
|
||||
|
||||
module.exports = function getIndexPatterns(boundCallWithRequest) {
|
||||
const params = {
|
||||
index: '.kibana',
|
||||
type: 'index-pattern',
|
||||
body: {
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return boundCallWithRequest('search', params)
|
||||
.then(function parseResults(results) {
|
||||
const hits = results.hits.hits;
|
||||
return _.map(hits, (patternHit) => {
|
||||
if (patternHit._source.fields) {
|
||||
patternHit._source.fields = JSON.parse(patternHit._source.fields);
|
||||
}
|
||||
if (patternHit._source.fieldFormatMap) {
|
||||
patternHit._source.fieldFormatMap = JSON.parse(patternHit._source.fieldFormatMap);
|
||||
}
|
||||
|
||||
const snakeAttributes = convertToSnakeCase(patternHit._source);
|
||||
return createResourceObject('index_patterns', patternHit._id, snakeAttributes);
|
||||
});
|
||||
})
|
||||
.then((patterns) => {
|
||||
return createApiDocument(patterns);
|
||||
});
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
export default function (server) {
|
||||
require('./register_get')(server);
|
||||
require('./register_post')(server);
|
||||
require('./register_delete')(server);
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
const _ = require('lodash');
|
||||
const handleESError = require('../../../lib/handle_es_error');
|
||||
const getIndexPattern = require('./get_index_pattern');
|
||||
const getIndexPatterns = require('./get_index_patterns');
|
||||
|
||||
module.exports = function registerGet(server) {
|
||||
|
||||
server.route({
|
||||
path: '/api/kibana/index_patterns',
|
||||
method: 'GET',
|
||||
handler: function (req, reply) {
|
||||
const boundCallWithRequest = _.partial(server.plugins.elasticsearch.callWithRequest, req);
|
||||
|
||||
getIndexPatterns(boundCallWithRequest)
|
||||
.then(
|
||||
function (patterns) {
|
||||
reply(patterns);
|
||||
},
|
||||
function (error) {
|
||||
reply(handleESError(error));
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
path: '/api/kibana/index_patterns/{id}',
|
||||
method: 'GET',
|
||||
handler: function (req, reply) {
|
||||
const boundCallWithRequest = _.partial(server.plugins.elasticsearch.callWithRequest, req);
|
||||
const patternId = req.params.id;
|
||||
|
||||
getIndexPattern(patternId, boundCallWithRequest)
|
||||
.then(
|
||||
function (pattern) {
|
||||
reply(pattern);
|
||||
},
|
||||
function (error) {
|
||||
reply(handleESError(error));
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
|
@ -1,102 +0,0 @@
|
|||
define(function (require) {
|
||||
var _ = require('intern/dojo/node!lodash');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
var createTestData = require('intern/dojo/node!../../../unit/api/index_patterns/data');
|
||||
var Promise = require('bluebird');
|
||||
var indexPatternSchema = require('intern/dojo/node!../../../../src/plugins/kibana/server/lib/schemas/resources/index_pattern_schema');
|
||||
var Joi = require('intern/dojo/node!joi');
|
||||
|
||||
function expectSnakeCase(object) {
|
||||
_.forEach(object, function (value, key) {
|
||||
expect(key).to.be(_.snakeCase(key));
|
||||
});
|
||||
}
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
|
||||
bdd.describe('GET index_patterns', function getIndexPatterns() {
|
||||
|
||||
bdd.before(function () {
|
||||
return scenarioManager.reload('emptyKibana').then(function () {
|
||||
return Promise.all([
|
||||
request.post('/kibana/index_patterns').send(createTestData().indexPattern),
|
||||
request.post('/kibana/index_patterns').send(
|
||||
_(createTestData().indexPattern)
|
||||
.set('data.attributes.title', 'foo')
|
||||
.set('data.id', 'foo')
|
||||
.value()
|
||||
),
|
||||
request.post('/kibana/index_patterns').send(
|
||||
_(createTestData().indexPattern)
|
||||
.set('data.attributes.title', 'bar*')
|
||||
.set('data.id', 'bar*')
|
||||
.value()
|
||||
)
|
||||
]).then(function () {
|
||||
return scenarioManager.client.indices.refresh({
|
||||
index: '.kibana'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.after(function () {
|
||||
return Promise.all([
|
||||
request.del('/kibana/index_patterns/logstash-*'),
|
||||
request.del('/kibana/index_patterns/foo'),
|
||||
request.del('/kibana/index_patterns/bar*')
|
||||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return 200 with all patterns in an array', function return200() {
|
||||
return request.get('/kibana/index_patterns')
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
expect(res.body.data).to.be.an('array');
|
||||
expect(res.body.data.length).to.be(3);
|
||||
expect(res.body.included).to.not.be.ok();
|
||||
Joi.assert(res.body, indexPatternSchema.post);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should use snake_case in the response body', function () {
|
||||
return request.get('/kibana/index_patterns')
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
_.forEach(res.body.data, function (resource) {
|
||||
expectSnakeCase(resource);
|
||||
expectSnakeCase(resource.attributes);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.describe('GET index_pattern by ID', function getIndexPatternByID() {
|
||||
|
||||
bdd.it('should return 200 with the valid index pattern requested', function () {
|
||||
return request.get('/kibana/index_patterns/logstash-*')
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
expect(res.body.data.attributes.title).to.be('logstash-*');
|
||||
Joi.assert(res.body, indexPatternSchema.post);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should use snake_case in the response body', function () {
|
||||
return request.get('/kibana/index_patterns/logstash-*')
|
||||
.expect(200)
|
||||
.then(function (res) {
|
||||
expectSnakeCase(res.body.data);
|
||||
expectSnakeCase(res.body.data.attributes);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should return 404 for a non-existent ID', function () {
|
||||
return request.get('/kibana/index_patterns/thisdoesnotexist').expect(404);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
@ -58,12 +58,15 @@ define(function (require) {
|
|||
.send(createTestData().indexPattern)
|
||||
.expect(201)
|
||||
.then(function () {
|
||||
return request.get('/kibana/index_patterns/logstash-*')
|
||||
.expect(200)
|
||||
return scenarioManager.client.get({
|
||||
index: '.kibana',
|
||||
type: 'index-pattern',
|
||||
id: 'logstash-*'
|
||||
})
|
||||
.then(function (res) {
|
||||
var fields = res.body.data.attributes.fields;
|
||||
var fields = JSON.parse(res._source.fields);
|
||||
// @timestamp was created with only name and type, all other fields should be set as defaults by API
|
||||
expect(res.body.data.attributes.title).to.be('logstash-*');
|
||||
expect(res._source.title).to.be('logstash-*');
|
||||
expect(fields[1].name).to.be('@timestamp');
|
||||
expect(fields[1].type).to.be('date');
|
||||
expect(fields[1].count).to.be(0);
|
||||
|
|
|
@ -7,7 +7,6 @@ define(function (require) {
|
|||
var _ = require('intern/dojo/node!lodash');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
var post = require('./_post');
|
||||
var get = require('./_get');
|
||||
var del = require('./_del');
|
||||
|
||||
bdd.describe('index_patterns API', function () {
|
||||
|
@ -22,7 +21,6 @@ define(function (require) {
|
|||
return scenarioManager.unload('emptyKibana');
|
||||
});
|
||||
|
||||
get(bdd, scenarioManager, request);
|
||||
post(bdd, scenarioManager, request);
|
||||
del(bdd, scenarioManager, request);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue