API generation

This commit is contained in:
delvedor
2018-10-30 17:26:22 +01:00
parent ad9b68aea6
commit 55c507c423
123 changed files with 15280 additions and 8 deletions

130
api/api/cluster.health.js Normal file
View File

@ -0,0 +1,130 @@
'use strict'
function buildClusterHealth (opts) {
// eslint-disable-next-line no-unused-vars
const { makeRequest, ConfigurationError } = opts
/**
* Perform a [cluster.health](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html) request
*
* @param {list} index - Limit the information returned to a specific index
* @param {enum} level - Specify the level of detail for returned information
* @param {boolean} local - Return local information, do not retrieve the state from master node (default: false)
* @param {time} master_timeout - Explicit operation timeout for connection to master node
* @param {time} timeout - Explicit operation timeout
* @param {string} wait_for_active_shards - Wait until the specified number of shards is active
* @param {string} wait_for_nodes - Wait until the specified number of nodes is available
* @param {enum} wait_for_events - Wait until all currently queued events with the given priority are processed
* @param {boolean} wait_for_no_relocating_shards - Whether to wait until there are no relocating shards in the cluster
* @param {boolean} wait_for_no_initializing_shards - Whether to wait until there are no initializing shards in the cluster
* @param {enum} wait_for_status - Wait until cluster is in a specific state
*/
return function clusterHealth (params, callback) {
if (typeof params === 'function' || params == null) {
callback = params
params = {}
}
// promises support
if (callback == null) {
return new Promise((resolve, reject) => {
clusterHealth(params, (err, body) => {
err ? reject(err) : resolve(body)
})
})
}
// check required parameters
if (params.body != null) {
return callback(
new ConfigurationError('This API does not require a body'),
{ body: null, headers: null, statusCode: null }
)
}
// build querystring object
const querystring = {}
const keys = Object.keys(params)
const acceptedQuerystring = [
'level',
'local',
'master_timeout',
'timeout',
'wait_for_active_shards',
'wait_for_nodes',
'wait_for_events',
'wait_for_no_relocating_shards',
'wait_for_no_initializing_shards',
'wait_for_status',
'pretty',
'human',
'error_trace',
'source',
'filter_path'
]
const acceptedQuerystringCamelCased = [
'level',
'local',
'masterTimeout',
'timeout',
'waitForActiveShards',
'waitForNodes',
'waitForEvents',
'waitForNoRelocatingShards',
'waitForNoInitializingShards',
'waitForStatus',
'pretty',
'human',
'errorTrace',
'source',
'filterPath'
]
for (var i = 0, len = keys.length; i < len; i++) {
var key = keys[i]
if (acceptedQuerystring.indexOf(key) !== -1) {
querystring[key] = params[key]
} else {
var camelIndex = acceptedQuerystringCamelCased.indexOf(key)
if (camelIndex !== -1) {
querystring[acceptedQuerystring[camelIndex]] = params[key]
}
}
}
// configure http method
var method = params.method
if (method == null) {
method = 'GET'
}
// validate headers object
if (params.headers != null && typeof params.headers !== 'object') {
return callback(
new ConfigurationError(`Headers should be an object, instead got: ${typeof params.headers}`),
{ body: null, headers: null, statusCode: null }
)
}
var ignore = params.ignore || null
if (typeof ignore === 'number') {
ignore = [ignore]
}
// build request object
const parts = ['_cluster', 'health', params['index']]
const request = {
method,
path: '/' + parts.filter(Boolean).map(encodeURIComponent).join('/'),
querystring,
body: null,
headers: params.headers || null,
ignore,
requestTimeout: params.requestTimeout || null,
agent: null,
url: ''
}
return makeRequest(request, callback)
}
}
module.exports = buildClusterHealth