Remove PUT endpoint
This commit is contained in:
parent
c1a32aa8de
commit
bc0406157d
4 changed files with 0 additions and 141 deletions
|
@ -1,6 +1,5 @@
|
|||
export default function (server) {
|
||||
require('./register_get')(server);
|
||||
require('./register_post')(server);
|
||||
require('./register_put')(server);
|
||||
require('./register_delete')(server);
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
const Boom = require('boom');
|
||||
const indexPatternSchema = require('../../../lib/schemas/resources/index_pattern_schema');
|
||||
const _ = require('lodash');
|
||||
const handleESError = require('../../../lib/handle_es_error');
|
||||
const { convertToCamelCase } = require('../../../lib/case_conversion');
|
||||
|
||||
module.exports = function registerPut(server) {
|
||||
server.route({
|
||||
path: '/api/kibana/index_patterns/{id}',
|
||||
method: 'PUT',
|
||||
config: {
|
||||
validate: {
|
||||
payload: indexPatternSchema.put
|
||||
}
|
||||
},
|
||||
handler: function (req, reply) {
|
||||
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
|
||||
const indexPatternResource = _.cloneDeep(req.payload);
|
||||
const indexPatternId = indexPatternResource.data.id;
|
||||
const indexPattern = convertToCamelCase(indexPatternResource.data.attributes);
|
||||
const included = indexPatternResource.included;
|
||||
indexPattern.fields = JSON.stringify(indexPattern.fields);
|
||||
indexPattern.fieldFormatMap = JSON.stringify(indexPattern.fieldFormatMap);
|
||||
|
||||
if (!_.isEmpty(included)) {
|
||||
return reply(Boom.badRequest('PUT does not support included resource updates'));
|
||||
}
|
||||
|
||||
const params = {
|
||||
index: '.kibana',
|
||||
type: 'index-pattern',
|
||||
id: indexPatternId,
|
||||
body: {
|
||||
doc: indexPattern
|
||||
}
|
||||
};
|
||||
callWithRequest(req, 'update', params)
|
||||
.then(function () {
|
||||
return reply('success');
|
||||
}, function (error) {
|
||||
return reply(handleESError(error));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
|
@ -1,93 +0,0 @@
|
|||
define(function (require) {
|
||||
var Promise = require('bluebird');
|
||||
var createTestData = require('intern/dojo/node!../../../unit/api/index_patterns/data');
|
||||
var _ = require('intern/dojo/node!lodash');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
|
||||
bdd.describe('PUT index_patterns', function putIndexPatterns() {
|
||||
|
||||
bdd.beforeEach(function () {
|
||||
return scenarioManager.reload('emptyKibana').then(function () {
|
||||
return request.post('/kibana/index_patterns').send(createTestData().indexPatternWithTemplate);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.afterEach(function () {
|
||||
return request.del('/kibana/index_patterns/logstash-*?include=template');
|
||||
});
|
||||
|
||||
bdd.it('should return 200 for a successful update', function () {
|
||||
var pattern = createTestData().indexPatternWithTemplate;
|
||||
delete pattern.included;
|
||||
pattern.data.attributes.time_field_name = 'foo';
|
||||
pattern.data.attributes.fields[0].count = 5;
|
||||
|
||||
return request.put('/kibana/index_patterns/logstash-*')
|
||||
.send(pattern)
|
||||
.expect(200)
|
||||
.then(function () {
|
||||
return request.get('/kibana/index_patterns/logstash-*');
|
||||
})
|
||||
.then(function (res) {
|
||||
expect(res.body.data.attributes.time_field_name).to.be('foo');
|
||||
expect(res.body.data.attributes.fields[0].count).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should return 400 if you try to update an included template', function () {
|
||||
return request.put('/kibana/index_patterns/logstash-*')
|
||||
.send(createTestData().indexPatternWithTemplate)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
bdd.it('should return 400 for an invalid payload', function () {
|
||||
const putTestData = createTestData().indexPatternWithTemplate;
|
||||
delete putTestData.included;
|
||||
|
||||
return Promise.all([
|
||||
request.put('/kibana/index_patterns/logstash-*').expect(400),
|
||||
|
||||
request.put('/kibana/index_patterns/logstash-*')
|
||||
.send({})
|
||||
.expect(400),
|
||||
|
||||
//fields must be an array
|
||||
request.put('/kibana/index_patterns/logstash-*')
|
||||
.send(_.set(putTestData, 'data.attributes.fields', {}))
|
||||
.expect(400),
|
||||
|
||||
// field objects must have a name
|
||||
request.put('/kibana/index_patterns/logstash-*')
|
||||
.send(_.set(putTestData, 'data.attributes.fields', [{count: 0}]))
|
||||
.expect(400)
|
||||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return 404 for a non-existent id', function () {
|
||||
var pattern = createTestData().indexPatternWithTemplate;
|
||||
pattern.data.id = 'idonotexist';
|
||||
pattern.data.attributes.title = 'idonotexist';
|
||||
delete pattern.included;
|
||||
|
||||
return request.put('/kibana/index_patterns/idonotexist')
|
||||
.send(pattern)
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
bdd.it('should enforce snake_case in the request body', function () {
|
||||
var pattern = createTestData().indexPatternWithTemplate;
|
||||
pattern.data.attributes.timeFieldName = 'foo';
|
||||
delete pattern.data.attributes.time_field_name;
|
||||
delete pattern.included;
|
||||
|
||||
return request.put('/kibana/index_patterns/logstash-*')
|
||||
.send(pattern)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
});
|
|
@ -8,7 +8,6 @@ define(function (require) {
|
|||
var expect = require('intern/dojo/node!expect.js');
|
||||
var post = require('./_post');
|
||||
var get = require('./_get');
|
||||
var put = require('./_put');
|
||||
var del = require('./_del');
|
||||
|
||||
bdd.describe('index_patterns API', function () {
|
||||
|
@ -25,7 +24,6 @@ define(function (require) {
|
|||
|
||||
get(bdd, scenarioManager, request);
|
||||
post(bdd, scenarioManager, request);
|
||||
put(bdd, scenarioManager, request);
|
||||
del(bdd, scenarioManager, request);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue