Source: api/api/ingest.js

  1. /*
  2. * Copyright OpenSearch Contributors
  3. * SPDX-License-Identifier: Apache-2.0
  4. *
  5. * The OpenSearch Contributors require contributions made to
  6. * this file be licensed under the Apache-2.0 license or a
  7. * compatible open source license.
  8. *
  9. */
  10. /*
  11. * Licensed to Elasticsearch B.V. under one or more contributor
  12. * license agreements. See the NOTICE file distributed with
  13. * this work for additional information regarding copyright
  14. * ownership. Elasticsearch B.V. licenses this file to you under
  15. * the Apache License, Version 2.0 (the "License"); you may
  16. * not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at
  18. *
  19. * http://www.apache.org/licenses/LICENSE-2.0
  20. *
  21. * Unless required by applicable law or agreed to in writing,
  22. * software distributed under the License is distributed on an
  23. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24. * KIND, either express or implied. See the License for the
  25. * specific language governing permissions and limitations
  26. * under the License.
  27. */
  28. 'use strict';
  29. /* eslint camelcase: 0 */
  30. /* eslint no-unused-vars: 0 */
  31. /** @namespace API-Ingest */
  32. const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
  33. const acceptedQuerystring = [
  34. 'cluster_manager_timeout',
  35. 'master_timeout',
  36. 'timeout',
  37. 'pretty',
  38. 'human',
  39. 'error_trace',
  40. 'source',
  41. 'filter_path',
  42. 'summary',
  43. 'verbose',
  44. ];
  45. const snakeCase = {
  46. clusterManagerTimeout: 'cluster_manager_timeout',
  47. masterTimeout: 'master_timeout',
  48. errorTrace: 'error_trace',
  49. filterPath: 'filter_path',
  50. };
  51. function IngestApi(transport, ConfigurationError) {
  52. this.transport = transport;
  53. this[kConfigurationError] = ConfigurationError;
  54. }
  55. /**
  56. * Deletes a pipeline.
  57. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/ingest-apis/delete-ingest/ OpenSearch - Delete a pipeline}
  58. *
  59. * @memberOf API-Ingest
  60. *
  61. * @param {Object} params
  62. * @param {string} params.id - Pipeline ID
  63. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  64. * @param {string} [params.timeout] - Explicit operation timeout
  65. *
  66. * @param {Object} options - Options for {@link Transport#request}
  67. * @param {function} callback - Callback that handles errors and response
  68. *
  69. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*} {@link https://opensearch.org/docs/latest/api-reference/ingest-apis/delete-ingest/#response Delete Pipeline Response}
  70. */
  71. IngestApi.prototype.deletePipeline = function ingestDeletePipelineApi(params, options, callback) {
  72. [params, options, callback] = normalizeArguments(params, options, callback);
  73. // check required parameters
  74. if (params.id == null) {
  75. const err = new this[kConfigurationError]('Missing required parameter: id');
  76. return handleError(err, callback);
  77. }
  78. let { method, body, id, ...querystring } = params;
  79. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  80. let path = '';
  81. if (method == null) method = 'DELETE';
  82. path = '/' + '_ingest' + '/' + 'pipeline' + '/' + encodeURIComponent(id);
  83. // build request object
  84. const request = {
  85. method,
  86. path,
  87. body: body || '',
  88. querystring,
  89. };
  90. return this.transport.request(request, options, callback);
  91. };
  92. /**
  93. * Returns statistical information about geoip databases
  94. *
  95. * @memberOf API-Ingest
  96. *
  97. * @param {Object} params - (Unused)
  98. * @param {Object} options - Options for {@link Transport#request}
  99. * @param {function} callback - Callback that handles errors and response
  100. *
  101. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  102. */
  103. IngestApi.prototype.geoIpStats = function ingestGeoIpStatsApi(params, options, callback) {
  104. [params, options, callback] = normalizeArguments(params, options, callback);
  105. let { method, body, ...querystring } = params;
  106. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  107. let path = '';
  108. if (method == null) method = 'GET';
  109. path = '/' + '_ingest' + '/' + 'geoip' + '/' + 'stats';
  110. // build request object
  111. const request = {
  112. method,
  113. path,
  114. body: null,
  115. querystring,
  116. };
  117. return this.transport.request(request, options, callback);
  118. };
  119. /**
  120. * Returns a pipeline.
  121. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/ingest-apis/get-ingest/ OpenSearch - Get pipeline}
  122. *
  123. * @memberOf API-Ingest
  124. *
  125. * @param {Object} params
  126. * @param {string} [params.id] - Comma separated list of pipeline ids. Wildcards supported
  127. * @param {boolean} [params.summary=false] - Return pipelines without their definitions
  128. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  129. *
  130. * @param {Object} options - Options for {@link Transport#request}
  131. * @param {function} callback - Callback that handles errors and response
  132. *
  133. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*} {@link https://opensearch.org/docs/latest/api-reference/ingest-apis/get-ingest/#response Get Pipeline Response}
  134. */
  135. IngestApi.prototype.getPipeline = function ingestGetPipelineApi(params, options, callback) {
  136. [params, options, callback] = normalizeArguments(params, options, callback);
  137. let { method, body, id, ...querystring } = params;
  138. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  139. let path = '';
  140. if (id != null) {
  141. if (method == null) method = 'GET';
  142. path = '/' + '_ingest' + '/' + 'pipeline' + '/' + encodeURIComponent(id);
  143. } else {
  144. if (method == null) method = 'GET';
  145. path = '/' + '_ingest' + '/' + 'pipeline';
  146. }
  147. // build request object
  148. const request = {
  149. method,
  150. path,
  151. body: null,
  152. querystring,
  153. };
  154. return this.transport.request(request, options, callback);
  155. };
  156. /**
  157. * Returns a list of the built-in patterns.
  158. *
  159. * @memberOf API-Ingest
  160. *
  161. * @param {Object} params - (Unused)
  162. * @param {Object} options - Options for {@link Transport#request}
  163. * @param {function} callback - Callback that handles errors and response
  164. *
  165. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  166. */
  167. IngestApi.prototype.processorGrok = function ingestProcessorGrokApi(params, options, callback) {
  168. [params, options, callback] = normalizeArguments(params, options, callback);
  169. let { method, body, ...querystring } = params;
  170. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  171. let path = '';
  172. if (method == null) method = 'GET';
  173. path = '/' + '_ingest' + '/' + 'processor' + '/' + 'grok';
  174. // build request object
  175. const request = {
  176. method,
  177. path,
  178. body: null,
  179. querystring,
  180. };
  181. return this.transport.request(request, options, callback);
  182. };
  183. /**
  184. * Creates or updates a pipeline.
  185. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/ingest-apis/create-update-ingest/ OpenSearch - Create/Update pipeline}
  186. *
  187. * @memberOf API-Ingest
  188. *
  189. * @param {Object} params
  190. * @param {string} params.id - Pipeline ID
  191. * @param {Object} params.body - Ingest definition
  192. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  193. * @param {string} [params.timeout] - Explicit operation timeout
  194. *
  195. * @param {Object} options - Options for {@link Transport#request}
  196. * @param {function} callback - Callback that handles errors and response
  197. *
  198. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*} {@link https://opensearch.org/docs/latest/api-reference/ingest-apis/create-update-ingest/#response Create/Update Pipeline Response}
  199. */
  200. IngestApi.prototype.putPipeline = function ingestPutPipelineApi(params, options, callback) {
  201. [params, options, callback] = normalizeArguments(params, options, callback);
  202. // check required parameters
  203. if (params.id == null) {
  204. const err = new this[kConfigurationError]('Missing required parameter: id');
  205. return handleError(err, callback);
  206. }
  207. if (params.body == null) {
  208. const err = new this[kConfigurationError]('Missing required parameter: body');
  209. return handleError(err, callback);
  210. }
  211. let { method, body, id, ...querystring } = params;
  212. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  213. let path = '';
  214. if (method == null) method = 'PUT';
  215. path = '/' + '_ingest' + '/' + 'pipeline' + '/' + encodeURIComponent(id);
  216. // build request object
  217. const request = {
  218. method,
  219. path,
  220. body: body || '',
  221. querystring,
  222. };
  223. return this.transport.request(request, options, callback);
  224. };
  225. /**
  226. * Allows to simulate a pipeline with example documents.
  227. * <br/> See Also: {@link https://opensearch.org/docs/latest/api-reference/ingest-apis/simulate-ingest/ OpenSearch - Simulate Pipeline}
  228. *
  229. * @memberOf API-Ingest
  230. *
  231. * @param {Object} params
  232. * @param {string} [params.id] - Pipeline ID
  233. * @param {boolean} [params.verbose] - Verbose mode. Display data output for each processor in executed pipeline
  234. * @param {Object} params.body - Simulate definition
  235. *
  236. * @param {Object} options - Options for {@link Transport#request}
  237. * @param {function} callback - Callback that handles errors and response
  238. *
  239. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  240. */
  241. IngestApi.prototype.simulate = function ingestSimulateApi(params, options, callback) {
  242. [params, options, callback] = normalizeArguments(params, options, callback);
  243. // check required parameters
  244. if (params.body == null) {
  245. const err = new this[kConfigurationError]('Missing required parameter: body');
  246. return handleError(err, callback);
  247. }
  248. let { method, body, id, ...querystring } = params;
  249. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  250. let path = '';
  251. if (id != null) {
  252. if (method == null) method = body == null ? 'GET' : 'POST';
  253. path = '/' + '_ingest' + '/' + 'pipeline' + '/' + encodeURIComponent(id) + '/' + '_simulate';
  254. } else {
  255. if (method == null) method = body == null ? 'GET' : 'POST';
  256. path = '/' + '_ingest' + '/' + 'pipeline' + '/' + '_simulate';
  257. }
  258. // build request object
  259. const request = {
  260. method,
  261. path,
  262. body: body || '',
  263. querystring,
  264. };
  265. return this.transport.request(request, options, callback);
  266. };
  267. Object.defineProperties(IngestApi.prototype, {
  268. delete_pipeline: {
  269. get() {
  270. return this.deletePipeline;
  271. },
  272. },
  273. geo_ip_stats: {
  274. get() {
  275. return this.geoIpStats;
  276. },
  277. },
  278. get_pipeline: {
  279. get() {
  280. return this.getPipeline;
  281. },
  282. },
  283. processor_grok: {
  284. get() {
  285. return this.processorGrok;
  286. },
  287. },
  288. put_pipeline: {
  289. get() {
  290. return this.putPipeline;
  291. },
  292. },
  293. });
  294. module.exports = IngestApi;