Files
elasticsearch-js/api/api/xpack.watcher.get_watch.js
2019-01-29 17:31:43 +01:00

120 lines
3.0 KiB
JavaScript

'use strict'
/* eslint camelcase: 0 */
/* eslint no-unused-vars: 0 */
function buildXpackWatcherGetWatch (opts) {
// eslint-disable-next-line no-unused-vars
const { makeRequest, ConfigurationError, result } = opts
/**
* Perform a [xpack.watcher.get_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-get-watch.html) request
*
* @param {string} id - Watch ID
*/
const acceptedQuerystring = [
]
const snakeCase = {
}
return function xpackWatcherGetWatch (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) => {
xpackWatcherGetWatch(params, options, (err, body) => {
err ? reject(err) : resolve(body)
})
})
}
// check required parameters
if (params['id'] == null) {
return callback(
new ConfigurationError('Missing required parameter: id'),
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, id } = params
var querystring = semicopy(params, ['method', 'body', 'id'])
if (method == null) {
method = 'GET'
}
var ignore = options.ignore || null
if (typeof ignore === 'number') {
ignore = [ignore]
}
var path = ''
path = '/' + '_watcher' + '/' + 'watch' + '/' + encodeURIComponent(id)
// build request object
const request = {
method,
path,
body: null,
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 = buildXpackWatcherGetWatch