Source: api/api/delete_script.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. const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
  32. const acceptedQuerystring = [
  33. 'timeout',
  34. 'cluster_manager_timeout',
  35. 'master_timeout',
  36. 'pretty',
  37. 'human',
  38. 'error_trace',
  39. 'source',
  40. 'filter_path',
  41. ];
  42. const snakeCase = {
  43. clusterManagerTimeout: 'cluster_manager_timeout',
  44. masterTimeout: 'master_timeout',
  45. errorTrace: 'error_trace',
  46. filterPath: 'filter_path',
  47. };
  48. /**
  49. * Delete a stored script.
  50. * @memberOf API-Script
  51. *
  52. * @param {Object} params
  53. * @param {string} params.id - Stored script or search template name
  54. * @param {string} [params.timeout=30s] - Explicit operation timeout
  55. * @param {string} [params.cluster_manager_timeout] - Specify timeout for connection to cluster_manager
  56. *
  57. * @param {Object} [options] - Options for {@link Transport#request}
  58. * @param {function} [callback] - Callback that handles errors and response
  59. *
  60. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  61. */
  62. function deleteScriptApi(params, options, callback) {
  63. [params, options, callback] = normalizeArguments(params, options, callback);
  64. // check required parameters
  65. if (params.id == null) {
  66. const err = new this[kConfigurationError]('Missing required parameter: id');
  67. return handleError(err, callback);
  68. }
  69. let { method, body, id, ...querystring } = params;
  70. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  71. let path = '';
  72. if (method == null) method = 'DELETE';
  73. path = '/' + '_scripts' + '/' + encodeURIComponent(id);
  74. // build request object
  75. const request = {
  76. method,
  77. path,
  78. body: body || '',
  79. querystring,
  80. };
  81. return this.transport.request(request, options, callback);
  82. }
  83. module.exports = deleteScriptApi;