130 lines
3.3 KiB
JavaScript
130 lines
3.3 KiB
JavaScript
'use strict'
|
|
|
|
/* eslint camelcase: 0 */
|
|
/* eslint no-unused-vars: 0 */
|
|
|
|
function buildIndicesDeleteTemplate (opts) {
|
|
// eslint-disable-next-line no-unused-vars
|
|
const { makeRequest, ConfigurationError, result } = opts
|
|
/**
|
|
* Perform a [indices.delete_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request
|
|
*
|
|
* @param {string} name - The name of the template
|
|
* @param {time} timeout - Explicit operation timeout
|
|
* @param {time} master_timeout - Specify timeout for connection to master
|
|
*/
|
|
|
|
const acceptedQuerystring = [
|
|
'timeout',
|
|
'master_timeout',
|
|
'pretty',
|
|
'human',
|
|
'error_trace',
|
|
'source',
|
|
'filter_path'
|
|
]
|
|
|
|
const snakeCase = {
|
|
masterTimeout: 'master_timeout',
|
|
errorTrace: 'error_trace',
|
|
filterPath: 'filter_path'
|
|
}
|
|
|
|
return function indicesDeleteTemplate (params, options, callback) {
|
|
options = options || {}
|
|
if (typeof options === 'function') {
|
|
callback = options
|
|
options = {}
|
|
}
|
|
if (typeof params === 'function' || params == null) {
|
|
callback = params
|
|
params = {}
|
|
options = {}
|
|
}
|
|
// promises support
|
|
if (callback == null) {
|
|
return new Promise((resolve, reject) => {
|
|
indicesDeleteTemplate(params, options, (err, body) => {
|
|
err ? reject(err) : resolve(body)
|
|
})
|
|
})
|
|
}
|
|
|
|
// check required parameters
|
|
if (params['name'] == null) {
|
|
return callback(
|
|
new ConfigurationError('Missing required parameter: name'),
|
|
result
|
|
)
|
|
}
|
|
if (params.body != null) {
|
|
return callback(
|
|
new ConfigurationError('This API does not require a body'),
|
|
result
|
|
)
|
|
}
|
|
|
|
// validate headers object
|
|
if (options.headers != null && typeof options.headers !== 'object') {
|
|
return callback(
|
|
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
|
|
result
|
|
)
|
|
}
|
|
|
|
var warnings = null
|
|
var { method, body, name } = params
|
|
var querystring = semicopy(params, ['method', 'body', 'name'])
|
|
|
|
if (method == null) {
|
|
method = 'DELETE'
|
|
}
|
|
|
|
var ignore = options.ignore || null
|
|
if (typeof ignore === 'number') {
|
|
ignore = [ignore]
|
|
}
|
|
|
|
var path = ''
|
|
|
|
path = '/' + '_template' + '/' + encodeURIComponent(name)
|
|
|
|
// build request object
|
|
const request = {
|
|
method,
|
|
path,
|
|
body: '',
|
|
querystring
|
|
}
|
|
|
|
const requestOptions = {
|
|
ignore,
|
|
requestTimeout: options.requestTimeout || null,
|
|
maxRetries: options.maxRetries || null,
|
|
asStream: options.asStream || false,
|
|
headers: options.headers || null,
|
|
warnings
|
|
}
|
|
|
|
return makeRequest(request, requestOptions, callback)
|
|
|
|
function semicopy (obj, exclude) {
|
|
var target = {}
|
|
var keys = Object.keys(obj)
|
|
for (var i = 0, len = keys.length; i < len; i++) {
|
|
var key = keys[i]
|
|
if (exclude.indexOf(key) === -1) {
|
|
target[snakeCase[key] || key] = obj[key]
|
|
if (acceptedQuerystring.indexOf(snakeCase[key] || key) === -1) {
|
|
warnings = warnings || []
|
|
warnings.push('Client - Unknown parameter: "' + key + '", sending it as query parameter')
|
|
}
|
|
}
|
|
}
|
|
return target
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = buildIndicesDeleteTemplate
|