Pattern to name conversion is no longer just for templates

This commit is contained in:
Matthew Bargar 2016-01-28 14:15:09 -05:00
parent 15d387f644
commit 1c6c97a7b2
4 changed files with 15 additions and 15 deletions

View file

@ -1,29 +1,29 @@
const {templateToPattern, patternToTemplate} = require('../convert_pattern_and_template_name');
const {ingestToPattern, patternToIngest} = require('../convert_pattern_and_ingest_name');
const expect = require('expect.js');
describe('convertPatternAndTemplateName', function () {
describe('templateToPattern', function () {
describe('ingestToPattern', function () {
it('should convert an index template\'s name to its matching index pattern\'s title', function () {
expect(templateToPattern('kibana-logstash-*')).to.be('logstash-*');
expect(ingestToPattern('kibana-logstash-*')).to.be('logstash-*');
});
it('should throw an error if the template name isn\'t a valid kibana namespaced name', function () {
expect(templateToPattern).withArgs('logstash-*').to.throwException('not a valid kibana namespaced template name');
expect(templateToPattern).withArgs('').to.throwException(/not a valid kibana namespaced template name/);
expect(ingestToPattern).withArgs('logstash-*').to.throwException('not a valid kibana namespaced template name');
expect(ingestToPattern).withArgs('').to.throwException(/not a valid kibana namespaced template name/);
});
});
describe('patternToTemplate', function () {
describe('patternToIngest', function () {
it('should convert an index pattern\'s title to its matching index template\'s name', function () {
expect(patternToTemplate('logstash-*')).to.be('kibana-logstash-*');
expect(patternToIngest('logstash-*')).to.be('kibana-logstash-*');
});
it('should throw an error if the pattern is empty', function () {
expect(patternToTemplate).withArgs('').to.throwException(/pattern must not be empty/);
expect(patternToIngest).withArgs('').to.throwException(/pattern must not be empty/);
});
});

View file

@ -4,7 +4,7 @@
// This module provides utility functions for easily converting between template and pattern names.
module.exports = {
templateToPattern: (templateName) => {
ingestToPattern: (templateName) => {
if (templateName.indexOf('kibana-') === -1) {
throw new Error('not a valid kibana namespaced template name');
}
@ -12,7 +12,7 @@ module.exports = {
return templateName.slice(templateName.indexOf('-') + 1);
},
patternToTemplate: (patternName) => {
patternToIngest: (patternName) => {
if (patternName === '') {
throw new Error('pattern must not be empty');
}

View file

@ -1,6 +1,6 @@
const Promise = require('bluebird');
const handleESError = require('../../../lib/handle_es_error');
const {templateToPattern, patternToTemplate} = require('../../../lib/convert_pattern_and_template_name');
const {ingestToPattern, patternToIngest} = require('../../../lib/convert_pattern_and_ingest_name');
module.exports = function registerDelete(server) {
server.route({
@ -16,9 +16,9 @@ module.exports = function registerDelete(server) {
Promise.all([
callWithRequest(req, 'delete', deletePatternParams),
callWithRequest(req, 'indices.deleteTemplate', {name: patternToTemplate(req.params.id), ignore: [404]}),
callWithRequest(req, 'indices.deleteTemplate', {name: patternToIngest(req.params.id), ignore: [404]}),
callWithRequest(req, 'transport.request', {
path: `_ingest/pipeline/${patternToTemplate(req.params.id)}`,
path: `_ingest/pipeline/${patternToIngest(req.params.id)}`,
method: 'DELETE'
})
])

View file

@ -1,6 +1,6 @@
const Boom = require('boom');
const _ = require('lodash');
const {templateToPattern, patternToTemplate} = require('../../../lib/convert_pattern_and_template_name');
const {ingestToPattern, patternToIngest} = require('../../../lib/convert_pattern_and_ingest_name');
const ingestConfigSchema = require('../../../lib/schemas/resources/ingest_config_schema');
const handleESError = require('../../../lib/handle_es_error');
const { keysToCamelCaseShallow } = require('../../../lib/case_conversion');
@ -66,7 +66,7 @@ module.exports = function registerPost(server) {
const requestDocument = _.cloneDeep(req.payload);
const indexPattern = keysToCamelCaseShallow(requestDocument.index_pattern);
const indexPatternId = indexPattern.id;
const ingestConfigName = patternToTemplate(indexPatternId);
const ingestConfigName = patternToIngest(indexPatternId);
delete indexPattern.id;
const mappings = createMappingsFromPatternFields(indexPattern.fields);