diff --git a/api/api/bulk.js b/api/api/bulk.js index fda39fb40..f1f47b959 100644 --- a/api/api/bulk.js +++ b/api/api/bulk.js @@ -24,7 +24,7 @@ function buildBulk (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [bulk](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-bulk.html) request * @@ -99,17 +99,17 @@ function buildBulk (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -130,36 +130,8 @@ function buildBulk (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.aliases.js b/api/api/cat.aliases.js index dda2b5e37..239541734 100644 --- a/api/api/cat.aliases.js +++ b/api/api/cat.aliases.js @@ -24,7 +24,7 @@ function buildCatAliases (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.aliases](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-alias.html) request * @@ -83,17 +83,17 @@ function buildCatAliases (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, name } = params - var querystring = semicopy(params, ['method', 'body', 'name']) + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -112,36 +112,8 @@ function buildCatAliases (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.allocation.js b/api/api/cat.allocation.js index daa974d9e..8ba8a3bd6 100644 --- a/api/api/cat.allocation.js +++ b/api/api/cat.allocation.js @@ -24,7 +24,7 @@ function buildCatAllocation (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.allocation](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-allocation.html) request * @@ -85,17 +85,17 @@ function buildCatAllocation (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, nodeId, node_id } = params - var querystring = semicopy(params, ['method', 'body', 'nodeId', 'node_id']) + var warnings = [] + var { method, body, nodeId, node_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -114,36 +114,8 @@ function buildCatAllocation (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.count.js b/api/api/cat.count.js index dba60e054..1a70a2974 100644 --- a/api/api/cat.count.js +++ b/api/api/cat.count.js @@ -24,7 +24,7 @@ function buildCatCount (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.count](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-count.html) request * @@ -83,17 +83,17 @@ function buildCatCount (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -112,36 +112,8 @@ function buildCatCount (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.fielddata.js b/api/api/cat.fielddata.js index ad03e8510..721c47452 100644 --- a/api/api/cat.fielddata.js +++ b/api/api/cat.fielddata.js @@ -24,7 +24,7 @@ function buildCatFielddata (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.fielddata](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-fielddata.html) request * @@ -87,17 +87,17 @@ function buildCatFielddata (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, fields } = params - var querystring = semicopy(params, ['method', 'body', 'fields']) + var warnings = [] + var { method, body, fields, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -116,36 +116,8 @@ function buildCatFielddata (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.health.js b/api/api/cat.health.js index 959ebc58b..5f668c45c 100644 --- a/api/api/cat.health.js +++ b/api/api/cat.health.js @@ -24,7 +24,7 @@ function buildCatHealth (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.health](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-health.html) request * @@ -84,17 +84,17 @@ function buildCatHealth (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -109,36 +109,8 @@ function buildCatHealth (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.help.js b/api/api/cat.help.js index 5cd06ef63..de1065d16 100644 --- a/api/api/cat.help.js +++ b/api/api/cat.help.js @@ -24,7 +24,7 @@ function buildCatHelp (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.help](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat.html) request * @@ -71,17 +71,17 @@ function buildCatHelp (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -96,36 +96,8 @@ function buildCatHelp (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.indices.js b/api/api/cat.indices.js index a949f7d16..9fd0f6ff6 100644 --- a/api/api/cat.indices.js +++ b/api/api/cat.indices.js @@ -24,7 +24,7 @@ function buildCatIndices (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.indices](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-indices.html) request * @@ -89,17 +89,17 @@ function buildCatIndices (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -118,36 +118,8 @@ function buildCatIndices (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.master.js b/api/api/cat.master.js index d17566356..901be4026 100644 --- a/api/api/cat.master.js +++ b/api/api/cat.master.js @@ -24,7 +24,7 @@ function buildCatMaster (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.master](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-master.html) request * @@ -82,17 +82,17 @@ function buildCatMaster (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -107,36 +107,8 @@ function buildCatMaster (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.nodeattrs.js b/api/api/cat.nodeattrs.js index cadad2dfc..72c98d9e7 100644 --- a/api/api/cat.nodeattrs.js +++ b/api/api/cat.nodeattrs.js @@ -24,7 +24,7 @@ function buildCatNodeattrs (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.nodeattrs](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-nodeattrs.html) request * @@ -82,17 +82,17 @@ function buildCatNodeattrs (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -107,36 +107,8 @@ function buildCatNodeattrs (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.nodes.js b/api/api/cat.nodes.js index b387abda8..9907cc4f5 100644 --- a/api/api/cat.nodes.js +++ b/api/api/cat.nodes.js @@ -24,7 +24,7 @@ function buildCatNodes (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.nodes](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-nodes.html) request * @@ -85,17 +85,17 @@ function buildCatNodes (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -110,36 +110,8 @@ function buildCatNodes (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.pending_tasks.js b/api/api/cat.pending_tasks.js index e9a1e2870..ad3ee3db7 100644 --- a/api/api/cat.pending_tasks.js +++ b/api/api/cat.pending_tasks.js @@ -24,7 +24,7 @@ function buildCatPendingTasks (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.pending_tasks](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-pending-tasks.html) request * @@ -82,17 +82,17 @@ function buildCatPendingTasks (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -107,36 +107,8 @@ function buildCatPendingTasks (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.plugins.js b/api/api/cat.plugins.js index 7d2c60f3a..fbc79d0ea 100644 --- a/api/api/cat.plugins.js +++ b/api/api/cat.plugins.js @@ -24,7 +24,7 @@ function buildCatPlugins (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.plugins](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-plugins.html) request * @@ -82,17 +82,17 @@ function buildCatPlugins (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -107,36 +107,8 @@ function buildCatPlugins (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.recovery.js b/api/api/cat.recovery.js index 022695436..b53826a90 100644 --- a/api/api/cat.recovery.js +++ b/api/api/cat.recovery.js @@ -24,7 +24,7 @@ function buildCatRecovery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.recovery](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-recovery.html) request * @@ -83,17 +83,17 @@ function buildCatRecovery (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -112,36 +112,8 @@ function buildCatRecovery (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.repositories.js b/api/api/cat.repositories.js index 79fe7ad6c..70a02fdbb 100644 --- a/api/api/cat.repositories.js +++ b/api/api/cat.repositories.js @@ -24,7 +24,7 @@ function buildCatRepositories (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.repositories](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-repositories.html) request * @@ -82,17 +82,17 @@ function buildCatRepositories (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -107,36 +107,8 @@ function buildCatRepositories (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.segments.js b/api/api/cat.segments.js index 357ba372d..b0ca5827d 100644 --- a/api/api/cat.segments.js +++ b/api/api/cat.segments.js @@ -24,7 +24,7 @@ function buildCatSegments (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.segments](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-segments.html) request * @@ -80,17 +80,17 @@ function buildCatSegments (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -109,36 +109,8 @@ function buildCatSegments (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.shards.js b/api/api/cat.shards.js index 505787744..eec14151a 100644 --- a/api/api/cat.shards.js +++ b/api/api/cat.shards.js @@ -24,7 +24,7 @@ function buildCatShards (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.shards](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-shards.html) request * @@ -85,17 +85,17 @@ function buildCatShards (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -114,36 +114,8 @@ function buildCatShards (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.snapshots.js b/api/api/cat.snapshots.js index 943f27233..ea6d13197 100644 --- a/api/api/cat.snapshots.js +++ b/api/api/cat.snapshots.js @@ -24,7 +24,7 @@ function buildCatSnapshots (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.snapshots](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-snapshots.html) request * @@ -88,17 +88,17 @@ function buildCatSnapshots (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository } = params - var querystring = semicopy(params, ['method', 'body', 'repository']) + var warnings = [] + var { method, body, repository, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -117,36 +117,8 @@ function buildCatSnapshots (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.tasks.js b/api/api/cat.tasks.js index 73cd320ab..192560583 100644 --- a/api/api/cat.tasks.js +++ b/api/api/cat.tasks.js @@ -24,7 +24,7 @@ function buildCatTasks (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.tasks](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html) request * @@ -90,17 +90,17 @@ function buildCatTasks (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -115,36 +115,8 @@ function buildCatTasks (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.templates.js b/api/api/cat.templates.js index 61f5c7b8c..047f5e943 100644 --- a/api/api/cat.templates.js +++ b/api/api/cat.templates.js @@ -24,7 +24,7 @@ function buildCatTemplates (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.templates](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-templates.html) request * @@ -83,17 +83,17 @@ function buildCatTemplates (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, name } = params - var querystring = semicopy(params, ['method', 'body', 'name']) + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -112,36 +112,8 @@ function buildCatTemplates (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cat.thread_pool.js b/api/api/cat.thread_pool.js index 1cd7c2a2e..b25affda4 100644 --- a/api/api/cat.thread_pool.js +++ b/api/api/cat.thread_pool.js @@ -24,7 +24,7 @@ function buildCatThreadPool (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cat.thread_pool](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cat-thread-pool.html) request * @@ -85,17 +85,17 @@ function buildCatThreadPool (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, threadPoolPatterns, thread_pool_patterns } = params - var querystring = semicopy(params, ['method', 'body', 'threadPoolPatterns', 'thread_pool_patterns']) + var warnings = [] + var { method, body, threadPoolPatterns, thread_pool_patterns, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -114,36 +114,8 @@ function buildCatThreadPool (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/ccr.delete_auto_follow_pattern.js b/api/api/ccr.delete_auto_follow_pattern.js new file mode 100644 index 000000000..d9d8dbf8c --- /dev/null +++ b/api/api/ccr.delete_auto_follow_pattern.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrDeleteAutoFollowPattern (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.delete_auto_follow_pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html) request + * + * @param {string} name - The name of the auto follow pattern. + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrDeleteAutoFollowPattern (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['name'] == null) { + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ccr' + '/' + 'auto_follow' + '/' + encodeURIComponent(name) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrDeleteAutoFollowPattern diff --git a/api/api/ccr.follow.js b/api/api/ccr.follow.js new file mode 100644 index 000000000..f98f46dab --- /dev/null +++ b/api/api/ccr.follow.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrFollow (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.follow](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.html) request + * + * @param {string} index - The name of the follower index + * @param {string} wait_for_active_shards - Sets the number of shard copies that must be active before returning. Defaults to 0. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) + * @param {object} body - The name of the leader index and other optional ccr related parameters + */ + + const acceptedQuerystring = [ + 'wait_for_active_shards' + ] + + const snakeCase = { + waitForActiveShards: 'wait_for_active_shards' + } + + return function ccrFollow (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['index'] == null) { + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ccr' + '/' + 'follow' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrFollow diff --git a/api/api/ccr.follow_info.js b/api/api/ccr.follow_info.js new file mode 100644 index 000000000..2599c47eb --- /dev/null +++ b/api/api/ccr.follow_info.js @@ -0,0 +1,90 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrFollowInfo (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.follow_info](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html) request + * + * @param {list} index - A comma-separated list of index patterns; use `_all` to perform the operation on all indices + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrFollowInfo (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ccr' + '/' + 'info' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrFollowInfo diff --git a/api/api/ccr.follow_stats.js b/api/api/ccr.follow_stats.js new file mode 100644 index 000000000..6d4b118d7 --- /dev/null +++ b/api/api/ccr.follow_stats.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrFollowStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.follow_stats](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html) request + * + * @param {list} index - A comma-separated list of index patterns; use `_all` to perform the operation on all indices + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrFollowStats (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['index'] == null) { + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ccr' + '/' + 'stats' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrFollowStats diff --git a/api/api/ccr.forget_follower.js b/api/api/ccr.forget_follower.js new file mode 100644 index 000000000..a13fed2f7 --- /dev/null +++ b/api/api/ccr.forget_follower.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrForgetFollower (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.forget_follower](http://www.elastic.co/guide/en/elasticsearch/reference/current) request + * + * @param {string} index - the name of the leader index for which specified follower retention leases should be removed + * @param {object} body - the name and UUID of the follower index, the name of the cluster containing the follower index, and the alias from the perspective of that cluster for the remote cluster containing the leader index + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrForgetFollower (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['index'] == null) { + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ccr' + '/' + 'forget_follower' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrForgetFollower diff --git a/api/api/ccr.get_auto_follow_pattern.js b/api/api/ccr.get_auto_follow_pattern.js new file mode 100644 index 000000000..4408c4fc9 --- /dev/null +++ b/api/api/ccr.get_auto_follow_pattern.js @@ -0,0 +1,94 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrGetAutoFollowPattern (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.get_auto_follow_pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html) request + * + * @param {string} name - The name of the auto follow pattern. + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrGetAutoFollowPattern (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((name) != null) { + path = '/' + '_ccr' + '/' + 'auto_follow' + '/' + encodeURIComponent(name) + } else { + path = '/' + '_ccr' + '/' + 'auto_follow' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrGetAutoFollowPattern diff --git a/api/api/ccr.pause_follow.js b/api/api/ccr.pause_follow.js new file mode 100644 index 000000000..36038853a --- /dev/null +++ b/api/api/ccr.pause_follow.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrPauseFollow (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.pause_follow](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-pause-follow.html) request + * + * @param {string} index - The name of the follower index that should pause following its leader index. + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrPauseFollow (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['index'] == null) { + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ccr' + '/' + 'pause_follow' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrPauseFollow diff --git a/api/api/ccr.put_auto_follow_pattern.js b/api/api/ccr.put_auto_follow_pattern.js new file mode 100644 index 000000000..c01ceeeae --- /dev/null +++ b/api/api/ccr.put_auto_follow_pattern.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrPutAutoFollowPattern (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.put_auto_follow_pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-auto-follow-pattern.html) request + * + * @param {string} name - The name of the auto follow pattern. + * @param {object} body - The specification of the auto follow pattern + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrPutAutoFollowPattern (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['name'] == null) { + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ccr' + '/' + 'auto_follow' + '/' + encodeURIComponent(name) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrPutAutoFollowPattern diff --git a/api/api/ccr.resume_follow.js b/api/api/ccr.resume_follow.js new file mode 100644 index 000000000..6a55c779d --- /dev/null +++ b/api/api/ccr.resume_follow.js @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrResumeFollow (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.resume_follow](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-resume-follow.html) request + * + * @param {string} index - The name of the follow index to resume following. + * @param {object} body - The name of the leader index and other optional ccr related parameters + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrResumeFollow (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['index'] == null) { + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ccr' + '/' + 'resume_follow' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrResumeFollow diff --git a/api/api/ccr.stats.js b/api/api/ccr.stats.js new file mode 100644 index 000000000..4297da6c7 --- /dev/null +++ b/api/api/ccr.stats.js @@ -0,0 +1,89 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.stats](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-stats.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrStats (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ccr' + '/' + 'stats' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrStats diff --git a/api/api/ccr.unfollow.js b/api/api/ccr.unfollow.js new file mode 100644 index 000000000..50601072b --- /dev/null +++ b/api/api/ccr.unfollow.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildCcrUnfollow (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ccr.unfollow](http://www.elastic.co/guide/en/elasticsearch/reference/current) request + * + * @param {string} index - The name of the follower index that should be turned into a regular index. + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ccrUnfollow (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['index'] == null) { + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ccr' + '/' + 'unfollow' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildCcrUnfollow diff --git a/api/api/clear_scroll.js b/api/api/clear_scroll.js index 01c4c6f52..ab6f1b586 100644 --- a/api/api/clear_scroll.js +++ b/api/api/clear_scroll.js @@ -24,7 +24,7 @@ function buildClearScroll (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [clear_scroll](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-request-scroll.html) request * @@ -63,17 +63,17 @@ function buildClearScroll (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, scrollId, scroll_id } = params - var querystring = semicopy(params, ['method', 'body', 'scrollId', 'scroll_id']) + var warnings = [] + var { method, body, scrollId, scroll_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -92,36 +92,8 @@ function buildClearScroll (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.allocation_explain.js b/api/api/cluster.allocation_explain.js index 6e21d9e7b..f480709b7 100644 --- a/api/api/cluster.allocation_explain.js +++ b/api/api/cluster.allocation_explain.js @@ -24,7 +24,7 @@ function buildClusterAllocationExplain (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.allocation_explain](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-allocation-explain.html) request * @@ -68,17 +68,17 @@ function buildClusterAllocationExplain (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -93,36 +93,8 @@ function buildClusterAllocationExplain (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.get_settings.js b/api/api/cluster.get_settings.js index 44b8d6b2a..fd3ffbbaf 100644 --- a/api/api/cluster.get_settings.js +++ b/api/api/cluster.get_settings.js @@ -24,7 +24,7 @@ function buildClusterGetSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.get_settings](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-update-settings.html) request * @@ -78,17 +78,17 @@ function buildClusterGetSettings (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -103,36 +103,8 @@ function buildClusterGetSettings (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.health.js b/api/api/cluster.health.js index 51154f37f..879384acb 100644 --- a/api/api/cluster.health.js +++ b/api/api/cluster.health.js @@ -24,7 +24,7 @@ function buildClusterHealth (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.health](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-health.html) request * @@ -92,17 +92,17 @@ function buildClusterHealth (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -121,36 +121,8 @@ function buildClusterHealth (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.pending_tasks.js b/api/api/cluster.pending_tasks.js index 6657254d9..ea03729af 100644 --- a/api/api/cluster.pending_tasks.js +++ b/api/api/cluster.pending_tasks.js @@ -24,7 +24,7 @@ function buildClusterPendingTasks (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.pending_tasks](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-pending.html) request * @@ -72,17 +72,17 @@ function buildClusterPendingTasks (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -97,36 +97,8 @@ function buildClusterPendingTasks (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.put_settings.js b/api/api/cluster.put_settings.js index c88a26c2d..1688db284 100644 --- a/api/api/cluster.put_settings.js +++ b/api/api/cluster.put_settings.js @@ -24,7 +24,7 @@ function buildClusterPutSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.put_settings](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-update-settings.html) request * @@ -70,17 +70,17 @@ function buildClusterPutSettings (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -95,36 +95,8 @@ function buildClusterPutSettings (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.remote_info.js b/api/api/cluster.remote_info.js index 5dbf7e36c..009948c4c 100644 --- a/api/api/cluster.remote_info.js +++ b/api/api/cluster.remote_info.js @@ -24,7 +24,7 @@ function buildClusterRemoteInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.remote_info](http://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-remote-info.html) request * @@ -67,17 +67,17 @@ function buildClusterRemoteInfo (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -92,36 +92,8 @@ function buildClusterRemoteInfo (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.reroute.js b/api/api/cluster.reroute.js index bf5f88232..257ca7243 100644 --- a/api/api/cluster.reroute.js +++ b/api/api/cluster.reroute.js @@ -24,7 +24,7 @@ function buildClusterReroute (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.reroute](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-reroute.html) request * @@ -77,17 +77,17 @@ function buildClusterReroute (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildClusterReroute (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.state.js b/api/api/cluster.state.js index 87df58fe2..ec817ea95 100644 --- a/api/api/cluster.state.js +++ b/api/api/cluster.state.js @@ -24,7 +24,7 @@ function buildClusterState (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.state](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-state.html) request * @@ -92,17 +92,17 @@ function buildClusterState (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, metric } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'metric']) + var warnings = [] + var { method, body, index, metric, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -123,36 +123,8 @@ function buildClusterState (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/cluster.stats.js b/api/api/cluster.stats.js index feb83ca69..772d7d1c3 100644 --- a/api/api/cluster.stats.js +++ b/api/api/cluster.stats.js @@ -24,7 +24,7 @@ function buildClusterStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [cluster.stats](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-stats.html) request * @@ -73,17 +73,17 @@ function buildClusterStats (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, nodeId, node_id } = params - var querystring = semicopy(params, ['method', 'body', 'nodeId', 'node_id']) + var warnings = [] + var { method, body, nodeId, node_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildClusterStats (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/count.js b/api/api/count.js index 93569520f..471a5b38b 100644 --- a/api/api/count.js +++ b/api/api/count.js @@ -24,7 +24,7 @@ function buildCount (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [count](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-count.html) request * @@ -103,17 +103,17 @@ function buildCount (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -134,36 +134,8 @@ function buildCount (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/count_percolate.js b/api/api/count_percolate.js index 8bae716b2..78059e2a9 100644 --- a/api/api/count_percolate.js +++ b/api/api/count_percolate.js @@ -24,7 +24,7 @@ function buildCountPercolate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [count_percolate](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-percolate.html) request * @@ -108,17 +108,23 @@ function buildCountPercolate (opts) { return handleError(err, callback) } +<<<<<<< HEAD:api/api/count_percolate.js var warnings = null var { method, body, index, type, id } = params var querystring = semicopy(params, ['method', 'body', 'index', 'type', 'id']) +======= + var warnings = [] + var { method, body, index, target, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) +>>>>>>> 215cc03... Simplify API wrappers (#839):api/api/indices.split.js if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -137,36 +143,8 @@ function buildCountPercolate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/create.js b/api/api/create.js index cecaa4312..0d5c39499 100644 --- a/api/api/create.js +++ b/api/api/create.js @@ -24,7 +24,7 @@ function buildCreate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [create](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-index_.html) request * @@ -105,17 +105,17 @@ function buildCreate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -130,36 +130,8 @@ function buildCreate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/data_frame.delete_data_frame_transform.js b/api/api/data_frame.delete_data_frame_transform.js new file mode 100644 index 000000000..68fb7118d --- /dev/null +++ b/api/api/data_frame.delete_data_frame_transform.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildDataFrameDeleteDataFrameTransform (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [data_frame.delete_data_frame_transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-data-frame-transform.html) request + * + * @param {string} transform_id - The id of the transform to delete + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function dataFrameDeleteDataFrameTransform (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['transform_id'] == null && params['transformId'] == null) { + const err = new ConfigurationError('Missing required parameter: transform_id or transformId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, transformId, transform_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_data_frame' + '/' + 'transforms' + '/' + encodeURIComponent(transform_id || transformId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildDataFrameDeleteDataFrameTransform diff --git a/api/api/data_frame.get_data_frame_transform.js b/api/api/data_frame.get_data_frame_transform.js new file mode 100644 index 000000000..160f75c7e --- /dev/null +++ b/api/api/data_frame.get_data_frame_transform.js @@ -0,0 +1,103 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildDataFrameGetDataFrameTransform (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [data_frame.get_data_frame_transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/get-data-frame-transform.html) request + * + * @param {string} transform_id - The id or comma delimited list of id expressions of the transforms to get, '_all' or '*' implies get all transforms + * @param {int} from - skips a number of transform configs, defaults to 0 + * @param {int} size - specifies a max number of transforms to get, defaults to 100 + */ + + const acceptedQuerystring = [ + 'from', + 'size' + ] + + const snakeCase = { + + } + + return function dataFrameGetDataFrameTransform (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, transformId, transform_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((transform_id || transformId) != null) { + path = '/' + '_data_frame' + '/' + 'transforms' + '/' + encodeURIComponent(transform_id || transformId) + } else { + path = '/' + '_data_frame' + '/' + 'transforms' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildDataFrameGetDataFrameTransform diff --git a/api/api/data_frame.get_data_frame_transform_stats.js b/api/api/data_frame.get_data_frame_transform_stats.js new file mode 100644 index 000000000..c11e1e94b --- /dev/null +++ b/api/api/data_frame.get_data_frame_transform_stats.js @@ -0,0 +1,99 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildDataFrameGetDataFrameTransformStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [data_frame.get_data_frame_transform_stats](https://www.elastic.co/guide/en/elasticsearch/reference/current/get-data-frame-transform-stats.html) request + * + * @param {string} transform_id - The id of the transform for which to get stats. '_all' or '*' implies all transforms + * @param {number} from - skips a number of transform stats, defaults to 0 + * @param {number} size - specifies a max number of transform stats to get, defaults to 100 + */ + + const acceptedQuerystring = [ + 'from', + 'size' + ] + + const snakeCase = { + + } + + return function dataFrameGetDataFrameTransformStats (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, transformId, transform_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_data_frame' + '/' + 'transforms' + '/' + encodeURIComponent(transform_id || transformId) + '/' + '_stats' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildDataFrameGetDataFrameTransformStats diff --git a/api/api/data_frame.preview_data_frame_transform.js b/api/api/data_frame.preview_data_frame_transform.js new file mode 100644 index 000000000..c51772d8f --- /dev/null +++ b/api/api/data_frame.preview_data_frame_transform.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildDataFramePreviewDataFrameTransform (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [data_frame.preview_data_frame_transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/preview-data-frame-transform.html) request + * + * @param {object} body - The definition for the data_frame transform to preview + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function dataFramePreviewDataFrameTransform (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_data_frame' + '/' + 'transforms' + '/' + '_preview' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildDataFramePreviewDataFrameTransform diff --git a/api/api/data_frame.put_data_frame_transform.js b/api/api/data_frame.put_data_frame_transform.js new file mode 100644 index 000000000..30993de05 --- /dev/null +++ b/api/api/data_frame.put_data_frame_transform.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildDataFramePutDataFrameTransform (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [data_frame.put_data_frame_transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-data-frame-transform.html) request + * + * @param {string} transform_id - The id of the new transform. + * @param {object} body - The data frame transform definition + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function dataFramePutDataFrameTransform (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['transform_id'] == null && params['transformId'] == null) { + const err = new ConfigurationError('Missing required parameter: transform_id or transformId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, transformId, transform_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_data_frame' + '/' + 'transforms' + '/' + encodeURIComponent(transform_id || transformId) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildDataFramePutDataFrameTransform diff --git a/api/api/data_frame.start_data_frame_transform.js b/api/api/data_frame.start_data_frame_transform.js new file mode 100644 index 000000000..2bffd5d50 --- /dev/null +++ b/api/api/data_frame.start_data_frame_transform.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildDataFrameStartDataFrameTransform (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [data_frame.start_data_frame_transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/start-data-frame-transform.html) request + * + * @param {string} transform_id - The id of the transform to start + * @param {time} timeout - Controls the time to wait for the transform to start + */ + + const acceptedQuerystring = [ + 'timeout' + ] + + const snakeCase = { + + } + + return function dataFrameStartDataFrameTransform (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['transform_id'] == null && params['transformId'] == null) { + const err = new ConfigurationError('Missing required parameter: transform_id or transformId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, transformId, transform_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_data_frame' + '/' + 'transforms' + '/' + encodeURIComponent(transform_id || transformId) + '/' + '_start' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildDataFrameStartDataFrameTransform diff --git a/api/api/data_frame.stop_data_frame_transform.js b/api/api/data_frame.stop_data_frame_transform.js new file mode 100644 index 000000000..87ee0929f --- /dev/null +++ b/api/api/data_frame.stop_data_frame_transform.js @@ -0,0 +1,104 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildDataFrameStopDataFrameTransform (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [data_frame.stop_data_frame_transform](https://www.elastic.co/guide/en/elasticsearch/reference/current/stop-data-frame-transform.html) request + * + * @param {string} transform_id - The id of the transform to stop + * @param {boolean} wait_for_completion - Whether to wait for the transform to fully stop before returning or not. Default to false + * @param {time} timeout - Controls the time to wait until the transform has stopped. Default to 30 seconds + */ + + const acceptedQuerystring = [ + 'wait_for_completion', + 'timeout' + ] + + const snakeCase = { + waitForCompletion: 'wait_for_completion' + + } + + return function dataFrameStopDataFrameTransform (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['transform_id'] == null && params['transformId'] == null) { + const err = new ConfigurationError('Missing required parameter: transform_id or transformId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, transformId, transform_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_data_frame' + '/' + 'transforms' + '/' + encodeURIComponent(transform_id || transformId) + '/' + '_stop' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildDataFrameStopDataFrameTransform diff --git a/api/api/delete.js b/api/api/delete.js index 357e4411a..6bd3a00fb 100644 --- a/api/api/delete.js +++ b/api/api/delete.js @@ -24,7 +24,7 @@ function buildDelete (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [delete](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-delete.html) request * @@ -107,17 +107,17 @@ function buildDelete (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -132,36 +132,8 @@ function buildDelete (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/delete_by_query.js b/api/api/delete_by_query.js index 363dc902a..8ea54daf3 100644 --- a/api/api/delete_by_query.js +++ b/api/api/delete_by_query.js @@ -24,7 +24,7 @@ function buildDeleteByQuery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [delete_by_query](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-delete-by-query.html) request * @@ -159,17 +159,17 @@ function buildDeleteByQuery (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -188,36 +188,8 @@ function buildDeleteByQuery (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/delete_by_query_rethrottle.js b/api/api/delete_by_query_rethrottle.js new file mode 100644 index 000000000..6759b1d4a --- /dev/null +++ b/api/api/delete_by_query_rethrottle.js @@ -0,0 +1,112 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildDeleteByQueryRethrottle (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [delete_by_query_rethrottle](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html) request + * + * @param {string} task_id - The task id to rethrottle + * @param {number} requests_per_second - The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. + */ + + const acceptedQuerystring = [ + 'requests_per_second', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + + const snakeCase = { + requestsPerSecond: 'requests_per_second', + errorTrace: 'error_trace', + filterPath: 'filter_path' + } + + return function deleteByQueryRethrottle (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['task_id'] == null && params['taskId'] == null) { + const err = new ConfigurationError('Missing required parameter: task_id or taskId') + return handleError(err, callback) + } + if (params['requests_per_second'] == null && params['requestsPerSecond'] == null) { + const err = new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, taskId, task_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_delete_by_query' + '/' + encodeURIComponent(task_id || taskId) + '/' + '_rethrottle' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildDeleteByQueryRethrottle diff --git a/api/api/delete_script.js b/api/api/delete_script.js index 90c329149..05c2196ab 100644 --- a/api/api/delete_script.js +++ b/api/api/delete_script.js @@ -24,7 +24,7 @@ function buildDeleteScript (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [delete_script](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-scripting.html) request * @@ -88,17 +88,23 @@ function buildDeleteScript (opts) { return handleError(err, callback) } +<<<<<<< HEAD var warnings = null var { method, body, id, lang } = params var querystring = semicopy(params, ['method', 'body', 'id', 'lang']) +======= + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) +>>>>>>> 215cc03... Simplify API wrappers (#839) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -117,36 +123,8 @@ function buildDeleteScript (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/delete_template.js b/api/api/delete_template.js index 2a9a733f7..b9ca1f050 100644 --- a/api/api/delete_template.js +++ b/api/api/delete_template.js @@ -24,7 +24,7 @@ function buildDeleteTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [delete_template](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-template.html) request * @@ -72,17 +72,17 @@ function buildDeleteTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id } = params - var querystring = semicopy(params, ['method', 'body', 'id']) + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -97,36 +97,8 @@ function buildDeleteTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/exists.js b/api/api/exists.js index 147f6a543..cc815fd37 100644 --- a/api/api/exists.js +++ b/api/api/exists.js @@ -24,7 +24,7 @@ function buildExists (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [exists](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-get.html) request * @@ -108,17 +108,17 @@ function buildExists (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'HEAD' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -133,36 +133,8 @@ function buildExists (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/exists_source.js b/api/api/exists_source.js index 443d8f15a..9ee2ff62a 100644 --- a/api/api/exists_source.js +++ b/api/api/exists_source.js @@ -24,7 +24,7 @@ function buildExistsSource (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [exists_source](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request * @@ -114,17 +114,17 @@ function buildExistsSource (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'HEAD' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -139,36 +139,8 @@ function buildExistsSource (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/explain.js b/api/api/explain.js index 104873fcc..33b0b1343 100644 --- a/api/api/explain.js +++ b/api/api/explain.js @@ -24,7 +24,7 @@ function buildExplain (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [explain](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-explain.html) request * @@ -110,17 +110,17 @@ function buildExplain (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -135,36 +135,8 @@ function buildExplain (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/field_caps.js b/api/api/field_caps.js index e15254570..ad07735f0 100644 --- a/api/api/field_caps.js +++ b/api/api/field_caps.js @@ -24,7 +24,7 @@ function buildFieldCaps (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [field_caps](http://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-field-caps.html) request * @@ -74,17 +74,17 @@ function buildFieldCaps (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -103,36 +103,8 @@ function buildFieldCaps (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/field_stats.js b/api/api/field_stats.js index 2a1bafe27..53cdb50b7 100644 --- a/api/api/field_stats.js +++ b/api/api/field_stats.js @@ -24,7 +24,7 @@ function buildFieldStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [field_stats](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-field-stats.html) request * @@ -76,17 +76,17 @@ function buildFieldStats (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -105,36 +105,8 @@ function buildFieldStats (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/get.js b/api/api/get.js index 5eb22f1f9..666e4f226 100644 --- a/api/api/get.js +++ b/api/api/get.js @@ -24,7 +24,7 @@ function buildGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [get](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-get.html) request * @@ -108,17 +108,17 @@ function buildGet (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -133,36 +133,8 @@ function buildGet (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/get_script.js b/api/api/get_script.js index da9ae5546..811113272 100644 --- a/api/api/get_script.js +++ b/api/api/get_script.js @@ -24,7 +24,7 @@ function buildGetScript (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [get_script](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-scripting.html) request * @@ -83,17 +83,23 @@ function buildGetScript (opts) { return handleError(err, callback) } +<<<<<<< HEAD var warnings = null var { method, body, id, lang } = params var querystring = semicopy(params, ['method', 'body', 'id', 'lang']) +======= + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) +>>>>>>> 215cc03... Simplify API wrappers (#839) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -112,36 +118,8 @@ function buildGetScript (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/get_source.js b/api/api/get_source.js index 1bfba7def..02d96144f 100644 --- a/api/api/get_source.js +++ b/api/api/get_source.js @@ -24,7 +24,7 @@ function buildGetSource (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [get_source](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-get.html) request * @@ -105,17 +105,17 @@ function buildGetSource (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -130,36 +130,8 @@ function buildGetSource (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/get_template.js b/api/api/get_template.js index 9579e7c61..d3ce7929f 100644 --- a/api/api/get_template.js +++ b/api/api/get_template.js @@ -24,7 +24,7 @@ function buildGetTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [get_template](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-template.html) request * @@ -72,17 +72,17 @@ function buildGetTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id } = params - var querystring = semicopy(params, ['method', 'body', 'id']) + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -97,36 +97,8 @@ function buildGetTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/graph.explore.js b/api/api/graph.explore.js new file mode 100644 index 000000000..2f626c42b --- /dev/null +++ b/api/api/graph.explore.js @@ -0,0 +1,105 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildGraphExplore (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [graph.explore](https://www.elastic.co/guide/en/elasticsearch/reference/current/graph-explore-api.html) request + * + * @param {list} index - A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices + * @param {list} type - A comma-separated list of document types to search; leave empty to perform the operation on all types + * @param {string} routing - Specific routing value + * @param {time} timeout - Explicit operation timeout + * @param {object} body - Graph Query DSL + */ + + const acceptedQuerystring = [ + 'routing', + 'timeout' + ] + + const snakeCase = { + + } + + return function graphExplore (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((index) != null && (type) != null) { + path = '/' + encodeURIComponent(index) + '/' + encodeURIComponent(type) + '/' + '_graph' + '/' + 'explore' + } else { + path = '/' + encodeURIComponent(index) + '/' + '_graph' + '/' + 'explore' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildGraphExplore diff --git a/api/api/ilm.delete_lifecycle.js b/api/api/ilm.delete_lifecycle.js new file mode 100644 index 000000000..6ae64f5ae --- /dev/null +++ b/api/api/ilm.delete_lifecycle.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmDeleteLifecycle (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.delete_lifecycle](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-delete-lifecycle.html) request + * + * @param {string} policy - The name of the index lifecycle policy + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmDeleteLifecycle (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, policy, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ilm' + '/' + 'policy' + '/' + encodeURIComponent(policy) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmDeleteLifecycle diff --git a/api/api/ilm.explain_lifecycle.js b/api/api/ilm.explain_lifecycle.js new file mode 100644 index 000000000..7317c5af5 --- /dev/null +++ b/api/api/ilm.explain_lifecycle.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmExplainLifecycle (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.explain_lifecycle](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html) request + * + * @param {string} index - The name of the index to explain + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmExplainLifecycle (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ilm' + '/' + 'explain' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmExplainLifecycle diff --git a/api/api/ilm.get_lifecycle.js b/api/api/ilm.get_lifecycle.js new file mode 100644 index 000000000..05050040c --- /dev/null +++ b/api/api/ilm.get_lifecycle.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmGetLifecycle (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.get_lifecycle](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-lifecycle.html) request + * + * @param {string} policy - The name of the index lifecycle policy + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmGetLifecycle (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, policy, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((policy) != null) { + path = '/' + '_ilm' + '/' + 'policy' + '/' + encodeURIComponent(policy) + } else { + path = '/' + '_ilm' + '/' + 'policy' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmGetLifecycle diff --git a/api/api/ilm.get_status.js b/api/api/ilm.get_status.js new file mode 100644 index 000000000..5cbb2bc12 --- /dev/null +++ b/api/api/ilm.get_status.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmGetStatus (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.get_status](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-status.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmGetStatus (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ilm' + '/' + 'status' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmGetStatus diff --git a/api/api/ilm.move_to_step.js b/api/api/ilm.move_to_step.js new file mode 100644 index 000000000..3f699d25d --- /dev/null +++ b/api/api/ilm.move_to_step.js @@ -0,0 +1,91 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmMoveToStep (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.move_to_step](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html) request + * + * @param {string} index - The name of the index whose lifecycle step is to change + * @param {object} body - The new lifecycle step to move to + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmMoveToStep (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ilm' + '/' + 'move' + '/' + encodeURIComponent(index) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmMoveToStep diff --git a/api/api/ilm.put_lifecycle.js b/api/api/ilm.put_lifecycle.js new file mode 100644 index 000000000..8f875547a --- /dev/null +++ b/api/api/ilm.put_lifecycle.js @@ -0,0 +1,91 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmPutLifecycle (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.put_lifecycle](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-put-lifecycle.html) request + * + * @param {string} policy - The name of the index lifecycle policy + * @param {object} body - The lifecycle policy definition to register + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmPutLifecycle (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, policy, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ilm' + '/' + 'policy' + '/' + encodeURIComponent(policy) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmPutLifecycle diff --git a/api/api/ilm.remove_policy.js b/api/api/ilm.remove_policy.js new file mode 100644 index 000000000..0ad388fc0 --- /dev/null +++ b/api/api/ilm.remove_policy.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmRemovePolicy (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.remove_policy](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-remove-policy.html) request + * + * @param {string} index - The name of the index to remove policy on + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmRemovePolicy (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ilm' + '/' + 'remove' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmRemovePolicy diff --git a/api/api/ilm.retry.js b/api/api/ilm.retry.js new file mode 100644 index 000000000..30ee6a8ea --- /dev/null +++ b/api/api/ilm.retry.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmRetry (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.retry](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-retry-policy.html) request + * + * @param {string} index - The name of the indices (comma-separated) whose failed lifecycle step is to be retry + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmRetry (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_ilm' + '/' + 'retry' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmRetry diff --git a/api/api/ilm.start.js b/api/api/ilm.start.js new file mode 100644 index 000000000..2dcd08d4b --- /dev/null +++ b/api/api/ilm.start.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmStart (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.start](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-start.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmStart (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ilm' + '/' + 'start' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmStart diff --git a/api/api/ilm.stop.js b/api/api/ilm.stop.js new file mode 100644 index 000000000..d22d2491a --- /dev/null +++ b/api/api/ilm.stop.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildIlmStop (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ilm.stop](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-stop.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function ilmStop (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ilm' + '/' + 'stop' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildIlmStop diff --git a/api/api/index.js b/api/api/index.js index 663144e16..89c7b8132 100644 --- a/api/api/index.js +++ b/api/api/index.js @@ -24,7 +24,7 @@ function buildIndex (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [index](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-index_.html) request * @@ -113,17 +113,17 @@ function buildIndex (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -142,36 +142,8 @@ function buildIndex (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.analyze.js b/api/api/indices.analyze.js index 4a20415bc..d4bb9413e 100644 --- a/api/api/indices.analyze.js +++ b/api/api/indices.analyze.js @@ -24,7 +24,7 @@ function buildIndicesAnalyze (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.analyze](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-analyze.html) request * @@ -87,17 +87,17 @@ function buildIndicesAnalyze (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -116,36 +116,8 @@ function buildIndicesAnalyze (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.clear_cache.js b/api/api/indices.clear_cache.js index f825fa774..6b5a30663 100644 --- a/api/api/indices.clear_cache.js +++ b/api/api/indices.clear_cache.js @@ -24,7 +24,7 @@ function buildIndicesClearCache (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.clear_cache](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-clearcache.html) request * @@ -95,17 +95,17 @@ function buildIndicesClearCache (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -124,36 +124,8 @@ function buildIndicesClearCache (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.close.js b/api/api/indices.close.js index 3e58357fe..6b2ee97e9 100644 --- a/api/api/indices.close.js +++ b/api/api/indices.close.js @@ -24,7 +24,7 @@ function buildIndicesClose (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.close](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-open-close.html) request * @@ -86,17 +86,17 @@ function buildIndicesClose (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildIndicesClose (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.create.js b/api/api/indices.create.js index 1170ea979..6ae621c8c 100644 --- a/api/api/indices.create.js +++ b/api/api/indices.create.js @@ -24,7 +24,7 @@ function buildIndicesCreate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.create](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-create-index.html) request * @@ -80,17 +80,17 @@ function buildIndicesCreate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -105,36 +105,8 @@ function buildIndicesCreate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.delete.js b/api/api/indices.delete.js index be49c746e..b921c1ab6 100644 --- a/api/api/indices.delete.js +++ b/api/api/indices.delete.js @@ -24,7 +24,7 @@ function buildIndicesDelete (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.delete](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-delete-index.html) request * @@ -77,17 +77,17 @@ function buildIndicesDelete (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildIndicesDelete (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.delete_alias.js b/api/api/indices.delete_alias.js index 49bd23d3d..077f2972e 100644 --- a/api/api/indices.delete_alias.js +++ b/api/api/indices.delete_alias.js @@ -24,7 +24,7 @@ function buildIndicesDeleteAlias (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.delete_alias](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html) request * @@ -88,17 +88,17 @@ function buildIndicesDeleteAlias (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, name } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'name']) + var warnings = [] + var { method, body, index, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -117,36 +117,8 @@ function buildIndicesDeleteAlias (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.delete_template.js b/api/api/indices.delete_template.js index 051d6062b..3dc6602b2 100644 --- a/api/api/indices.delete_template.js +++ b/api/api/indices.delete_template.js @@ -24,7 +24,7 @@ function buildIndicesDeleteTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.delete_template](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-templates.html) request * @@ -77,17 +77,17 @@ function buildIndicesDeleteTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, name } = params - var querystring = semicopy(params, ['method', 'body', 'name']) + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildIndicesDeleteTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.exists.js b/api/api/indices.exists.js index 3baf2fa13..4f613471b 100644 --- a/api/api/indices.exists.js +++ b/api/api/indices.exists.js @@ -24,7 +24,7 @@ function buildIndicesExists (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.exists](http://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-exists.html) request * @@ -89,17 +89,17 @@ function buildIndicesExists (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'HEAD' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -114,36 +114,8 @@ function buildIndicesExists (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.exists_alias.js b/api/api/indices.exists_alias.js index 14f811ed7..45b5415c9 100644 --- a/api/api/indices.exists_alias.js +++ b/api/api/indices.exists_alias.js @@ -24,7 +24,7 @@ function buildIndicesExistsAlias (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.exists_alias](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html) request * @@ -80,17 +80,17 @@ function buildIndicesExistsAlias (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, name } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'name']) + var warnings = [] + var { method, body, index, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'HEAD' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -109,36 +109,8 @@ function buildIndicesExistsAlias (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.exists_template.js b/api/api/indices.exists_template.js index cadc5924e..43ef4ddf6 100644 --- a/api/api/indices.exists_template.js +++ b/api/api/indices.exists_template.js @@ -24,7 +24,7 @@ function buildIndicesExistsTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.exists_template](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-templates.html) request * @@ -80,17 +80,17 @@ function buildIndicesExistsTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, name } = params - var querystring = semicopy(params, ['method', 'body', 'name']) + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'HEAD' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -105,36 +105,8 @@ function buildIndicesExistsTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.exists_type.js b/api/api/indices.exists_type.js index e460e7ae0..607c01d29 100644 --- a/api/api/indices.exists_type.js +++ b/api/api/indices.exists_type.js @@ -24,7 +24,7 @@ function buildIndicesExistsType (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.exists_type](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-types-exists.html) request * @@ -94,17 +94,17 @@ function buildIndicesExistsType (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'HEAD' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -119,36 +119,8 @@ function buildIndicesExistsType (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.flush.js b/api/api/indices.flush.js index d75aeb94c..c60da2670 100644 --- a/api/api/indices.flush.js +++ b/api/api/indices.flush.js @@ -24,7 +24,7 @@ function buildIndicesFlush (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.flush](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-flush.html) request * @@ -82,17 +82,17 @@ function buildIndicesFlush (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildIndicesFlush (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.flush_synced.js b/api/api/indices.flush_synced.js index d58b9ebaa..767cfc533 100644 --- a/api/api/indices.flush_synced.js +++ b/api/api/indices.flush_synced.js @@ -24,7 +24,7 @@ function buildIndicesFlushSynced (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.flush_synced](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-synced-flush.html) request * @@ -77,17 +77,17 @@ function buildIndicesFlushSynced (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -106,36 +106,8 @@ function buildIndicesFlushSynced (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.forcemerge.js b/api/api/indices.forcemerge.js index b11fee565..09d2fea62 100644 --- a/api/api/indices.forcemerge.js +++ b/api/api/indices.forcemerge.js @@ -24,7 +24,7 @@ function buildIndicesForcemerge (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.forcemerge](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-forcemerge.html) request * @@ -91,17 +91,17 @@ function buildIndicesForcemerge (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -120,36 +120,8 @@ function buildIndicesForcemerge (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.get.js b/api/api/indices.get.js index 76b8733a2..61a9c74d8 100644 --- a/api/api/indices.get.js +++ b/api/api/indices.get.js @@ -24,7 +24,7 @@ function buildIndicesGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.get](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-get-index.html) request * @@ -96,17 +96,23 @@ function buildIndicesGet (opts) { return handleError(err, callback) } +<<<<<<< HEAD var warnings = null var { method, body, index, feature } = params var querystring = semicopy(params, ['method', 'body', 'index', 'feature']) +======= + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) +>>>>>>> 215cc03... Simplify API wrappers (#839) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -125,36 +131,8 @@ function buildIndicesGet (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.get_alias.js b/api/api/indices.get_alias.js index b66004bb9..5a2266fce 100644 --- a/api/api/indices.get_alias.js +++ b/api/api/indices.get_alias.js @@ -24,7 +24,7 @@ function buildIndicesGetAlias (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.get_alias](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html) request * @@ -80,17 +80,17 @@ function buildIndicesGetAlias (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, name } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'name']) + var warnings = [] + var { method, body, index, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -113,36 +113,8 @@ function buildIndicesGetAlias (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.get_field_mapping.js b/api/api/indices.get_field_mapping.js index 5f758a158..b7fd62a86 100644 --- a/api/api/indices.get_field_mapping.js +++ b/api/api/indices.get_field_mapping.js @@ -24,7 +24,7 @@ function buildIndicesGetFieldMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.get_field_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-get-field-mapping.html) request * @@ -88,17 +88,17 @@ function buildIndicesGetFieldMapping (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type, fields } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type', 'fields']) + var warnings = [] + var { method, body, index, type, fields, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -121,36 +121,8 @@ function buildIndicesGetFieldMapping (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.get_mapping.js b/api/api/indices.get_mapping.js index 1d2fc10d6..51ac69668 100644 --- a/api/api/indices.get_mapping.js +++ b/api/api/indices.get_mapping.js @@ -24,7 +24,7 @@ function buildIndicesGetMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.get_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-get-mapping.html) request * @@ -80,17 +80,17 @@ function buildIndicesGetMapping (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -113,36 +113,8 @@ function buildIndicesGetMapping (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.get_settings.js b/api/api/indices.get_settings.js index 0b813572c..48675cff8 100644 --- a/api/api/indices.get_settings.js +++ b/api/api/indices.get_settings.js @@ -24,7 +24,7 @@ function buildIndicesGetSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.get_settings](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-get-settings.html) request * @@ -86,17 +86,17 @@ function buildIndicesGetSettings (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, name } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'name']) + var warnings = [] + var { method, body, index, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -119,36 +119,8 @@ function buildIndicesGetSettings (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.get_template.js b/api/api/indices.get_template.js index 12b78be18..982b1c5f2 100644 --- a/api/api/indices.get_template.js +++ b/api/api/indices.get_template.js @@ -24,7 +24,7 @@ function buildIndicesGetTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.get_template](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-templates.html) request * @@ -76,17 +76,17 @@ function buildIndicesGetTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, name } = params - var querystring = semicopy(params, ['method', 'body', 'name']) + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -105,36 +105,8 @@ function buildIndicesGetTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.get_upgrade.js b/api/api/indices.get_upgrade.js index bfe74bd37..8cbda0fba 100644 --- a/api/api/indices.get_upgrade.js +++ b/api/api/indices.get_upgrade.js @@ -24,7 +24,7 @@ function buildIndicesGetUpgrade (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.get_upgrade](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-upgrade.html) request * @@ -77,17 +77,17 @@ function buildIndicesGetUpgrade (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -106,36 +106,8 @@ function buildIndicesGetUpgrade (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.open.js b/api/api/indices.open.js index 1435cbe45..8d9296843 100644 --- a/api/api/indices.open.js +++ b/api/api/indices.open.js @@ -24,7 +24,7 @@ function buildIndicesOpen (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.open](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-open-close.html) request * @@ -86,17 +86,17 @@ function buildIndicesOpen (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildIndicesOpen (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.put_alias.js b/api/api/indices.put_alias.js index b80bda3ee..87c525806 100644 --- a/api/api/indices.put_alias.js +++ b/api/api/indices.put_alias.js @@ -24,7 +24,7 @@ function buildIndicesPutAlias (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.put_alias](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html) request * @@ -85,17 +85,17 @@ function buildIndicesPutAlias (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, name } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'name']) + var warnings = [] + var { method, body, index, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -114,36 +114,8 @@ function buildIndicesPutAlias (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.put_mapping.js b/api/api/indices.put_mapping.js index 50b7ed297..b76cd6800 100644 --- a/api/api/indices.put_mapping.js +++ b/api/api/indices.put_mapping.js @@ -24,7 +24,7 @@ function buildIndicesPutMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.put_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-put-mapping.html) request * @@ -91,17 +91,17 @@ function buildIndicesPutMapping (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -128,36 +128,8 @@ function buildIndicesPutMapping (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.put_settings.js b/api/api/indices.put_settings.js index 1fd1cc1a2..d37cdcf9e 100644 --- a/api/api/indices.put_settings.js +++ b/api/api/indices.put_settings.js @@ -24,7 +24,7 @@ function buildIndicesPutSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.put_settings](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-update-settings.html) request * @@ -87,17 +87,17 @@ function buildIndicesPutSettings (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -116,36 +116,8 @@ function buildIndicesPutSettings (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.put_template.js b/api/api/indices.put_template.js index 03bac22c6..1d93eddfb 100644 --- a/api/api/indices.put_template.js +++ b/api/api/indices.put_template.js @@ -24,7 +24,7 @@ function buildIndicesPutTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.put_template](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-templates.html) request * @@ -85,17 +85,17 @@ function buildIndicesPutTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, name } = params - var querystring = semicopy(params, ['method', 'body', 'name']) + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -110,36 +110,8 @@ function buildIndicesPutTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.recovery.js b/api/api/indices.recovery.js index 4cc7fe21c..d280ea0fd 100644 --- a/api/api/indices.recovery.js +++ b/api/api/indices.recovery.js @@ -24,7 +24,7 @@ function buildIndicesRecovery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.recovery](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-recovery.html) request * @@ -73,17 +73,17 @@ function buildIndicesRecovery (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildIndicesRecovery (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.refresh.js b/api/api/indices.refresh.js index c34808a10..ef13c4422 100644 --- a/api/api/indices.refresh.js +++ b/api/api/indices.refresh.js @@ -24,7 +24,7 @@ function buildIndicesRefresh (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.refresh](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-refresh.html) request * @@ -77,17 +77,17 @@ function buildIndicesRefresh (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -106,36 +106,8 @@ function buildIndicesRefresh (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.rollover.js b/api/api/indices.rollover.js index 27b81828b..a31896691 100644 --- a/api/api/indices.rollover.js +++ b/api/api/indices.rollover.js @@ -24,7 +24,7 @@ function buildIndicesRollover (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.rollover](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-rollover-index.html) request * @@ -87,17 +87,17 @@ function buildIndicesRollover (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, alias, newIndex, new_index } = params - var querystring = semicopy(params, ['method', 'body', 'alias', 'newIndex', 'new_index']) + var warnings = [] + var { method, body, alias, newIndex, new_index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -116,36 +116,8 @@ function buildIndicesRollover (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.segments.js b/api/api/indices.segments.js index 7552e0c55..10ec685ab 100644 --- a/api/api/indices.segments.js +++ b/api/api/indices.segments.js @@ -24,7 +24,7 @@ function buildIndicesSegments (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.segments](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-segments.html) request * @@ -82,17 +82,17 @@ function buildIndicesSegments (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildIndicesSegments (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.shard_stores.js b/api/api/indices.shard_stores.js index 0ce6d2a64..80aabbf68 100644 --- a/api/api/indices.shard_stores.js +++ b/api/api/indices.shard_stores.js @@ -24,7 +24,7 @@ function buildIndicesShardStores (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.shard_stores](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-shards-stores.html) request * @@ -82,17 +82,17 @@ function buildIndicesShardStores (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildIndicesShardStores (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.shrink.js b/api/api/indices.shrink.js index 98d6ebcd1..4fb55da46 100644 --- a/api/api/indices.shrink.js +++ b/api/api/indices.shrink.js @@ -24,7 +24,7 @@ function buildIndicesShrink (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.shrink](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-shrink-index.html) request * @@ -88,17 +88,17 @@ function buildIndicesShrink (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, target } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'target']) + var warnings = [] + var { method, body, index, target, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -113,36 +113,8 @@ function buildIndicesShrink (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.stats.js b/api/api/indices.stats.js index a801d7f2d..70d1d9b64 100644 --- a/api/api/indices.stats.js +++ b/api/api/indices.stats.js @@ -24,7 +24,7 @@ function buildIndicesStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.stats](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-stats.html) request * @@ -86,17 +86,17 @@ function buildIndicesStats (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, metric } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'metric']) + var warnings = [] + var { method, body, index, metric, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -119,36 +119,8 @@ function buildIndicesStats (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.update_aliases.js b/api/api/indices.update_aliases.js index dd7bbb659..065ed7e88 100644 --- a/api/api/indices.update_aliases.js +++ b/api/api/indices.update_aliases.js @@ -24,7 +24,7 @@ function buildIndicesUpdateAliases (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.update_aliases](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-aliases.html) request * @@ -73,17 +73,17 @@ function buildIndicesUpdateAliases (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -98,36 +98,8 @@ function buildIndicesUpdateAliases (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.upgrade.js b/api/api/indices.upgrade.js index 97910c123..2129385d5 100644 --- a/api/api/indices.upgrade.js +++ b/api/api/indices.upgrade.js @@ -24,7 +24,7 @@ function buildIndicesUpgrade (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.upgrade](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-upgrade.html) request * @@ -83,17 +83,17 @@ function buildIndicesUpgrade (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -112,36 +112,8 @@ function buildIndicesUpgrade (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/indices.validate_query.js b/api/api/indices.validate_query.js index 45ee95382..9b65b0896 100644 --- a/api/api/indices.validate_query.js +++ b/api/api/indices.validate_query.js @@ -24,7 +24,7 @@ function buildIndicesValidateQuery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [indices.validate_query](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-validate.html) request * @@ -103,17 +103,17 @@ function buildIndicesValidateQuery (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -134,36 +134,8 @@ function buildIndicesValidateQuery (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/info.js b/api/api/info.js index 534d473b1..480775042 100644 --- a/api/api/info.js +++ b/api/api/info.js @@ -24,7 +24,7 @@ function buildInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [info](https://www.elastic.co/guide/) request * @@ -67,17 +67,17 @@ function buildInfo (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -92,36 +92,8 @@ function buildInfo (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/ingest.delete_pipeline.js b/api/api/ingest.delete_pipeline.js index f44e632b7..c1607f9a4 100644 --- a/api/api/ingest.delete_pipeline.js +++ b/api/api/ingest.delete_pipeline.js @@ -24,7 +24,7 @@ function buildIngestDeletePipeline (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [ingest.delete_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/5.x/ingest.html) request * @@ -77,17 +77,17 @@ function buildIngestDeletePipeline (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id } = params - var querystring = semicopy(params, ['method', 'body', 'id']) + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildIngestDeletePipeline (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/ingest.get_pipeline.js b/api/api/ingest.get_pipeline.js index 186bdc947..a9d68a0a9 100644 --- a/api/api/ingest.get_pipeline.js +++ b/api/api/ingest.get_pipeline.js @@ -24,7 +24,7 @@ function buildIngestGetPipeline (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [ingest.get_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/5.x/ingest.html) request * @@ -71,17 +71,17 @@ function buildIngestGetPipeline (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id } = params - var querystring = semicopy(params, ['method', 'body', 'id']) + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -100,36 +100,8 @@ function buildIngestGetPipeline (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/ingest.processor_grok.js b/api/api/ingest.processor_grok.js index 056843cb2..d6d23d6b9 100644 --- a/api/api/ingest.processor_grok.js +++ b/api/api/ingest.processor_grok.js @@ -24,7 +24,7 @@ function buildIngestProcessorGrok (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [ingest.processor_grok](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request * @@ -67,17 +67,17 @@ function buildIngestProcessorGrok (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -92,36 +92,8 @@ function buildIngestProcessorGrok (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/ingest.put_pipeline.js b/api/api/ingest.put_pipeline.js index 2329542f5..881c4d2f7 100644 --- a/api/api/ingest.put_pipeline.js +++ b/api/api/ingest.put_pipeline.js @@ -24,7 +24,7 @@ function buildIngestPutPipeline (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [ingest.put_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/5.x/ingest.html) request * @@ -78,17 +78,17 @@ function buildIngestPutPipeline (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id } = params - var querystring = semicopy(params, ['method', 'body', 'id']) + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -103,36 +103,8 @@ function buildIngestPutPipeline (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/ingest.simulate.js b/api/api/ingest.simulate.js index 603eaf9e5..9bbb401c8 100644 --- a/api/api/ingest.simulate.js +++ b/api/api/ingest.simulate.js @@ -24,7 +24,7 @@ function buildIngestSimulate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [ingest.simulate](https://www.elastic.co/guide/en/elasticsearch/plugins/5.x/ingest.html) request * @@ -71,17 +71,17 @@ function buildIngestSimulate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id } = params - var querystring = semicopy(params, ['method', 'body', 'id']) + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -100,36 +100,8 @@ function buildIngestSimulate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/license.delete.js b/api/api/license.delete.js new file mode 100644 index 000000000..cce9d75e5 --- /dev/null +++ b/api/api/license.delete.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildLicenseDelete (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [license.delete](https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-license.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function licenseDelete (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_license' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildLicenseDelete diff --git a/api/api/license.get.js b/api/api/license.get.js new file mode 100644 index 000000000..ae139fffd --- /dev/null +++ b/api/api/license.get.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildLicenseGet (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [license.get](https://www.elastic.co/guide/en/elasticsearch/reference/master/get-license.html) request + * + * @param {boolean} local - Return local information, do not retrieve the state from master node (default: false) + */ + + const acceptedQuerystring = [ + 'local' + ] + + const snakeCase = { + + } + + return function licenseGet (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_license' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildLicenseGet diff --git a/api/api/license.get_basic_status.js b/api/api/license.get_basic_status.js new file mode 100644 index 000000000..ec41252bf --- /dev/null +++ b/api/api/license.get_basic_status.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildLicenseGetBasicStatus (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [license.get_basic_status](https://www.elastic.co/guide/en/elasticsearch/reference/master/get-basic-status.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function licenseGetBasicStatus (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_license' + '/' + 'basic_status' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildLicenseGetBasicStatus diff --git a/api/api/license.get_trial_status.js b/api/api/license.get_trial_status.js new file mode 100644 index 000000000..af6b35917 --- /dev/null +++ b/api/api/license.get_trial_status.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildLicenseGetTrialStatus (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [license.get_trial_status](https://www.elastic.co/guide/en/elasticsearch/reference/master/get-trial-status.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function licenseGetTrialStatus (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_license' + '/' + 'trial_status' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildLicenseGetTrialStatus diff --git a/api/api/license.post.js b/api/api/license.post.js new file mode 100644 index 000000000..0c1ac7d07 --- /dev/null +++ b/api/api/license.post.js @@ -0,0 +1,91 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildLicensePost (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [license.post](https://www.elastic.co/guide/en/elasticsearch/reference/master/update-license.html) request + * + * @param {boolean} acknowledge - whether the user has acknowledged acknowledge messages (default: false) + * @param {object} body - licenses to be installed + */ + + const acceptedQuerystring = [ + 'acknowledge' + ] + + const snakeCase = { + + } + + return function licensePost (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_license' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildLicensePost diff --git a/api/api/license.post_start_basic.js b/api/api/license.post_start_basic.js new file mode 100644 index 000000000..5fa1373fb --- /dev/null +++ b/api/api/license.post_start_basic.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildLicensePostStartBasic (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [license.post_start_basic](https://www.elastic.co/guide/en/elasticsearch/reference/master/start-basic.html) request + * + * @param {boolean} acknowledge - whether the user has acknowledged acknowledge messages (default: false) + */ + + const acceptedQuerystring = [ + 'acknowledge' + ] + + const snakeCase = { + + } + + return function licensePostStartBasic (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_license' + '/' + 'start_basic' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildLicensePostStartBasic diff --git a/api/api/license.post_start_trial.js b/api/api/license.post_start_trial.js new file mode 100644 index 000000000..d68c00f90 --- /dev/null +++ b/api/api/license.post_start_trial.js @@ -0,0 +1,98 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildLicensePostStartTrial (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [license.post_start_trial](https://www.elastic.co/guide/en/elasticsearch/reference/master/start-trial.html) request + * + * @param {string} type - The type of trial license to generate (default: "trial") + * @param {boolean} acknowledge - whether the user has acknowledged acknowledge messages (default: false) + */ + + const acceptedQuerystring = [ + 'type', + 'acknowledge' + ] + + const snakeCase = { + + } + + return function licensePostStartTrial (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_license' + '/' + 'start_trial' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildLicensePostStartTrial diff --git a/api/api/mget.js b/api/api/mget.js index baef820ff..6c96dd5e1 100644 --- a/api/api/mget.js +++ b/api/api/mget.js @@ -24,7 +24,7 @@ function buildMget (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [mget](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-multi-get.html) request * @@ -95,17 +95,17 @@ function buildMget (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -126,36 +126,8 @@ function buildMget (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/migration.deprecations.js b/api/api/migration.deprecations.js new file mode 100644 index 000000000..e074c1bdb --- /dev/null +++ b/api/api/migration.deprecations.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMigrationDeprecations (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [migration.deprecations](http://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-deprecation.html) request + * + * @param {string} index - Index pattern + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function migrationDeprecations (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((index) != null) { + path = '/' + encodeURIComponent(index) + '/' + '_migration' + '/' + 'deprecations' + } else { + path = '/' + '_migration' + '/' + 'deprecations' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMigrationDeprecations diff --git a/api/api/ml.close_job.js b/api/api/ml.close_job.js new file mode 100644 index 000000000..361d14971 --- /dev/null +++ b/api/api/ml.close_job.js @@ -0,0 +1,103 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlCloseJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.close_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-close-job.html) request + * + * @param {string} job_id - The name of the job to close + * @param {boolean} allow_no_jobs - Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + * @param {boolean} force - True if the job should be forcefully closed + * @param {time} timeout - Controls the time to wait until a job has closed. Default to 30 minutes + * @param {object} body - The URL params optionally sent in the body + */ + + const acceptedQuerystring = [ + 'allow_no_jobs', + 'force', + 'timeout' + ] + + const snakeCase = { + allowNoJobs: 'allow_no_jobs' + + } + + return function mlCloseJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_close' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlCloseJob diff --git a/api/api/ml.delete_calendar.js b/api/api/ml.delete_calendar.js new file mode 100644 index 000000000..71f7505f8 --- /dev/null +++ b/api/api/ml.delete_calendar.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteCalendar (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_calendar](undefined) request + * + * @param {string} calendar_id - The ID of the calendar to delete + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlDeleteCalendar (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['calendar_id'] == null && params['calendarId'] == null) { + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, calendarId, calendar_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'calendars' + '/' + encodeURIComponent(calendar_id || calendarId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteCalendar diff --git a/api/api/ml.delete_calendar_event.js b/api/api/ml.delete_calendar_event.js new file mode 100644 index 000000000..cd4d751d3 --- /dev/null +++ b/api/api/ml.delete_calendar_event.js @@ -0,0 +1,111 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteCalendarEvent (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_calendar_event](undefined) request + * + * @param {string} calendar_id - The ID of the calendar to modify + * @param {string} event_id - The ID of the event to remove from the calendar + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlDeleteCalendarEvent (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['calendar_id'] == null && params['calendarId'] == null) { + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) + } + if (params['event_id'] == null && params['eventId'] == null) { + const err = new ConfigurationError('Missing required parameter: event_id or eventId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // check required url components + if ((params['event_id'] != null || params['eventId'] != null) && ((params['calendar_id'] == null && params['calendarId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: calendar_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, calendarId, calendar_id, eventId, event_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'calendars' + '/' + encodeURIComponent(calendar_id || calendarId) + '/' + 'events' + '/' + encodeURIComponent(event_id || eventId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteCalendarEvent diff --git a/api/api/ml.delete_calendar_job.js b/api/api/ml.delete_calendar_job.js new file mode 100644 index 000000000..19823d1af --- /dev/null +++ b/api/api/ml.delete_calendar_job.js @@ -0,0 +1,111 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteCalendarJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_calendar_job](undefined) request + * + * @param {string} calendar_id - The ID of the calendar to modify + * @param {string} job_id - The ID of the job to remove from the calendar + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlDeleteCalendarJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['calendar_id'] == null && params['calendarId'] == null) { + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) + } + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // check required url components + if ((params['job_id'] != null || params['jobId'] != null) && ((params['calendar_id'] == null && params['calendarId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: calendar_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, calendarId, calendar_id, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'calendars' + '/' + encodeURIComponent(calendar_id || calendarId) + '/' + 'jobs' + '/' + encodeURIComponent(job_id || jobId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteCalendarJob diff --git a/api/api/ml.delete_datafeed.js b/api/api/ml.delete_datafeed.js new file mode 100644 index 000000000..e245dbbb7 --- /dev/null +++ b/api/api/ml.delete_datafeed.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteDatafeed (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html) request + * + * @param {string} datafeed_id - The ID of the datafeed to delete + * @param {boolean} force - True if the datafeed should be forcefully deleted + */ + + const acceptedQuerystring = [ + 'force' + ] + + const snakeCase = { + + } + + return function mlDeleteDatafeed (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['datafeed_id'] == null && params['datafeedId'] == null) { + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, datafeedId, datafeed_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + encodeURIComponent(datafeed_id || datafeedId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteDatafeed diff --git a/api/api/ml.delete_expired_data.js b/api/api/ml.delete_expired_data.js new file mode 100644 index 000000000..c2c5edca7 --- /dev/null +++ b/api/api/ml.delete_expired_data.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteExpiredData (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_expired_data](undefined) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlDeleteExpiredData (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + '_delete_expired_data' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteExpiredData diff --git a/api/api/ml.delete_filter.js b/api/api/ml.delete_filter.js new file mode 100644 index 000000000..46ae221ab --- /dev/null +++ b/api/api/ml.delete_filter.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteFilter (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_filter](undefined) request + * + * @param {string} filter_id - The ID of the filter to delete + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlDeleteFilter (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['filter_id'] == null && params['filterId'] == null) { + const err = new ConfigurationError('Missing required parameter: filter_id or filterId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, filterId, filter_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'filters' + '/' + encodeURIComponent(filter_id || filterId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteFilter diff --git a/api/api/ml.delete_forecast.js b/api/api/ml.delete_forecast.js new file mode 100644 index 000000000..1b6616590 --- /dev/null +++ b/api/api/ml.delete_forecast.js @@ -0,0 +1,115 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteForecast (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_forecast](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html) request + * + * @param {string} job_id - The ID of the job from which to delete forecasts + * @param {string} forecast_id - The ID of the forecast to delete, can be comma delimited list. Leaving blank implies `_all` + * @param {boolean} allow_no_forecasts - Whether to ignore if `_all` matches no forecasts + * @param {time} timeout - Controls the time to wait until the forecast(s) are deleted. Default to 30 seconds + */ + + const acceptedQuerystring = [ + 'allow_no_forecasts', + 'timeout' + ] + + const snakeCase = { + allowNoForecasts: 'allow_no_forecasts' + + } + + return function mlDeleteForecast (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // check required url components + if ((params['forecast_id'] != null || params['forecastId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, forecastId, forecast_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((job_id || jobId) != null && (forecast_id || forecastId) != null) { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_forecast' + '/' + encodeURIComponent(forecast_id || forecastId) + } else { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_forecast' + } + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteForecast diff --git a/api/api/ml.delete_job.js b/api/api/ml.delete_job.js new file mode 100644 index 000000000..dae7db48c --- /dev/null +++ b/api/api/ml.delete_job.js @@ -0,0 +1,103 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html) request + * + * @param {string} job_id - The ID of the job to delete + * @param {boolean} force - True if the job should be forcefully deleted + * @param {boolean} wait_for_completion - Should this request wait until the operation has completed before returning + */ + + const acceptedQuerystring = [ + 'force', + 'wait_for_completion' + ] + + const snakeCase = { + waitForCompletion: 'wait_for_completion' + } + + return function mlDeleteJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteJob diff --git a/api/api/ml.delete_model_snapshot.js b/api/api/ml.delete_model_snapshot.js new file mode 100644 index 000000000..6f5cb1c43 --- /dev/null +++ b/api/api/ml.delete_model_snapshot.js @@ -0,0 +1,111 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlDeleteModelSnapshot (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.delete_model_snapshot](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-snapshot.html) request + * + * @param {string} job_id - The ID of the job to fetch + * @param {string} snapshot_id - The ID of the snapshot to delete + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlDeleteModelSnapshot (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params['snapshot_id'] == null && params['snapshotId'] == null) { + const err = new ConfigurationError('Missing required parameter: snapshot_id or snapshotId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // check required url components + if ((params['snapshot_id'] != null || params['snapshotId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, snapshotId, snapshot_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'model_snapshots' + '/' + encodeURIComponent(snapshot_id || snapshotId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlDeleteModelSnapshot diff --git a/api/api/ml.find_file_structure.js b/api/api/ml.find_file_structure.js new file mode 100644 index 000000000..eee5b0e56 --- /dev/null +++ b/api/api/ml.find_file_structure.js @@ -0,0 +1,128 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlFindFileStructure (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.find_file_structure](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-find-file-structure.html) request + * + * @param {int} lines_to_sample - How many lines of the file should be included in the analysis + * @param {time} timeout - Timeout after which the analysis will be aborted + * @param {string} charset - Optional parameter to specify the character set of the file + * @param {enum} format - Optional parameter to specify the high level file format + * @param {boolean} has_header_row - Optional parameter to specify whether a delimited file includes the column names in its first row + * @param {list} column_names - Optional parameter containing a comma separated list of the column names for a delimited file + * @param {string} delimiter - Optional parameter to specify the delimiter character for a delimited file - must be a single character + * @param {string} quote - Optional parameter to specify the quote character for a delimited file - must be a single character + * @param {boolean} should_trim_fields - Optional parameter to specify whether the values between delimiters in a delimited file should have whitespace trimmed from them + * @param {string} grok_pattern - Optional parameter to specify the Grok pattern that should be used to extract fields from messages in a semi-structured text file + * @param {string} timestamp_field - Optional parameter to specify the timestamp field in the file + * @param {string} timestamp_format - Optional parameter to specify the timestamp format in the file - may be either a Joda or Java time format + * @param {boolean} explain - Whether to include a commentary on how the structure was derived + * @param {object} body - The contents of the file to be analyzed + */ + + const acceptedQuerystring = [ + 'lines_to_sample', + 'timeout', + 'charset', + 'format', + 'has_header_row', + 'column_names', + 'delimiter', + 'quote', + 'should_trim_fields', + 'grok_pattern', + 'timestamp_field', + 'timestamp_format', + 'explain' + ] + + const snakeCase = { + linesToSample: 'lines_to_sample', + hasHeaderRow: 'has_header_row', + columnNames: 'column_names', + shouldTrimFields: 'should_trim_fields', + grokPattern: 'grok_pattern', + timestampField: 'timestamp_field', + timestampFormat: 'timestamp_format' + + } + + return function mlFindFileStructure (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'find_file_structure' + + // build request object + const request = { + method, + path, + bulkBody: body, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlFindFileStructure diff --git a/api/api/ml.flush_job.js b/api/api/ml.flush_job.js new file mode 100644 index 000000000..670aa49a5 --- /dev/null +++ b/api/api/ml.flush_job.js @@ -0,0 +1,108 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlFlushJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.flush_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html) request + * + * @param {string} job_id - The name of the job to flush + * @param {boolean} calc_interim - Calculates interim results for the most recent bucket or all buckets within the latency period + * @param {string} start - When used in conjunction with calc_interim, specifies the range of buckets on which to calculate interim results + * @param {string} end - When used in conjunction with calc_interim, specifies the range of buckets on which to calculate interim results + * @param {string} advance_time - Advances time to the given value generating results and updating the model for the advanced interval + * @param {string} skip_time - Skips time to the given value without generating results or updating the model for the skipped interval + * @param {object} body - Flush parameters + */ + + const acceptedQuerystring = [ + 'calc_interim', + 'start', + 'end', + 'advance_time', + 'skip_time' + ] + + const snakeCase = { + calcInterim: 'calc_interim', + advanceTime: 'advance_time', + skipTime: 'skip_time' + } + + return function mlFlushJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_flush' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlFlushJob diff --git a/api/api/ml.forecast.js b/api/api/ml.forecast.js new file mode 100644 index 000000000..ce19e9e65 --- /dev/null +++ b/api/api/ml.forecast.js @@ -0,0 +1,103 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlForecast (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.forecast](undefined) request + * + * @param {string} job_id - The ID of the job to forecast for + * @param {time} duration - The duration of the forecast + * @param {time} expires_in - The time interval after which the forecast expires. Expired forecasts will be deleted at the first opportunity. + */ + + const acceptedQuerystring = [ + 'duration', + 'expires_in' + ] + + const snakeCase = { + expiresIn: 'expires_in' + } + + return function mlForecast (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_forecast' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlForecast diff --git a/api/api/ml.get_buckets.js b/api/api/ml.get_buckets.js new file mode 100644 index 000000000..4e8a3e68d --- /dev/null +++ b/api/api/ml.get_buckets.js @@ -0,0 +1,127 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetBuckets (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_buckets](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-bucket.html) request + * + * @param {string} job_id - ID of the job to get bucket results from + * @param {string} timestamp - The timestamp of the desired single bucket result + * @param {boolean} expand - Include anomaly records + * @param {boolean} exclude_interim - Exclude interim results + * @param {int} from - skips a number of buckets + * @param {int} size - specifies a max number of buckets to get + * @param {string} start - Start time filter for buckets + * @param {string} end - End time filter for buckets + * @param {double} anomaly_score - Filter for the most anomalous buckets + * @param {string} sort - Sort buckets by a particular field + * @param {boolean} desc - Set the sort direction + * @param {object} body - Bucket selection details if not provided in URI + */ + + const acceptedQuerystring = [ + 'expand', + 'exclude_interim', + 'from', + 'size', + 'start', + 'end', + 'anomaly_score', + 'sort', + 'desc' + ] + + const snakeCase = { + excludeInterim: 'exclude_interim', + anomalyScore: 'anomaly_score' + + } + + return function mlGetBuckets (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + + // check required url components + if (params['timestamp'] != null && ((params['job_id'] == null && params['jobId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, timestamp, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((job_id || jobId) != null && (timestamp) != null) { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'results' + '/' + 'buckets' + '/' + encodeURIComponent(timestamp) + } else { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'results' + '/' + 'buckets' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetBuckets diff --git a/api/api/ml.get_calendar_events.js b/api/api/ml.get_calendar_events.js new file mode 100644 index 000000000..45752948d --- /dev/null +++ b/api/api/ml.get_calendar_events.js @@ -0,0 +1,110 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetCalendarEvents (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_calendar_events](undefined) request + * + * @param {string} calendar_id - The ID of the calendar containing the events + * @param {string} job_id - Get events for the job. When this option is used calendar_id must be '_all' + * @param {string} start - Get events after this time + * @param {date} end - Get events before this time + * @param {int} from - Skips a number of events + * @param {int} size - Specifies a max number of events to get + */ + + const acceptedQuerystring = [ + 'job_id', + 'start', + 'end', + 'from', + 'size' + ] + + const snakeCase = { + jobId: 'job_id' + + } + + return function mlGetCalendarEvents (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['calendar_id'] == null && params['calendarId'] == null) { + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, calendarId, calendar_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'calendars' + '/' + encodeURIComponent(calendar_id || calendarId) + '/' + 'events' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetCalendarEvents diff --git a/api/api/ml.get_calendars.js b/api/api/ml.get_calendars.js new file mode 100644 index 000000000..549f5530f --- /dev/null +++ b/api/api/ml.get_calendars.js @@ -0,0 +1,98 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetCalendars (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_calendars](undefined) request + * + * @param {string} calendar_id - The ID of the calendar to fetch + * @param {int} from - skips a number of calendars + * @param {int} size - specifies a max number of calendars to get + * @param {object} body - The from and size parameters optionally sent in the body + */ + + const acceptedQuerystring = [ + 'from', + 'size' + ] + + const snakeCase = { + + } + + return function mlGetCalendars (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, calendarId, calendar_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((calendar_id || calendarId) != null) { + path = '/' + '_ml' + '/' + 'calendars' + '/' + encodeURIComponent(calendar_id || calendarId) + } else { + path = '/' + '_ml' + '/' + 'calendars' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetCalendars diff --git a/api/api/ml.get_categories.js b/api/api/ml.get_categories.js new file mode 100644 index 000000000..381ebb54c --- /dev/null +++ b/api/api/ml.get_categories.js @@ -0,0 +1,105 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetCategories (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_categories](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-category.html) request + * + * @param {string} job_id - The name of the job + * @param {long} category_id - The identifier of the category definition of interest + * @param {int} from - skips a number of categories + * @param {int} size - specifies a max number of categories to get + * @param {object} body - Category selection details if not provided in URI + */ + + const acceptedQuerystring = [ + 'from', + 'size' + ] + + const snakeCase = { + + } + + return function mlGetCategories (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, categoryId, category_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((job_id || jobId) != null && (category_id || categoryId) != null) { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'results' + '/' + 'categories' + '/' + encodeURIComponent(category_id || categoryId) + } else { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'results' + '/' + 'categories' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetCategories diff --git a/api/api/ml.get_datafeed_stats.js b/api/api/ml.get_datafeed_stats.js new file mode 100644 index 000000000..4f042ce05 --- /dev/null +++ b/api/api/ml.get_datafeed_stats.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetDatafeedStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_datafeed_stats](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed-stats.html) request + * + * @param {string} datafeed_id - The ID of the datafeeds stats to fetch + * @param {boolean} allow_no_datafeeds - Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) + */ + + const acceptedQuerystring = [ + 'allow_no_datafeeds' + ] + + const snakeCase = { + allowNoDatafeeds: 'allow_no_datafeeds' + } + + return function mlGetDatafeedStats (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, datafeedId, datafeed_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((datafeed_id || datafeedId) != null) { + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + encodeURIComponent(datafeed_id || datafeedId) + '/' + '_stats' + } else { + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + '_stats' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetDatafeedStats diff --git a/api/api/ml.get_datafeeds.js b/api/api/ml.get_datafeeds.js new file mode 100644 index 000000000..709418c6a --- /dev/null +++ b/api/api/ml.get_datafeeds.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetDatafeeds (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_datafeeds](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed.html) request + * + * @param {string} datafeed_id - The ID of the datafeeds to fetch + * @param {boolean} allow_no_datafeeds - Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) + */ + + const acceptedQuerystring = [ + 'allow_no_datafeeds' + ] + + const snakeCase = { + allowNoDatafeeds: 'allow_no_datafeeds' + } + + return function mlGetDatafeeds (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, datafeedId, datafeed_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((datafeed_id || datafeedId) != null) { + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + encodeURIComponent(datafeed_id || datafeedId) + } else { + path = '/' + '_ml' + '/' + 'datafeeds' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetDatafeeds diff --git a/api/api/ml.get_filters.js b/api/api/ml.get_filters.js new file mode 100644 index 000000000..bac797feb --- /dev/null +++ b/api/api/ml.get_filters.js @@ -0,0 +1,103 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetFilters (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_filters](undefined) request + * + * @param {string} filter_id - The ID of the filter to fetch + * @param {int} from - skips a number of filters + * @param {int} size - specifies a max number of filters to get + */ + + const acceptedQuerystring = [ + 'from', + 'size' + ] + + const snakeCase = { + + } + + return function mlGetFilters (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, filterId, filter_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((filter_id || filterId) != null) { + path = '/' + '_ml' + '/' + 'filters' + '/' + encodeURIComponent(filter_id || filterId) + } else { + path = '/' + '_ml' + '/' + 'filters' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetFilters diff --git a/api/api/ml.get_influencers.js b/api/api/ml.get_influencers.js new file mode 100644 index 000000000..e128965d1 --- /dev/null +++ b/api/api/ml.get_influencers.js @@ -0,0 +1,114 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetInfluencers (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_influencers](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-influencer.html) request + * + * @param {string} job_id - + * @param {boolean} exclude_interim - Exclude interim results + * @param {int} from - skips a number of influencers + * @param {int} size - specifies a max number of influencers to get + * @param {string} start - start timestamp for the requested influencers + * @param {string} end - end timestamp for the requested influencers + * @param {double} influencer_score - influencer score threshold for the requested influencers + * @param {string} sort - sort field for the requested influencers + * @param {boolean} desc - whether the results should be sorted in decending order + * @param {object} body - Influencer selection criteria + */ + + const acceptedQuerystring = [ + 'exclude_interim', + 'from', + 'size', + 'start', + 'end', + 'influencer_score', + 'sort', + 'desc' + ] + + const snakeCase = { + excludeInterim: 'exclude_interim', + influencerScore: 'influencer_score' + + } + + return function mlGetInfluencers (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'results' + '/' + 'influencers' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetInfluencers diff --git a/api/api/ml.get_job_stats.js b/api/api/ml.get_job_stats.js new file mode 100644 index 000000000..af2096023 --- /dev/null +++ b/api/api/ml.get_job_stats.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetJobStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_job_stats](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html) request + * + * @param {string} job_id - The ID of the jobs stats to fetch + * @param {boolean} allow_no_jobs - Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + */ + + const acceptedQuerystring = [ + 'allow_no_jobs' + ] + + const snakeCase = { + allowNoJobs: 'allow_no_jobs' + } + + return function mlGetJobStats (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((job_id || jobId) != null) { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_stats' + } else { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + '_stats' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetJobStats diff --git a/api/api/ml.get_jobs.js b/api/api/ml.get_jobs.js new file mode 100644 index 000000000..a61691dff --- /dev/null +++ b/api/api/ml.get_jobs.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetJobs (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_jobs](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job.html) request + * + * @param {string} job_id - The ID of the jobs to fetch + * @param {boolean} allow_no_jobs - Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + */ + + const acceptedQuerystring = [ + 'allow_no_jobs' + ] + + const snakeCase = { + allowNoJobs: 'allow_no_jobs' + } + + return function mlGetJobs (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((job_id || jobId) != null) { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + } else { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetJobs diff --git a/api/api/ml.get_model_snapshots.js b/api/api/ml.get_model_snapshots.js new file mode 100644 index 000000000..efc1b770c --- /dev/null +++ b/api/api/ml.get_model_snapshots.js @@ -0,0 +1,119 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetModelSnapshots (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_model_snapshots](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-snapshot.html) request + * + * @param {string} job_id - The ID of the job to fetch + * @param {string} snapshot_id - The ID of the snapshot to fetch + * @param {int} from - Skips a number of documents + * @param {int} size - The default number of documents returned in queries as a string. + * @param {date} start - The filter 'start' query parameter + * @param {date} end - The filter 'end' query parameter + * @param {string} sort - Name of the field to sort on + * @param {boolean} desc - True if the results should be sorted in descending order + * @param {object} body - Model snapshot selection criteria + */ + + const acceptedQuerystring = [ + 'from', + 'size', + 'start', + 'end', + 'sort', + 'desc' + ] + + const snakeCase = { + + } + + return function mlGetModelSnapshots (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + + // check required url components + if ((params['snapshot_id'] != null || params['snapshotId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, snapshotId, snapshot_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((job_id || jobId) != null && (snapshot_id || snapshotId) != null) { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'model_snapshots' + '/' + encodeURIComponent(snapshot_id || snapshotId) + } else { + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'model_snapshots' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetModelSnapshots diff --git a/api/api/ml.get_overall_buckets.js b/api/api/ml.get_overall_buckets.js new file mode 100644 index 000000000..03798dbe4 --- /dev/null +++ b/api/api/ml.get_overall_buckets.js @@ -0,0 +1,114 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetOverallBuckets (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_overall_buckets](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-overall-buckets.html) request + * + * @param {string} job_id - The job IDs for which to calculate overall bucket results + * @param {int} top_n - The number of top job bucket scores to be used in the overall_score calculation + * @param {string} bucket_span - The span of the overall buckets. Defaults to the longest job bucket_span + * @param {double} overall_score - Returns overall buckets with overall scores higher than this value + * @param {boolean} exclude_interim - If true overall buckets that include interim buckets will be excluded + * @param {string} start - Returns overall buckets with timestamps after this time + * @param {string} end - Returns overall buckets with timestamps earlier than this time + * @param {boolean} allow_no_jobs - Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) + * @param {object} body - Overall bucket selection details if not provided in URI + */ + + const acceptedQuerystring = [ + 'top_n', + 'bucket_span', + 'overall_score', + 'exclude_interim', + 'start', + 'end', + 'allow_no_jobs' + ] + + const snakeCase = { + topN: 'top_n', + bucketSpan: 'bucket_span', + overallScore: 'overall_score', + excludeInterim: 'exclude_interim', + allowNoJobs: 'allow_no_jobs' + } + + return function mlGetOverallBuckets (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'results' + '/' + 'overall_buckets' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetOverallBuckets diff --git a/api/api/ml.get_records.js b/api/api/ml.get_records.js new file mode 100644 index 000000000..00cdbf7ec --- /dev/null +++ b/api/api/ml.get_records.js @@ -0,0 +1,114 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlGetRecords (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.get_records](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-record.html) request + * + * @param {string} job_id - + * @param {boolean} exclude_interim - Exclude interim results + * @param {int} from - skips a number of records + * @param {int} size - specifies a max number of records to get + * @param {string} start - Start time filter for records + * @param {string} end - End time filter for records + * @param {double} record_score - + * @param {string} sort - Sort records by a particular field + * @param {boolean} desc - Set the sort direction + * @param {object} body - Record selection criteria + */ + + const acceptedQuerystring = [ + 'exclude_interim', + 'from', + 'size', + 'start', + 'end', + 'record_score', + 'sort', + 'desc' + ] + + const snakeCase = { + excludeInterim: 'exclude_interim', + recordScore: 'record_score' + + } + + return function mlGetRecords (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'results' + '/' + 'records' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlGetRecords diff --git a/api/api/ml.info.js b/api/api/ml.info.js new file mode 100644 index 000000000..f21bbc95d --- /dev/null +++ b/api/api/ml.info.js @@ -0,0 +1,89 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlInfo (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.info](undefined) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlInfo (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'info' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlInfo diff --git a/api/api/ml.open_job.js b/api/api/ml.open_job.js new file mode 100644 index 000000000..a5bb89244 --- /dev/null +++ b/api/api/ml.open_job.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlOpenJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.open_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html) request + * + * @param {string} job_id - The ID of the job to open + * @param {boolean} ignore_downtime - Controls if gaps in data are treated as anomalous or as a maintenance window after a job re-start + * @param {time} timeout - Controls the time to wait until a job has opened. Default to 30 minutes + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlOpenJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ignoreDowntime, ignore_downtime, timeout, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_open' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlOpenJob diff --git a/api/api/ml.post_calendar_events.js b/api/api/ml.post_calendar_events.js new file mode 100644 index 000000000..17112d594 --- /dev/null +++ b/api/api/ml.post_calendar_events.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlPostCalendarEvents (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.post_calendar_events](undefined) request + * + * @param {string} calendar_id - The ID of the calendar to modify + * @param {object} body - A list of events + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlPostCalendarEvents (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['calendar_id'] == null && params['calendarId'] == null) { + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, calendarId, calendar_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'calendars' + '/' + encodeURIComponent(calendar_id || calendarId) + '/' + 'events' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlPostCalendarEvents diff --git a/api/api/ml.post_data.js b/api/api/ml.post_data.js new file mode 100644 index 000000000..54d5dba4d --- /dev/null +++ b/api/api/ml.post_data.js @@ -0,0 +1,105 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlPostData (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.post_data](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-post-data.html) request + * + * @param {string} job_id - The name of the job receiving the data + * @param {string} reset_start - Optional parameter to specify the start of the bucket resetting range + * @param {string} reset_end - Optional parameter to specify the end of the bucket resetting range + * @param {object} body - The data to process + */ + + const acceptedQuerystring = [ + 'reset_start', + 'reset_end' + ] + + const snakeCase = { + resetStart: 'reset_start', + resetEnd: 'reset_end' + } + + return function mlPostData (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_data' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlPostData diff --git a/api/api/ml.preview_datafeed.js b/api/api/ml.preview_datafeed.js new file mode 100644 index 000000000..e4e64c0f6 --- /dev/null +++ b/api/api/ml.preview_datafeed.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlPreviewDatafeed (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.preview_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-preview-datafeed.html) request + * + * @param {string} datafeed_id - The ID of the datafeed to preview + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlPreviewDatafeed (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['datafeed_id'] == null && params['datafeedId'] == null) { + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, datafeedId, datafeed_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + encodeURIComponent(datafeed_id || datafeedId) + '/' + '_preview' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlPreviewDatafeed diff --git a/api/api/ml.put_calendar.js b/api/api/ml.put_calendar.js new file mode 100644 index 000000000..f3bf2a1a6 --- /dev/null +++ b/api/api/ml.put_calendar.js @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlPutCalendar (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.put_calendar](undefined) request + * + * @param {string} calendar_id - The ID of the calendar to create + * @param {object} body - The calendar details + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlPutCalendar (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['calendar_id'] == null && params['calendarId'] == null) { + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, calendarId, calendar_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'calendars' + '/' + encodeURIComponent(calendar_id || calendarId) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlPutCalendar diff --git a/api/api/ml.put_calendar_job.js b/api/api/ml.put_calendar_job.js new file mode 100644 index 000000000..87fecf728 --- /dev/null +++ b/api/api/ml.put_calendar_job.js @@ -0,0 +1,111 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlPutCalendarJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.put_calendar_job](undefined) request + * + * @param {string} calendar_id - The ID of the calendar to modify + * @param {string} job_id - The ID of the job to add to the calendar + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlPutCalendarJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['calendar_id'] == null && params['calendarId'] == null) { + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) + } + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // check required url components + if ((params['job_id'] != null || params['jobId'] != null) && ((params['calendar_id'] == null && params['calendarId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: calendar_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, calendarId, calendar_id, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'calendars' + '/' + encodeURIComponent(calendar_id || calendarId) + '/' + 'jobs' + '/' + encodeURIComponent(job_id || jobId) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlPutCalendarJob diff --git a/api/api/ml.put_datafeed.js b/api/api/ml.put_datafeed.js new file mode 100644 index 000000000..14745042c --- /dev/null +++ b/api/api/ml.put_datafeed.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlPutDatafeed (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.put_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-datafeed.html) request + * + * @param {string} datafeed_id - The ID of the datafeed to create + * @param {object} body - The datafeed config + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlPutDatafeed (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['datafeed_id'] == null && params['datafeedId'] == null) { + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, datafeedId, datafeed_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + encodeURIComponent(datafeed_id || datafeedId) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlPutDatafeed diff --git a/api/api/ml.put_filter.js b/api/api/ml.put_filter.js new file mode 100644 index 000000000..3ce82f6b8 --- /dev/null +++ b/api/api/ml.put_filter.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlPutFilter (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.put_filter](undefined) request + * + * @param {string} filter_id - The ID of the filter to create + * @param {object} body - The filter details + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlPutFilter (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['filter_id'] == null && params['filterId'] == null) { + const err = new ConfigurationError('Missing required parameter: filter_id or filterId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, filterId, filter_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'filters' + '/' + encodeURIComponent(filter_id || filterId) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlPutFilter diff --git a/api/api/ml.put_job.js b/api/api/ml.put_job.js new file mode 100644 index 000000000..45ce0d481 --- /dev/null +++ b/api/api/ml.put_job.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlPutJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.put_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-job.html) request + * + * @param {string} job_id - The ID of the job to create + * @param {object} body - The job + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlPutJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlPutJob diff --git a/api/api/ml.revert_model_snapshot.js b/api/api/ml.revert_model_snapshot.js new file mode 100644 index 000000000..9b9f7b3d4 --- /dev/null +++ b/api/api/ml.revert_model_snapshot.js @@ -0,0 +1,109 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlRevertModelSnapshot (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.revert_model_snapshot](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-revert-snapshot.html) request + * + * @param {string} job_id - The ID of the job to fetch + * @param {string} snapshot_id - The ID of the snapshot to revert to + * @param {boolean} delete_intervening_results - Should we reset the results back to the time of the snapshot? + * @param {object} body - Reversion options + */ + + const acceptedQuerystring = [ + 'delete_intervening_results' + ] + + const snakeCase = { + deleteInterveningResults: 'delete_intervening_results' + } + + return function mlRevertModelSnapshot (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params['snapshot_id'] == null && params['snapshotId'] == null) { + const err = new ConfigurationError('Missing required parameter: snapshot_id or snapshotId') + return handleError(err, callback) + } + + // check required url components + if ((params['snapshot_id'] != null || params['snapshotId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, snapshotId, snapshot_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'model_snapshots' + '/' + encodeURIComponent(snapshot_id || snapshotId) + '/' + '_revert' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlRevertModelSnapshot diff --git a/api/api/ml.set_upgrade_mode.js b/api/api/ml.set_upgrade_mode.js new file mode 100644 index 000000000..cae1b7cbf --- /dev/null +++ b/api/api/ml.set_upgrade_mode.js @@ -0,0 +1,98 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlSetUpgradeMode (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.set_upgrade_mode](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-set-upgrade-mode.html) request + * + * @param {boolean} enabled - Whether to enable upgrade_mode ML setting or not. Defaults to false. + * @param {time} timeout - Controls the time to wait before action times out. Defaults to 30 seconds + */ + + const acceptedQuerystring = [ + 'enabled', + 'timeout' + ] + + const snakeCase = { + + } + + return function mlSetUpgradeMode (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'set_upgrade_mode' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlSetUpgradeMode diff --git a/api/api/ml.start_datafeed.js b/api/api/ml.start_datafeed.js new file mode 100644 index 000000000..ade441af4 --- /dev/null +++ b/api/api/ml.start_datafeed.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlStartDatafeed (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.start_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-start-datafeed.html) request + * + * @param {string} datafeed_id - The ID of the datafeed to start + * @param {string} start - The start time from where the datafeed should begin + * @param {string} end - The end time when the datafeed should stop. When not set, the datafeed continues in real time + * @param {time} timeout - Controls the time to wait until a datafeed has started. Default to 20 seconds + * @param {object} body - The start datafeed parameters + */ + + const acceptedQuerystring = [ + 'start', + 'end', + 'timeout' + ] + + const snakeCase = { + + } + + return function mlStartDatafeed (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['datafeed_id'] == null && params['datafeedId'] == null) { + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, datafeedId, datafeed_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + encodeURIComponent(datafeed_id || datafeedId) + '/' + '_start' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlStartDatafeed diff --git a/api/api/ml.stop_datafeed.js b/api/api/ml.stop_datafeed.js new file mode 100644 index 000000000..61ce3876d --- /dev/null +++ b/api/api/ml.stop_datafeed.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlStopDatafeed (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.stop_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-stop-datafeed.html) request + * + * @param {string} datafeed_id - The ID of the datafeed to stop + * @param {boolean} allow_no_datafeeds - Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) + * @param {boolean} force - True if the datafeed should be forcefully stopped. + * @param {time} timeout - Controls the time to wait until a datafeed has stopped. Default to 20 seconds + */ + + const acceptedQuerystring = [ + 'allow_no_datafeeds', + 'force', + 'timeout' + ] + + const snakeCase = { + allowNoDatafeeds: 'allow_no_datafeeds' + + } + + return function mlStopDatafeed (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['datafeed_id'] == null && params['datafeedId'] == null) { + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, datafeedId, datafeed_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + encodeURIComponent(datafeed_id || datafeedId) + '/' + '_stop' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlStopDatafeed diff --git a/api/api/ml.update_datafeed.js b/api/api/ml.update_datafeed.js new file mode 100644 index 000000000..492310dfa --- /dev/null +++ b/api/api/ml.update_datafeed.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlUpdateDatafeed (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.update_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-datafeed.html) request + * + * @param {string} datafeed_id - The ID of the datafeed to update + * @param {object} body - The datafeed update settings + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlUpdateDatafeed (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['datafeed_id'] == null && params['datafeedId'] == null) { + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, datafeedId, datafeed_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'datafeeds' + '/' + encodeURIComponent(datafeed_id || datafeedId) + '/' + '_update' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlUpdateDatafeed diff --git a/api/api/ml.update_filter.js b/api/api/ml.update_filter.js new file mode 100644 index 000000000..03e03b014 --- /dev/null +++ b/api/api/ml.update_filter.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlUpdateFilter (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.update_filter](undefined) request + * + * @param {string} filter_id - The ID of the filter to update + * @param {object} body - The filter update + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlUpdateFilter (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['filter_id'] == null && params['filterId'] == null) { + const err = new ConfigurationError('Missing required parameter: filter_id or filterId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, filterId, filter_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'filters' + '/' + encodeURIComponent(filter_id || filterId) + '/' + '_update' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlUpdateFilter diff --git a/api/api/ml.update_job.js b/api/api/ml.update_job.js new file mode 100644 index 000000000..d51325d13 --- /dev/null +++ b/api/api/ml.update_job.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlUpdateJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.update_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-job.html) request + * + * @param {string} job_id - The ID of the job to create + * @param {object} body - The job update settings + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlUpdateJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + '_update' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlUpdateJob diff --git a/api/api/ml.update_model_snapshot.js b/api/api/ml.update_model_snapshot.js new file mode 100644 index 000000000..117cb7fb0 --- /dev/null +++ b/api/api/ml.update_model_snapshot.js @@ -0,0 +1,112 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlUpdateModelSnapshot (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.update_model_snapshot](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-snapshot.html) request + * + * @param {string} job_id - The ID of the job to fetch + * @param {string} snapshot_id - The ID of the snapshot to update + * @param {object} body - The model snapshot properties to update + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlUpdateModelSnapshot (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['job_id'] == null && params['jobId'] == null) { + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) + } + if (params['snapshot_id'] == null && params['snapshotId'] == null) { + const err = new ConfigurationError('Missing required parameter: snapshot_id or snapshotId') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // check required url components + if ((params['snapshot_id'] != null || params['snapshotId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, jobId, job_id, snapshotId, snapshot_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + encodeURIComponent(job_id || jobId) + '/' + 'model_snapshots' + '/' + encodeURIComponent(snapshot_id || snapshotId) + '/' + '_update' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlUpdateModelSnapshot diff --git a/api/api/ml.validate.js b/api/api/ml.validate.js new file mode 100644 index 000000000..3f3ca43f4 --- /dev/null +++ b/api/api/ml.validate.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlValidate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.validate](undefined) request + * + * @param {object} body - The job config + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlValidate (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + '_validate' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlValidate diff --git a/api/api/ml.validate_detector.js b/api/api/ml.validate_detector.js new file mode 100644 index 000000000..8dcea86d3 --- /dev/null +++ b/api/api/ml.validate_detector.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMlValidateDetector (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ml.validate_detector](undefined) request + * + * @param {object} body - The detector + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function mlValidateDetector (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ml' + '/' + 'anomaly_detectors' + '/' + '_validate' + '/' + 'detector' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMlValidateDetector diff --git a/api/api/monitoring.bulk.js b/api/api/monitoring.bulk.js new file mode 100644 index 000000000..872e48e1d --- /dev/null +++ b/api/api/monitoring.bulk.js @@ -0,0 +1,108 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildMonitoringBulk (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [monitoring.bulk](https://www.elastic.co/guide/en/elasticsearch/reference/master/es-monitoring.html) request + * + * @param {string} type - Default document type for items which don't provide one + * @param {string} system_id - Identifier of the monitored system + * @param {string} system_api_version - API Version of the monitored system + * @param {string} interval - Collection interval (e.g., '10s' or '10000ms') of the payload + * @param {object} body - The operation definition and data (action-data pairs), separated by newlines + */ + + const acceptedQuerystring = [ + 'system_id', + 'system_api_version', + 'interval' + ] + + const snakeCase = { + systemId: 'system_id', + systemApiVersion: 'system_api_version' + + } + + return function monitoringBulk (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((type) != null) { + path = '/' + '_monitoring' + '/' + encodeURIComponent(type) + '/' + 'bulk' + } else { + path = '/' + '_monitoring' + '/' + 'bulk' + } + + // build request object + const request = { + method, + path, + bulkBody: body, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildMonitoringBulk diff --git a/api/api/mpercolate.js b/api/api/mpercolate.js index 191de1c96..32bfa9922 100644 --- a/api/api/mpercolate.js +++ b/api/api/mpercolate.js @@ -24,7 +24,7 @@ function buildMpercolate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [mpercolate](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-percolate.html) request * @@ -85,17 +85,23 @@ function buildMpercolate (opts) { return handleError(err, callback) } +<<<<<<< HEAD:api/api/mpercolate.js var warnings = null var { method, body, index, type } = params var querystring = semicopy(params, ['method', 'body', 'index', 'type']) +======= + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) +>>>>>>> 215cc03... Simplify API wrappers (#839):api/api/indices.unfreeze.js if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -116,36 +122,8 @@ function buildMpercolate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/msearch.js b/api/api/msearch.js index 46aa3fafb..8072f8a5a 100644 --- a/api/api/msearch.js +++ b/api/api/msearch.js @@ -24,7 +24,7 @@ function buildMsearch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [msearch](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-multi-search.html) request * @@ -88,17 +88,17 @@ function buildMsearch (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -119,36 +119,8 @@ function buildMsearch (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/msearch_template.js b/api/api/msearch_template.js index 6ff1a174c..af2b9f5b0 100644 --- a/api/api/msearch_template.js +++ b/api/api/msearch_template.js @@ -24,7 +24,7 @@ function buildMsearchTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [msearch_template](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) request * @@ -85,17 +85,17 @@ function buildMsearchTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -116,36 +116,8 @@ function buildMsearchTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/mtermvectors.js b/api/api/mtermvectors.js index 3095d391c..3d30cccb7 100644 --- a/api/api/mtermvectors.js +++ b/api/api/mtermvectors.js @@ -24,7 +24,7 @@ function buildMtermvectors (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [mtermvectors](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-multi-termvectors.html) request * @@ -99,17 +99,17 @@ function buildMtermvectors (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -130,36 +130,8 @@ function buildMtermvectors (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/nodes.hot_threads.js b/api/api/nodes.hot_threads.js index ea9a349df..023de6df5 100644 --- a/api/api/nodes.hot_threads.js +++ b/api/api/nodes.hot_threads.js @@ -24,7 +24,7 @@ function buildNodesHotThreads (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [nodes.hot_threads](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-nodes-hot-threads.html) request * @@ -81,17 +81,17 @@ function buildNodesHotThreads (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, nodeId, node_id } = params - var querystring = semicopy(params, ['method', 'body', 'nodeId', 'node_id']) + var warnings = [] + var { method, body, nodeId, node_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -116,36 +116,8 @@ function buildNodesHotThreads (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/nodes.info.js b/api/api/nodes.info.js index 848bec235..7db4dd8d4 100644 --- a/api/api/nodes.info.js +++ b/api/api/nodes.info.js @@ -24,7 +24,7 @@ function buildNodesInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [nodes.info](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-nodes-info.html) request * @@ -74,17 +74,17 @@ function buildNodesInfo (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, nodeId, node_id, metric } = params - var querystring = semicopy(params, ['method', 'body', 'nodeId', 'node_id', 'metric']) + var warnings = [] + var { method, body, nodeId, node_id, metric, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -107,36 +107,8 @@ function buildNodesInfo (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/nodes.reload_secure_settings.js b/api/api/nodes.reload_secure_settings.js new file mode 100644 index 000000000..948910a44 --- /dev/null +++ b/api/api/nodes.reload_secure_settings.js @@ -0,0 +1,107 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildNodesReloadSecureSettings (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [nodes.reload_secure_settings](https://www.elastic.co/guide/en/elasticsearch/reference/master/secure-settings.html#reloadable-secure-settings) request + * + * @param {list} node_id - A comma-separated list of node IDs to span the reload/reinit call. Should stay empty because reloading usually involves all cluster nodes. + * @param {time} timeout - Explicit operation timeout + */ + + const acceptedQuerystring = [ + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + + const snakeCase = { + errorTrace: 'error_trace', + filterPath: 'filter_path' + } + + return function nodesReloadSecureSettings (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, nodeId, node_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((node_id || nodeId) != null) { + path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'reload_secure_settings' + } else { + path = '/' + '_nodes' + '/' + 'reload_secure_settings' + } + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildNodesReloadSecureSettings diff --git a/api/api/nodes.stats.js b/api/api/nodes.stats.js index c0bc77f79..635b96b47 100644 --- a/api/api/nodes.stats.js +++ b/api/api/nodes.stats.js @@ -24,7 +24,7 @@ function buildNodesStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [nodes.stats](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/cluster-nodes-stats.html) request * @@ -89,17 +89,17 @@ function buildNodesStats (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, metric, indexMetric, index_metric, nodeId, node_id } = params - var querystring = semicopy(params, ['method', 'body', 'metric', 'indexMetric', 'index_metric', 'nodeId', 'node_id']) + var warnings = [] + var { method, body, metric, indexMetric, index_metric, nodeId, node_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -126,36 +126,8 @@ function buildNodesStats (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/nodes.usage.js b/api/api/nodes.usage.js new file mode 100644 index 000000000..159b09f7c --- /dev/null +++ b/api/api/nodes.usage.js @@ -0,0 +1,112 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildNodesUsage (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [nodes.usage](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-usage.html) request + * + * @param {list} metric - Limit the information returned to the specified metrics + * @param {list} node_id - A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes + * @param {time} timeout - Explicit operation timeout + */ + + const acceptedQuerystring = [ + 'timeout', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + + const snakeCase = { + errorTrace: 'error_trace', + filterPath: 'filter_path' + } + + return function nodesUsage (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, metric, nodeId, node_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((node_id || nodeId) != null && (metric) != null) { + path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'usage' + '/' + encodeURIComponent(metric) + } else if ((node_id || nodeId) != null) { + path = '/' + '_nodes' + '/' + encodeURIComponent(node_id || nodeId) + '/' + 'usage' + } else if ((metric) != null) { + path = '/' + '_nodes' + '/' + 'usage' + '/' + encodeURIComponent(metric) + } else { + path = '/' + '_nodes' + '/' + 'usage' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildNodesUsage diff --git a/api/api/ping.js b/api/api/ping.js index a3afdfe7b..f20960304 100644 --- a/api/api/ping.js +++ b/api/api/ping.js @@ -24,7 +24,7 @@ function buildPing (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [ping](https://www.elastic.co/guide/) request * @@ -67,17 +67,17 @@ function buildPing (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'HEAD' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -92,36 +92,8 @@ function buildPing (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/put_script.js b/api/api/put_script.js index c59742229..8469e8833 100644 --- a/api/api/put_script.js +++ b/api/api/put_script.js @@ -24,7 +24,7 @@ function buildPutScript (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [put_script](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-scripting.html) request * @@ -89,17 +89,23 @@ function buildPutScript (opts) { return handleError(err, callback) } +<<<<<<< HEAD var warnings = null var { method, body, id, lang } = params var querystring = semicopy(params, ['method', 'body', 'id', 'lang']) +======= + var warnings = [] + var { method, body, id, context, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) +>>>>>>> 215cc03... Simplify API wrappers (#839) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -118,36 +124,8 @@ function buildPutScript (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/put_template.js b/api/api/put_template.js index ed3596def..5324e69ce 100644 --- a/api/api/put_template.js +++ b/api/api/put_template.js @@ -24,7 +24,7 @@ function buildPutTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [put_template](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-template.html) request * @@ -73,17 +73,17 @@ function buildPutTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id } = params - var querystring = semicopy(params, ['method', 'body', 'id']) + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -98,36 +98,8 @@ function buildPutTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/reindex.js b/api/api/reindex.js index f7818984e..a01ce5f10 100644 --- a/api/api/reindex.js +++ b/api/api/reindex.js @@ -24,7 +24,7 @@ function buildReindex (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [reindex](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-reindex.html) request * @@ -83,17 +83,17 @@ function buildReindex (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -108,36 +108,8 @@ function buildReindex (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/reindex_rethrottle.js b/api/api/reindex_rethrottle.js index a3a2878bc..4f6f932c7 100644 --- a/api/api/reindex_rethrottle.js +++ b/api/api/reindex_rethrottle.js @@ -24,7 +24,7 @@ function buildReindexRethrottle (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [reindex_rethrottle](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-reindex.html) request * @@ -75,17 +75,17 @@ function buildReindexRethrottle (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, taskId, task_id } = params - var querystring = semicopy(params, ['method', 'body', 'taskId', 'task_id']) + var warnings = [] + var { method, body, taskId, task_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -106,36 +106,8 @@ function buildReindexRethrottle (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/render_search_template.js b/api/api/render_search_template.js index 8f494e653..704a2eb78 100644 --- a/api/api/render_search_template.js +++ b/api/api/render_search_template.js @@ -24,7 +24,7 @@ function buildRenderSearchTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [render_search_template](http://www.elasticsearch.org/guide/en/elasticsearch/reference/5.x/search-template.html) request * @@ -63,17 +63,17 @@ function buildRenderSearchTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id } = params - var querystring = semicopy(params, ['method', 'body', 'id']) + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -92,36 +92,8 @@ function buildRenderSearchTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/rollup.delete_job.js b/api/api/rollup.delete_job.js new file mode 100644 index 000000000..a6d7b8800 --- /dev/null +++ b/api/api/rollup.delete_job.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildRollupDeleteJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [rollup.delete_job]() request + * + * @param {string} id - The ID of the job to delete + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function rollupDeleteJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['id'] == null) { + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_rollup' + '/' + 'job' + '/' + encodeURIComponent(id) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildRollupDeleteJob diff --git a/api/api/rollup.get_jobs.js b/api/api/rollup.get_jobs.js new file mode 100644 index 000000000..8bb1f2e71 --- /dev/null +++ b/api/api/rollup.get_jobs.js @@ -0,0 +1,94 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildRollupGetJobs (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [rollup.get_jobs]() request + * + * @param {string} id - The ID of the job(s) to fetch. Accepts glob patterns, or left blank for all jobs + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function rollupGetJobs (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((id) != null) { + path = '/' + '_rollup' + '/' + 'job' + '/' + encodeURIComponent(id) + } else { + path = '/' + '_rollup' + '/' + 'job' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildRollupGetJobs diff --git a/api/api/rollup.get_rollup_caps.js b/api/api/rollup.get_rollup_caps.js new file mode 100644 index 000000000..b0e8d288c --- /dev/null +++ b/api/api/rollup.get_rollup_caps.js @@ -0,0 +1,94 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildRollupGetRollupCaps (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [rollup.get_rollup_caps]() request + * + * @param {string} id - The ID of the index to check rollup capabilities on, or left blank for all jobs + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function rollupGetRollupCaps (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((id) != null) { + path = '/' + '_rollup' + '/' + 'data' + '/' + encodeURIComponent(id) + } else { + path = '/' + '_rollup' + '/' + 'data' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildRollupGetRollupCaps diff --git a/api/api/rollup.get_rollup_index_caps.js b/api/api/rollup.get_rollup_index_caps.js new file mode 100644 index 000000000..cde9a275a --- /dev/null +++ b/api/api/rollup.get_rollup_index_caps.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildRollupGetRollupIndexCaps (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [rollup.get_rollup_index_caps]() request + * + * @param {string} index - The rollup index or index pattern to obtain rollup capabilities from. + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function rollupGetRollupIndexCaps (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['index'] == null) { + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + encodeURIComponent(index) + '/' + '_rollup' + '/' + 'data' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildRollupGetRollupIndexCaps diff --git a/api/api/rollup.rollup_search.js b/api/api/rollup.rollup_search.js new file mode 100644 index 000000000..4310e49f9 --- /dev/null +++ b/api/api/rollup.rollup_search.js @@ -0,0 +1,116 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildRollupRollupSearch (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [rollup.rollup_search]() request + * + * @param {list} index - The indices or index-pattern(s) (containing rollup or regular data) that should be searched + * @param {string} type - The doc type inside the index + * @param {boolean} typed_keys - Specify whether aggregation and suggester names should be prefixed by their respective types in the response + * @param {boolean} rest_total_hits_as_int - Indicates whether hits.total should be rendered as an integer or an object in the rest search response + * @param {object} body - The search request body + */ + + const acceptedQuerystring = [ + 'typed_keys', + 'rest_total_hits_as_int' + ] + + const snakeCase = { + typedKeys: 'typed_keys', + restTotalHitsAsInt: 'rest_total_hits_as_int' + } + + return function rollupRollupSearch (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['index'] == null) { + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // check required url components + if (params['type'] != null && (params['index'] == null)) { + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((index) != null && (type) != null) { + path = '/' + encodeURIComponent(index) + '/' + encodeURIComponent(type) + '/' + '_rollup_search' + } else { + path = '/' + encodeURIComponent(index) + '/' + '_rollup_search' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildRollupRollupSearch diff --git a/api/api/rollup.start_job.js b/api/api/rollup.start_job.js new file mode 100644 index 000000000..bf39647a7 --- /dev/null +++ b/api/api/rollup.start_job.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildRollupStartJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [rollup.start_job]() request + * + * @param {string} id - The ID of the job to start + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function rollupStartJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['id'] == null) { + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_rollup' + '/' + 'job' + '/' + encodeURIComponent(id) + '/' + '_start' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildRollupStartJob diff --git a/api/api/rollup.stop_job.js b/api/api/rollup.stop_job.js new file mode 100644 index 000000000..e4b2e1cc2 --- /dev/null +++ b/api/api/rollup.stop_job.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildRollupStopJob (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [rollup.stop_job]() request + * + * @param {string} id - The ID of the job to stop + * @param {boolean} wait_for_completion - True if the API should block until the job has fully stopped, false if should be executed async. Defaults to false. + * @param {time} timeout - Block for (at maximum) the specified duration while waiting for the job to stop. Defaults to 30s. + */ + + const acceptedQuerystring = [ + 'wait_for_completion', + 'timeout' + ] + + const snakeCase = { + waitForCompletion: 'wait_for_completion' + + } + + return function rollupStopJob (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['id'] == null) { + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_rollup' + '/' + 'job' + '/' + encodeURIComponent(id) + '/' + '_stop' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildRollupStopJob diff --git a/api/api/scripts_painless_context.js b/api/api/scripts_painless_context.js new file mode 100644 index 000000000..b10b63ac9 --- /dev/null +++ b/api/api/scripts_painless_context.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildScriptsPainlessContext (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [scripts_painless_context](undefined) request + * + * @param {string} context - Select a specific context to retrieve API information about + */ + + const acceptedQuerystring = [ + 'context', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + + const snakeCase = { + errorTrace: 'error_trace', + filterPath: 'filter_path' + } + + return function scriptsPainlessContext (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_scripts' + '/' + 'painless' + '/' + '_context' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildScriptsPainlessContext diff --git a/api/api/scripts_painless_execute.js b/api/api/scripts_painless_execute.js new file mode 100644 index 000000000..db99454e1 --- /dev/null +++ b/api/api/scripts_painless_execute.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildScriptsPainlessExecute (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [scripts_painless_execute](https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html) request + * + * @param {object} body - The script to execute + */ + + const acceptedQuerystring = [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + + const snakeCase = { + errorTrace: 'error_trace', + filterPath: 'filter_path' + } + + return function scriptsPainlessExecute (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_scripts' + '/' + 'painless' + '/' + '_execute' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildScriptsPainlessExecute diff --git a/api/api/scroll.js b/api/api/scroll.js index c9b075cfb..d1ab11c9b 100644 --- a/api/api/scroll.js +++ b/api/api/scroll.js @@ -24,7 +24,7 @@ function buildScroll (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [scroll](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-request-scroll.html) request * @@ -68,17 +68,17 @@ function buildScroll (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, scrollId, scroll_id } = params - var querystring = semicopy(params, ['method', 'body', 'scrollId', 'scroll_id']) + var warnings = [] + var { method, body, scrollId, scroll_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -97,36 +97,8 @@ function buildScroll (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/search.js b/api/api/search.js index 7f632d487..799bab339 100644 --- a/api/api/search.js +++ b/api/api/search.js @@ -24,7 +24,7 @@ function buildSearch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [search](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-search.html) request * @@ -166,17 +166,17 @@ function buildSearch (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -197,36 +197,8 @@ function buildSearch (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/search_shards.js b/api/api/search_shards.js index 3da0d0b9f..90277b81d 100644 --- a/api/api/search_shards.js +++ b/api/api/search_shards.js @@ -24,7 +24,7 @@ function buildSearchShards (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [search_shards](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-shards.html) request * @@ -90,17 +90,23 @@ function buildSearchShards (opts) { return handleError(err, callback) } +<<<<<<< HEAD var warnings = null var { method, body, index, type } = params var querystring = semicopy(params, ['method', 'body', 'index', 'type']) +======= + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) +>>>>>>> 215cc03... Simplify API wrappers (#839) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -121,36 +127,8 @@ function buildSearchShards (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/search_template.js b/api/api/search_template.js index 641c00564..af267713c 100644 --- a/api/api/search_template.js +++ b/api/api/search_template.js @@ -24,7 +24,7 @@ function buildSearchTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [search_template](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) request * @@ -95,17 +95,17 @@ function buildSearchTemplate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -126,36 +126,8 @@ function buildSearchTemplate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/security.authenticate.js b/api/api/security.authenticate.js new file mode 100644 index 000000000..c2f5ea868 --- /dev/null +++ b/api/api/security.authenticate.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityAuthenticate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.authenticate](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-authenticate.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityAuthenticate (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + '_authenticate' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityAuthenticate diff --git a/api/api/security.change_password.js b/api/api/security.change_password.js new file mode 100644 index 000000000..831f013a7 --- /dev/null +++ b/api/api/security.change_password.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityChangePassword (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.change_password](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html) request + * + * @param {string} username - The username of the user to change the password for + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * @param {object} body - the new password for the user + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityChangePassword (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, username, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((username) != null) { + path = '/' + '_security' + '/' + 'user' + '/' + encodeURIComponent(username) + '/' + '_password' + } else { + path = '/' + '_security' + '/' + 'user' + '/' + '_password' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityChangePassword diff --git a/api/api/security.clear_cached_realms.js b/api/api/security.clear_cached_realms.js new file mode 100644 index 000000000..b5483c8c4 --- /dev/null +++ b/api/api/security.clear_cached_realms.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityClearCachedRealms (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.clear_cached_realms](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-cache.html) request + * + * @param {list} realms - Comma-separated list of realms to clear + * @param {list} usernames - Comma-separated list of usernames to clear from the cache + */ + + const acceptedQuerystring = [ + 'usernames' + ] + + const snakeCase = { + + } + + return function securityClearCachedRealms (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['realms'] == null) { + const err = new ConfigurationError('Missing required parameter: realms') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, realms, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'realm' + '/' + encodeURIComponent(realms) + '/' + '_clear_cache' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityClearCachedRealms diff --git a/api/api/security.clear_cached_roles.js b/api/api/security.clear_cached_roles.js new file mode 100644 index 000000000..13eee568b --- /dev/null +++ b/api/api/security.clear_cached_roles.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityClearCachedRoles (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.clear_cached_roles](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-role-cache.html) request + * + * @param {list} name - Role name + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityClearCachedRoles (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['name'] == null) { + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'role' + '/' + encodeURIComponent(name) + '/' + '_clear_cache' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityClearCachedRoles diff --git a/api/api/security.create_api_key.js b/api/api/security.create_api_key.js new file mode 100644 index 000000000..a2e6a2e29 --- /dev/null +++ b/api/api/security.create_api_key.js @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityCreateApiKey (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.create_api_key](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html) request + * + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * @param {object} body - The api key request to create an API key + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityCreateApiKey (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'api_key' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityCreateApiKey diff --git a/api/api/security.delete_privileges.js b/api/api/security.delete_privileges.js new file mode 100644 index 000000000..72efa3bdd --- /dev/null +++ b/api/api/security.delete_privileges.js @@ -0,0 +1,112 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityDeletePrivileges (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.delete_privileges](TODO) request + * + * @param {string} application - Application name + * @param {string} name - Privilege name + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityDeletePrivileges (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['application'] == null) { + const err = new ConfigurationError('Missing required parameter: application') + return handleError(err, callback) + } + if (params['name'] == null) { + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // check required url components + if (params['name'] != null && (params['application'] == null)) { + const err = new ConfigurationError('Missing required parameter of the url: application') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, application, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'privilege' + '/' + encodeURIComponent(application) + '/' + encodeURIComponent(name) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityDeletePrivileges diff --git a/api/api/security.delete_role.js b/api/api/security.delete_role.js new file mode 100644 index 000000000..6401406c1 --- /dev/null +++ b/api/api/security.delete_role.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityDeleteRole (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.delete_role](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role.html) request + * + * @param {string} name - Role name + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityDeleteRole (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['name'] == null) { + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'role' + '/' + encodeURIComponent(name) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityDeleteRole diff --git a/api/api/security.delete_role_mapping.js b/api/api/security.delete_role_mapping.js new file mode 100644 index 000000000..b9f69494c --- /dev/null +++ b/api/api/security.delete_role_mapping.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityDeleteRoleMapping (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.delete_role_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role-mapping.html) request + * + * @param {string} name - Role-mapping name + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityDeleteRoleMapping (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['name'] == null) { + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'role_mapping' + '/' + encodeURIComponent(name) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityDeleteRoleMapping diff --git a/api/api/security.delete_user.js b/api/api/security.delete_user.js new file mode 100644 index 000000000..da25eda5e --- /dev/null +++ b/api/api/security.delete_user.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityDeleteUser (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.delete_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-user.html) request + * + * @param {string} username - username + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityDeleteUser (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['username'] == null) { + const err = new ConfigurationError('Missing required parameter: username') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, username, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'user' + '/' + encodeURIComponent(username) + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityDeleteUser diff --git a/api/api/security.disable_user.js b/api/api/security.disable_user.js new file mode 100644 index 000000000..c12de072d --- /dev/null +++ b/api/api/security.disable_user.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityDisableUser (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.disable_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html) request + * + * @param {string} username - The username of the user to disable + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityDisableUser (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['username'] == null) { + const err = new ConfigurationError('Missing required parameter: username') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, username, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'user' + '/' + encodeURIComponent(username) + '/' + '_disable' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityDisableUser diff --git a/api/api/security.enable_user.js b/api/api/security.enable_user.js new file mode 100644 index 000000000..b59558acb --- /dev/null +++ b/api/api/security.enable_user.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityEnableUser (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.enable_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html) request + * + * @param {string} username - The username of the user to enable + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityEnableUser (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['username'] == null) { + const err = new ConfigurationError('Missing required parameter: username') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, username, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'user' + '/' + encodeURIComponent(username) + '/' + '_enable' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityEnableUser diff --git a/api/api/security.get_api_key.js b/api/api/security.get_api_key.js new file mode 100644 index 000000000..eea2eb066 --- /dev/null +++ b/api/api/security.get_api_key.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityGetApiKey (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.get_api_key](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-api-key.html) request + * + * @param {string} id - API key id of the API key to be retrieved + * @param {string} name - API key name of the API key to be retrieved + * @param {string} username - user name of the user who created this API key to be retrieved + * @param {string} realm_name - realm name of the user who created this API key to be retrieved + */ + + const acceptedQuerystring = [ + 'id', + 'name', + 'username', + 'realm_name' + ] + + const snakeCase = { + realmName: 'realm_name' + } + + return function securityGetApiKey (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'api_key' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityGetApiKey diff --git a/api/api/security.get_privileges.js b/api/api/security.get_privileges.js new file mode 100644 index 000000000..5bea2a86c --- /dev/null +++ b/api/api/security.get_privileges.js @@ -0,0 +1,109 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityGetPrivileges (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.get_privileges](TODO) request + * + * @param {string} application - Application name + * @param {string} name - Privilege name + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityGetPrivileges (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // check required url components + if (params['name'] != null && (params['application'] == null)) { + const err = new ConfigurationError('Missing required parameter of the url: application') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, application, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((application) != null && (name) != null) { + path = '/' + '_security' + '/' + 'privilege' + '/' + encodeURIComponent(application) + '/' + encodeURIComponent(name) + } else if ((application) != null) { + path = '/' + '_security' + '/' + 'privilege' + '/' + encodeURIComponent(application) + } else { + path = '/' + '_security' + '/' + 'privilege' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityGetPrivileges diff --git a/api/api/security.get_role.js b/api/api/security.get_role.js new file mode 100644 index 000000000..f4c757bf6 --- /dev/null +++ b/api/api/security.get_role.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityGetRole (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.get_role](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role.html) request + * + * @param {string} name - Role name + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityGetRole (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((name) != null) { + path = '/' + '_security' + '/' + 'role' + '/' + encodeURIComponent(name) + } else { + path = '/' + '_security' + '/' + 'role' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityGetRole diff --git a/api/api/security.get_role_mapping.js b/api/api/security.get_role_mapping.js new file mode 100644 index 000000000..fc58769f6 --- /dev/null +++ b/api/api/security.get_role_mapping.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityGetRoleMapping (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.get_role_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role-mapping.html) request + * + * @param {string} name - Role-Mapping name + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityGetRoleMapping (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((name) != null) { + path = '/' + '_security' + '/' + 'role_mapping' + '/' + encodeURIComponent(name) + } else { + path = '/' + '_security' + '/' + 'role_mapping' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityGetRoleMapping diff --git a/api/api/security.get_token.js b/api/api/security.get_token.js new file mode 100644 index 000000000..1f4c8c761 --- /dev/null +++ b/api/api/security.get_token.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityGetToken (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.get_token](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-token.html) request + * + * @param {object} body - The token request to get + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityGetToken (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'oauth2' + '/' + 'token' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityGetToken diff --git a/api/api/security.get_user.js b/api/api/security.get_user.js new file mode 100644 index 000000000..590661f6b --- /dev/null +++ b/api/api/security.get_user.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityGetUser (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.get_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-user.html) request + * + * @param {list} username - A comma-separated list of usernames + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityGetUser (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, username, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((username) != null) { + path = '/' + '_security' + '/' + 'user' + '/' + encodeURIComponent(username) + } else { + path = '/' + '_security' + '/' + 'user' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityGetUser diff --git a/api/api/security.get_user_privileges.js b/api/api/security.get_user_privileges.js new file mode 100644 index 000000000..dc8e3f803 --- /dev/null +++ b/api/api/security.get_user_privileges.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityGetUserPrivileges (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.get_user_privileges](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-privileges.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityGetUserPrivileges (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'user' + '/' + '_privileges' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityGetUserPrivileges diff --git a/api/api/security.has_privileges.js b/api/api/security.has_privileges.js new file mode 100644 index 000000000..cea2e5a13 --- /dev/null +++ b/api/api/security.has_privileges.js @@ -0,0 +1,101 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityHasPrivileges (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.has_privileges](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-has-privileges.html) request + * + * @param {string} user - Username + * @param {object} body - The privileges to test + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityHasPrivileges (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, user, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((user) != null) { + path = '/' + '_security' + '/' + 'user' + '/' + encodeURIComponent(user) + '/' + '_has_privileges' + } else { + path = '/' + '_security' + '/' + 'user' + '/' + '_has_privileges' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityHasPrivileges diff --git a/api/api/security.invalidate_api_key.js b/api/api/security.invalidate_api_key.js new file mode 100644 index 000000000..16f0bf3f1 --- /dev/null +++ b/api/api/security.invalidate_api_key.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityInvalidateApiKey (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.invalidate_api_key](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-api-key.html) request + * + * @param {object} body - The api key request to invalidate API key(s) + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityInvalidateApiKey (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'api_key' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityInvalidateApiKey diff --git a/api/api/security.invalidate_token.js b/api/api/security.invalidate_token.js new file mode 100644 index 000000000..262d82ce4 --- /dev/null +++ b/api/api/security.invalidate_token.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityInvalidateToken (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.invalidate_token](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-token.html) request + * + * @param {object} body - The token to invalidate + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function securityInvalidateToken (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'DELETE' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'oauth2' + '/' + 'token' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityInvalidateToken diff --git a/api/api/security.put_privileges.js b/api/api/security.put_privileges.js new file mode 100644 index 000000000..80cf7976f --- /dev/null +++ b/api/api/security.put_privileges.js @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityPutPrivileges (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.put_privileges](TODO) request + * + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * @param {object} body - The privilege(s) to add + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityPutPrivileges (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'privilege' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityPutPrivileges diff --git a/api/api/security.put_role.js b/api/api/security.put_role.js new file mode 100644 index 000000000..62d8dae4d --- /dev/null +++ b/api/api/security.put_role.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityPutRole (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.put_role](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role.html) request + * + * @param {string} name - Role name + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * @param {object} body - The role to add + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityPutRole (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['name'] == null) { + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'role' + '/' + encodeURIComponent(name) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityPutRole diff --git a/api/api/security.put_role_mapping.js b/api/api/security.put_role_mapping.js new file mode 100644 index 000000000..091d7b477 --- /dev/null +++ b/api/api/security.put_role_mapping.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityPutRoleMapping (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.put_role_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role-mapping.html) request + * + * @param {string} name - Role-mapping name + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * @param {object} body - The role mapping to add + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityPutRoleMapping (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['name'] == null) { + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, name, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'role_mapping' + '/' + encodeURIComponent(name) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityPutRoleMapping diff --git a/api/api/security.put_user.js b/api/api/security.put_user.js new file mode 100644 index 000000000..7b8b04f54 --- /dev/null +++ b/api/api/security.put_user.js @@ -0,0 +1,102 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSecurityPutUser (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [security.put_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-user.html) request + * + * @param {string} username - The username of the User + * @param {enum} refresh - If `true` (the default) then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` then do nothing with refreshes. + * @param {object} body - The user to add + */ + + const acceptedQuerystring = [ + 'refresh' + ] + + const snakeCase = { + + } + + return function securityPutUser (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['username'] == null) { + const err = new ConfigurationError('Missing required parameter: username') + return handleError(err, callback) + } + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, username, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_security' + '/' + 'user' + '/' + encodeURIComponent(username) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSecurityPutUser diff --git a/api/api/snapshot.create.js b/api/api/snapshot.create.js index 271534554..410444d85 100644 --- a/api/api/snapshot.create.js +++ b/api/api/snapshot.create.js @@ -24,7 +24,7 @@ function buildSnapshotCreate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.create](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -86,17 +86,17 @@ function buildSnapshotCreate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository, snapshot } = params - var querystring = semicopy(params, ['method', 'body', 'repository', 'snapshot']) + var warnings = [] + var { method, body, repository, snapshot, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildSnapshotCreate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/snapshot.create_repository.js b/api/api/snapshot.create_repository.js index db438b595..5e6c780da 100644 --- a/api/api/snapshot.create_repository.js +++ b/api/api/snapshot.create_repository.js @@ -24,7 +24,7 @@ function buildSnapshotCreateRepository (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.create_repository](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -80,17 +80,17 @@ function buildSnapshotCreateRepository (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository } = params - var querystring = semicopy(params, ['method', 'body', 'repository']) + var warnings = [] + var { method, body, repository, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'PUT' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -105,36 +105,8 @@ function buildSnapshotCreateRepository (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/snapshot.delete.js b/api/api/snapshot.delete.js index 86c5c51b5..9a817cf44 100644 --- a/api/api/snapshot.delete.js +++ b/api/api/snapshot.delete.js @@ -24,7 +24,7 @@ function buildSnapshotDelete (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.delete](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -86,17 +86,17 @@ function buildSnapshotDelete (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository, snapshot } = params - var querystring = semicopy(params, ['method', 'body', 'repository', 'snapshot']) + var warnings = [] + var { method, body, repository, snapshot, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildSnapshotDelete (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/snapshot.delete_repository.js b/api/api/snapshot.delete_repository.js index 5800155f1..1ba374289 100644 --- a/api/api/snapshot.delete_repository.js +++ b/api/api/snapshot.delete_repository.js @@ -24,7 +24,7 @@ function buildSnapshotDeleteRepository (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.delete_repository](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -77,17 +77,17 @@ function buildSnapshotDeleteRepository (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository } = params - var querystring = semicopy(params, ['method', 'body', 'repository']) + var warnings = [] + var { method, body, repository, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'DELETE' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildSnapshotDeleteRepository (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/snapshot.get.js b/api/api/snapshot.get.js index cd4f447ef..72f88cb38 100644 --- a/api/api/snapshot.get.js +++ b/api/api/snapshot.get.js @@ -24,7 +24,7 @@ function buildSnapshotGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.get](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -91,17 +91,17 @@ function buildSnapshotGet (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository, snapshot } = params - var querystring = semicopy(params, ['method', 'body', 'repository', 'snapshot']) + var warnings = [] + var { method, body, repository, snapshot, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -116,36 +116,8 @@ function buildSnapshotGet (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/snapshot.get_repository.js b/api/api/snapshot.get_repository.js index 96916887c..89424248b 100644 --- a/api/api/snapshot.get_repository.js +++ b/api/api/snapshot.get_repository.js @@ -24,7 +24,7 @@ function buildSnapshotGetRepository (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.get_repository](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -73,17 +73,17 @@ function buildSnapshotGetRepository (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository } = params - var querystring = semicopy(params, ['method', 'body', 'repository']) + var warnings = [] + var { method, body, repository, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildSnapshotGetRepository (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/snapshot.restore.js b/api/api/snapshot.restore.js index 33647efeb..d888fb078 100644 --- a/api/api/snapshot.restore.js +++ b/api/api/snapshot.restore.js @@ -24,7 +24,7 @@ function buildSnapshotRestore (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.restore](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -86,17 +86,17 @@ function buildSnapshotRestore (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository, snapshot } = params - var querystring = semicopy(params, ['method', 'body', 'repository', 'snapshot']) + var warnings = [] + var { method, body, repository, snapshot, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildSnapshotRestore (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/snapshot.status.js b/api/api/snapshot.status.js index 4363c30f4..081787139 100644 --- a/api/api/snapshot.status.js +++ b/api/api/snapshot.status.js @@ -24,7 +24,7 @@ function buildSnapshotStatus (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.status](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -81,17 +81,17 @@ function buildSnapshotStatus (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository, snapshot } = params - var querystring = semicopy(params, ['method', 'body', 'repository', 'snapshot']) + var warnings = [] + var { method, body, repository, snapshot, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -112,36 +112,8 @@ function buildSnapshotStatus (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/snapshot.verify_repository.js b/api/api/snapshot.verify_repository.js index de4111896..52586dfd1 100644 --- a/api/api/snapshot.verify_repository.js +++ b/api/api/snapshot.verify_repository.js @@ -24,7 +24,7 @@ function buildSnapshotVerifyRepository (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [snapshot.verify_repository](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-snapshots.html) request * @@ -77,17 +77,17 @@ function buildSnapshotVerifyRepository (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, repository } = params - var querystring = semicopy(params, ['method', 'body', 'repository']) + var warnings = [] + var { method, body, repository, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -102,36 +102,8 @@ function buildSnapshotVerifyRepository (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/sql.clear_cursor.js b/api/api/sql.clear_cursor.js new file mode 100644 index 000000000..ab620ca6a --- /dev/null +++ b/api/api/sql.clear_cursor.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSqlClearCursor (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [sql.clear_cursor](Clear SQL cursor) request + * + * @param {object} body - Specify the cursor value in the `cursor` element to clean the cursor. + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function sqlClearCursor (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_sql' + '/' + 'close' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSqlClearCursor diff --git a/api/api/sql.query.js b/api/api/sql.query.js new file mode 100644 index 000000000..87246c23e --- /dev/null +++ b/api/api/sql.query.js @@ -0,0 +1,97 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSqlQuery (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [sql.query](Execute SQL) request + * + * @param {string} format - a short version of the Accept header, e.g. json, yaml + * @param {object} body - Use the `query` element to start a query. Use the `cursor` element to continue a query. + */ + + const acceptedQuerystring = [ + 'format' + ] + + const snakeCase = { + + } + + return function sqlQuery (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_sql' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSqlQuery diff --git a/api/api/sql.translate.js b/api/api/sql.translate.js new file mode 100644 index 000000000..cb5d62754 --- /dev/null +++ b/api/api/sql.translate.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSqlTranslate (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [sql.translate](Translate SQL into Elasticsearch queries) request + * + * @param {object} body - Specify the query in the `query` element. + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function sqlTranslate (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['body'] == null) { + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = body == null ? 'GET' : 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_sql' + '/' + 'translate' + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSqlTranslate diff --git a/api/api/ssl.certificates.js b/api/api/ssl.certificates.js new file mode 100644 index 000000000..706bf117d --- /dev/null +++ b/api/api/ssl.certificates.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildSslCertificates (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [ssl.certificates](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function sslCertificates (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_ssl' + '/' + 'certificates' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildSslCertificates diff --git a/api/api/suggest.js b/api/api/suggest.js index 8261e9b46..0dfe359e2 100644 --- a/api/api/suggest.js +++ b/api/api/suggest.js @@ -24,7 +24,7 @@ function buildSuggest (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [suggest](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/search-suggesters.html) request * @@ -82,17 +82,17 @@ function buildSuggest (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index } = params - var querystring = semicopy(params, ['method', 'body', 'index']) + var warnings = [] + var { method, body, index, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -111,36 +111,8 @@ function buildSuggest (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/tasks.cancel.js b/api/api/tasks.cancel.js index 78535ec27..5db9340e4 100644 --- a/api/api/tasks.cancel.js +++ b/api/api/tasks.cancel.js @@ -24,7 +24,7 @@ function buildTasksCancel (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [tasks.cancel](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html) request * @@ -78,17 +78,17 @@ function buildTasksCancel (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, taskId, task_id } = params - var querystring = semicopy(params, ['method', 'body', 'taskId', 'task_id']) + var warnings = [] + var { method, body, taskId, task_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -107,36 +107,8 @@ function buildTasksCancel (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/tasks.get.js b/api/api/tasks.get.js index cb670d622..f78347106 100644 --- a/api/api/tasks.get.js +++ b/api/api/tasks.get.js @@ -24,7 +24,7 @@ function buildTasksGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [tasks.get](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html) request * @@ -71,17 +71,17 @@ function buildTasksGet (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, taskId, task_id } = params - var querystring = semicopy(params, ['method', 'body', 'taskId', 'task_id']) + var warnings = [] + var { method, body, taskId, task_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -96,36 +96,8 @@ function buildTasksGet (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/tasks.list.js b/api/api/tasks.list.js index c0157e0d5..b53fc0f86 100644 --- a/api/api/tasks.list.js +++ b/api/api/tasks.list.js @@ -24,7 +24,7 @@ function buildTasksList (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [tasks.list](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/tasks.html) request * @@ -85,17 +85,17 @@ function buildTasksList (opts) { return handleError(err, callback) } - var warnings = null - var { method, body } = params - var querystring = semicopy(params, ['method', 'body']) + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'GET' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -110,36 +110,8 @@ function buildTasksList (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/termvectors.js b/api/api/termvectors.js index 180826603..c5cbfb6cd 100644 --- a/api/api/termvectors.js +++ b/api/api/termvectors.js @@ -24,7 +24,7 @@ function buildTermvectors (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [termvectors](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-termvectors.html) request * @@ -102,17 +102,17 @@ function buildTermvectors (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type, id } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type', 'id']) + var warnings = [] + var { method, body, index, type, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = body == null ? 'GET' : 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -131,36 +131,8 @@ function buildTermvectors (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/update.js b/api/api/update.js index b4abc7e40..a02428dc8 100644 --- a/api/api/update.js +++ b/api/api/update.js @@ -24,7 +24,7 @@ function buildUpdate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [update](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-update.html) request * @@ -114,17 +114,17 @@ function buildUpdate (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, id, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'id', 'index', 'type']) + var warnings = [] + var { method, body, id, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -139,36 +139,8 @@ function buildUpdate (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/update_by_query.js b/api/api/update_by_query.js index 72ae55897..b08bd43d7 100644 --- a/api/api/update_by_query.js +++ b/api/api/update_by_query.js @@ -24,7 +24,7 @@ function buildUpdateByQuery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts /** * Perform a [update_by_query](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/docs-update-by-query.html) request * @@ -160,17 +160,17 @@ function buildUpdateByQuery (opts) { return handleError(err, callback) } - var warnings = null - var { method, body, index, type } = params - var querystring = semicopy(params, ['method', 'body', 'index', 'type']) + var warnings = [] + var { method, body, index, type, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { method = 'POST' } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } var path = '' @@ -189,36 +189,8 @@ function buildUpdateByQuery (opts) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } } diff --git a/api/api/update_by_query_rethrottle.js b/api/api/update_by_query_rethrottle.js new file mode 100644 index 000000000..59a72a6e5 --- /dev/null +++ b/api/api/update_by_query_rethrottle.js @@ -0,0 +1,112 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildUpdateByQueryRethrottle (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [update_by_query_rethrottle](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html) request + * + * @param {string} task_id - The task id to rethrottle + * @param {number} requests_per_second - The throttle to set on this request in floating sub-requests per second. -1 means set no throttle. + */ + + const acceptedQuerystring = [ + 'requests_per_second', + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ] + + const snakeCase = { + requestsPerSecond: 'requests_per_second', + errorTrace: 'error_trace', + filterPath: 'filter_path' + } + + return function updateByQueryRethrottle (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['task_id'] == null && params['taskId'] == null) { + const err = new ConfigurationError('Missing required parameter: task_id or taskId') + return handleError(err, callback) + } + if (params['requests_per_second'] == null && params['requestsPerSecond'] == null) { + const err = new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, taskId, task_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_update_by_query' + '/' + encodeURIComponent(task_id || taskId) + '/' + '_rethrottle' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildUpdateByQueryRethrottle diff --git a/api/api/watcher.ack_watch.js b/api/api/watcher.ack_watch.js new file mode 100644 index 000000000..323ba16d7 --- /dev/null +++ b/api/api/watcher.ack_watch.js @@ -0,0 +1,111 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildWatcherAckWatch (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [watcher.ack_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-ack-watch.html) request + * + * @param {string} watch_id - Watch ID + * @param {list} action_id - A comma-separated list of the action ids to be acked + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function watcherAckWatch (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['watch_id'] == null && params['watchId'] == null) { + const err = new ConfigurationError('Missing required parameter: watch_id or watchId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // check required url components + if ((params['action_id'] != null || params['actionId'] != null) && ((params['watch_id'] == null && params['watchId'] == null))) { + const err = new ConfigurationError('Missing required parameter of the url: watch_id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, watchId, watch_id, actionId, action_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((watch_id || watchId) != null && (action_id || actionId) != null) { + path = '/' + '_watcher' + '/' + 'watch' + '/' + encodeURIComponent(watch_id || watchId) + '/' + '_ack' + '/' + encodeURIComponent(action_id || actionId) + } else { + path = '/' + '_watcher' + '/' + 'watch' + '/' + encodeURIComponent(watch_id || watchId) + '/' + '_ack' + } + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildWatcherAckWatch diff --git a/api/api/watcher.activate_watch.js b/api/api/watcher.activate_watch.js new file mode 100644 index 000000000..31640579a --- /dev/null +++ b/api/api/watcher.activate_watch.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildWatcherActivateWatch (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [watcher.activate_watch](https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-activate-watch.html) request + * + * @param {string} watch_id - Watch ID + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function watcherActivateWatch (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['watch_id'] == null && params['watchId'] == null) { + const err = new ConfigurationError('Missing required parameter: watch_id or watchId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, watchId, watch_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_watcher' + '/' + 'watch' + '/' + encodeURIComponent(watch_id || watchId) + '/' + '_activate' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildWatcherActivateWatch diff --git a/api/api/watcher.deactivate_watch.js b/api/api/watcher.deactivate_watch.js new file mode 100644 index 000000000..54501a2f0 --- /dev/null +++ b/api/api/watcher.deactivate_watch.js @@ -0,0 +1,100 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildWatcherDeactivateWatch (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [watcher.deactivate_watch](https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-deactivate-watch.html) request + * + * @param {string} watch_id - Watch ID + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function watcherDeactivateWatch (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['watch_id'] == null && params['watchId'] == null) { + const err = new ConfigurationError('Missing required parameter: watch_id or watchId') + return handleError(err, callback) + } + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, watchId, watch_id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_watcher' + '/' + 'watch' + '/' + encodeURIComponent(watch_id || watchId) + '/' + '_deactivate' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildWatcherDeactivateWatch diff --git a/api/api/watcher.execute_watch.js b/api/api/watcher.execute_watch.js new file mode 100644 index 000000000..8a7865d2a --- /dev/null +++ b/api/api/watcher.execute_watch.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildWatcherExecuteWatch (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [watcher.execute_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-execute-watch.html) request + * + * @param {string} id - Watch ID + * @param {boolean} debug - indicates whether the watch should execute in debug mode + * @param {object} body - Execution control + */ + + const acceptedQuerystring = [ + 'debug' + ] + + const snakeCase = { + + } + + return function watcherExecuteWatch (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((id) != null) { + path = '/' + '_watcher' + '/' + 'watch' + '/' + encodeURIComponent(id) + '/' + '_execute' + } else { + path = '/' + '_watcher' + '/' + 'watch' + '/' + '_execute' + } + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildWatcherExecuteWatch diff --git a/api/api/watcher.put_watch.js b/api/api/watcher.put_watch.js new file mode 100644 index 000000000..05ba4edfe --- /dev/null +++ b/api/api/watcher.put_watch.js @@ -0,0 +1,105 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildWatcherPutWatch (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [watcher.put_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-put-watch.html) request + * + * @param {string} id - Watch ID + * @param {boolean} active - Specify whether the watch is in/active by default + * @param {number} version - Explicit version number for concurrency control + * @param {number} if_seq_no - only update the watch if the last operation that has changed the watch has the specified sequence number + * @param {number} if_primary_term - only update the watch if the last operation that has changed the watch has the specified primary term + * @param {object} body - The watch + */ + + const acceptedQuerystring = [ + 'active', + 'version', + 'if_seq_no', + 'if_primary_term' + ] + + const snakeCase = { + ifSeqNo: 'if_seq_no', + ifPrimaryTerm: 'if_primary_term' + } + + return function watcherPutWatch (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params['id'] == null) { + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, id, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'PUT' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_watcher' + '/' + 'watch' + '/' + encodeURIComponent(id) + + // build request object + const request = { + method, + path, + body: body || '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildWatcherPutWatch diff --git a/api/api/watcher.start.js b/api/api/watcher.start.js new file mode 100644 index 000000000..5221faf23 --- /dev/null +++ b/api/api/watcher.start.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildWatcherStart (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [watcher.start](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-start.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function watcherStart (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_watcher' + '/' + '_start' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildWatcherStart diff --git a/api/api/watcher.stats.js b/api/api/watcher.stats.js new file mode 100644 index 000000000..792a895c1 --- /dev/null +++ b/api/api/watcher.stats.js @@ -0,0 +1,103 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildWatcherStats (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [watcher.stats](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stats.html) request + * + * @param {list} metric - Controls what additional stat metrics should be include in the response + * @param {list} metric - Controls what additional stat metrics should be include in the response + * @param {boolean} emit_stacktraces - Emits stack traces of currently running watches + */ + + const acceptedQuerystring = [ + 'metric', + 'emit_stacktraces' + ] + + const snakeCase = { + emitStacktraces: 'emit_stacktraces' + } + + return function watcherStats (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, metric, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + if ((metric) != null) { + path = '/' + '_watcher' + '/' + 'stats' + '/' + encodeURIComponent(metric) + } else { + path = '/' + '_watcher' + '/' + 'stats' + } + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildWatcherStats diff --git a/api/api/watcher.stop.js b/api/api/watcher.stop.js new file mode 100644 index 000000000..5eea1055c --- /dev/null +++ b/api/api/watcher.stop.js @@ -0,0 +1,95 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildWatcherStop (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [watcher.stop](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stop.html) request + * + */ + + const acceptedQuerystring = [ + + ] + + const snakeCase = { + + } + + return function watcherStop (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'POST' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_watcher' + '/' + '_stop' + + // build request object + const request = { + method, + path, + body: '', + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildWatcherStop diff --git a/api/api/xpack.info.js b/api/api/xpack.info.js new file mode 100644 index 000000000..504e3543d --- /dev/null +++ b/api/api/xpack.info.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildXpackInfo (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [xpack.info](https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html) request + * + * @param {list} categories - Comma-separated list of info categories. Can be any of: build, license, features + */ + + const acceptedQuerystring = [ + 'categories' + ] + + const snakeCase = { + + } + + return function xpackInfo (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_xpack' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildXpackInfo diff --git a/api/api/xpack.usage.js b/api/api/xpack.usage.js new file mode 100644 index 000000000..e7f3971a3 --- /dev/null +++ b/api/api/xpack.usage.js @@ -0,0 +1,96 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict' + +/* eslint camelcase: 0 */ +/* eslint no-unused-vars: 0 */ + +function buildXpackUsage (opts) { + // eslint-disable-next-line no-unused-vars + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts + /** + * Perform a [xpack.usage](Retrieve information about xpack features usage) request + * + * @param {time} master_timeout - Specify timeout for watch write operation + */ + + const acceptedQuerystring = [ + 'master_timeout' + ] + + const snakeCase = { + masterTimeout: 'master_timeout' + } + + return function xpackUsage (params, options, callback) { + options = options || {} + if (typeof options === 'function') { + callback = options + options = {} + } + if (typeof params === 'function' || params == null) { + callback = params + params = {} + options = {} + } + + // check required parameters + if (params.body != null) { + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) + } + + // validate headers object + if (options.headers != null && typeof options.headers !== 'object') { + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) + } + + var warnings = [] + var { method, body, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) + + if (method == null) { + method = 'GET' + } + + var ignore = options.ignore + if (typeof ignore === 'number') { + options.ignore = [ignore] + } + + var path = '' + + path = '/' + '_xpack' + '/' + 'usage' + + // build request object + const request = { + method, + path, + body: null, + querystring + } + + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) + } +} + +module.exports = buildXpackUsage diff --git a/api/index.js b/api/index.js index 577f5aa59..0ffb6741c 100644 --- a/api/index.js +++ b/api/index.js @@ -28,6 +28,7 @@ function ESAPI (opts) { const { result } = opts opts.handleError = handleError + opts.snakeCaseKeys = snakeCaseKeys const apis = { bulk: lazyLoad('bulk', opts), @@ -232,6 +233,19 @@ function ESAPI (opts) { if (callback) return callback(err, result) return Promise.reject(err) } + + function snakeCaseKeys (acceptedQuerystring, snakeCase, querystring, warnings) { + var target = {} + var keys = Object.keys(querystring) + for (var i = 0, len = keys.length; i < len; i++) { + var key = keys[i] + target[snakeCase[key] || key] = querystring[key] + if (acceptedQuerystring.indexOf(snakeCase[key] || key) === -1) { + warnings.push('Client - Unknown parameter: "' + key + '", sending it as query parameter') + } + } + return target + } } // It's unlikely that a user needs all of our APIs, diff --git a/scripts/utils/generateApis.js b/scripts/utils/generateApis.js index 9e1bfc046..825947737 100644 --- a/scripts/utils/generateApis.js +++ b/scripts/utils/generateApis.js @@ -118,17 +118,17 @@ function generate (spec, common) { return handleError(err, callback) } - var warnings = null - var { ${genQueryBlacklist(false)} } = params - var querystring = semicopy(params, [${genQueryBlacklist()}]) + var warnings = [] + var { ${genQueryBlacklist(false)}, ...querystring } = params + querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring, warnings) if (method == null) { ${generatePickMethod(methods)} } - var ignore = options.ignore || null + var ignore = options.ignore if (typeof ignore === 'number') { - ignore = [ignore] + options.ignore = [ignore] } @@ -143,36 +143,8 @@ function generate (spec, common) { querystring } - const requestOptions = { - ignore, - requestTimeout: options.requestTimeout || null, - maxRetries: options.maxRetries || null, - asStream: options.asStream || false, - headers: options.headers || null, - querystring: options.querystring || null, - compression: options.compression || false, - id: options.id || null, - context: options.context || 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 - } + options.warnings = warnings.length === 0 ? null : warnings + return makeRequest(request, options, callback) } `.trim() // always call trim to avoid newlines @@ -203,7 +175,7 @@ function generate (spec, common) { function build${name[0].toUpperCase() + name.slice(1)} (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, handleError } = opts + const { makeRequest, ConfigurationError, handleError, snakeCaseKeys } = opts ${generateDocumentation(spec[api], api)} const acceptedQuerystring = [ diff --git a/scripts/utils/generateMain.js b/scripts/utils/generateMain.js index 7f0a5aeda..99d24f9a9 100644 --- a/scripts/utils/generateMain.js +++ b/scripts/utils/generateMain.js @@ -125,6 +125,7 @@ function genFactory (folder) { const { result } = opts opts.handleError = handleError + opts.snakeCaseKeys = snakeCaseKeys const apis = ${apisStr} @@ -135,6 +136,19 @@ function genFactory (folder) { if (callback) return callback(err, result) return Promise.reject(err) } + + function snakeCaseKeys (acceptedQuerystring, snakeCase, querystring, warnings) { + var target = {} + var keys = Object.keys(querystring) + for (var i = 0, len = keys.length; i < len; i++) { + var key = keys[i] + target[snakeCase[key] || key] = querystring[key] + if (acceptedQuerystring.indexOf(snakeCase[key] || key) === -1) { + warnings.push('Client - Unknown parameter: "' + key + '", sending it as query parameter') + } + } + return target + } } // It's unlikely that a user needs all of our APIs, diff --git a/test/unit/events.test.js b/test/unit/events.test.js index 1312de932..7e5e11d69 100644 --- a/test/unit/events.test.js +++ b/test/unit/events.test.js @@ -53,15 +53,7 @@ test('Should emit a request event when a request is performed', t => { 'Content-Length': '0' } }, - options: { - ignore: null, - requestTimeout: null, - maxRetries: null, - asStream: false, - headers: null, - compression: false, - warnings: null - }, + options: {}, id: 1 }, connection: { @@ -114,15 +106,7 @@ test('Should emit a response event in case of a successful response', t => { 'Content-Length': '0' } }, - options: { - ignore: null, - requestTimeout: null, - maxRetries: null, - asStream: false, - headers: null, - compression: false, - warnings: null - }, + options: {}, id: 1 }, connection: { @@ -174,13 +158,7 @@ test('Should emit a response event with the error set', t => { } }, options: { - ignore: null, - requestTimeout: 500, - maxRetries: null, - asStream: false, - headers: null, - compression: false, - warnings: null + requestTimeout: 500 }, id: 1 },