Source: api/api/features.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-Features */
  32. const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils');
  33. const acceptedQuerystring = [
  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. function FeaturesApi(transport, ConfigurationError) {
  49. this.transport = transport;
  50. this[kConfigurationError] = ConfigurationError;
  51. }
  52. /**
  53. * Gets a list of features
  54. * @memberOf API-Features
  55. *
  56. * @param {Object} params
  57. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  58. *
  59. * @param {Object} [options] - Options for {@link Transport#request}
  60. * @param {function} [callback] - Callback that handles errors and response
  61. *
  62. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  63. */
  64. FeaturesApi.prototype.getFeatures = function featuresGetFeaturesApi(params, options, callback) {
  65. [params, options, callback] = normalizeArguments(params, options, callback);
  66. let { method, body, ...querystring } = params;
  67. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  68. let path = '';
  69. if (method == null) method = 'GET';
  70. path = '/' + '_features';
  71. // build request object
  72. const request = {
  73. method,
  74. path,
  75. body: null,
  76. querystring,
  77. };
  78. return this.transport.request(request, options, callback);
  79. };
  80. /**
  81. * Resets the internal state of features, usually by deleting system indices
  82. * @memberOf API-Features
  83. *
  84. * @param {Object} params - (Unused)
  85. * @param {Object} [options] - Options for {@link Transport#request}
  86. * @param {function} [callback] - Callback that handles errors and response
  87. *
  88. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  89. */
  90. FeaturesApi.prototype.resetFeatures = function featuresResetFeaturesApi(params, options, callback) {
  91. [params, options, callback] = normalizeArguments(params, options, callback);
  92. let { method, body, ...querystring } = params;
  93. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  94. let path = '';
  95. if (method == null) method = 'POST';
  96. path = '/' + '_features' + '/' + '_reset';
  97. // build request object
  98. const request = {
  99. method,
  100. path,
  101. body: body || '',
  102. querystring,
  103. };
  104. return this.transport.request(request, options, callback);
  105. };
  106. Object.defineProperties(FeaturesApi.prototype, {
  107. get_features: {
  108. get() {
  109. return this.getFeatures;
  110. },
  111. },
  112. reset_features: {
  113. get() {
  114. return this.resetFeatures;
  115. },
  116. },
  117. });
  118. module.exports = FeaturesApi;