Source: api/api/snapshot.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-Snapshot */
  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. 'wait_for_completion',
  43. 'verify',
  44. 'ignore_unavailable',
  45. 'index_details',
  46. 'include_repository',
  47. 'verbose',
  48. 'local',
  49. 'blob_count',
  50. 'concurrency',
  51. 'read_node_count',
  52. 'early_read_node_count',
  53. 'seed',
  54. 'rare_action_probability',
  55. 'max_blob_size',
  56. 'max_total_data_size',
  57. 'detailed',
  58. 'rarely_abort_writes',
  59. ];
  60. const snakeCase = {
  61. clusterManagerTimeout: 'cluster_manager_timeout',
  62. masterTimeout: 'master_timeout',
  63. errorTrace: 'error_trace',
  64. filterPath: 'filter_path',
  65. waitForCompletion: 'wait_for_completion',
  66. ignoreUnavailable: 'ignore_unavailable',
  67. indexDetails: 'index_details',
  68. includeRepository: 'include_repository',
  69. blobCount: 'blob_count',
  70. readNodeCount: 'read_node_count',
  71. earlyReadNodeCount: 'early_read_node_count',
  72. rareActionProbability: 'rare_action_probability',
  73. maxBlobSize: 'max_blob_size',
  74. maxTotalDataSize: 'max_total_data_size',
  75. rarelyAbortWrites: 'rarely_abort_writes',
  76. };
  77. function SnapshotApi(transport, ConfigurationError) {
  78. this.transport = transport;
  79. this[kConfigurationError] = ConfigurationError;
  80. }
  81. /**
  82. * Removes stale data from repository.
  83. *
  84. * @memberOf API-Snapshot
  85. *
  86. * @param {Object} params
  87. * @param {string} params.repository - A repository name
  88. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  89. * @param {string} [params.timeout] - Explicit operation timeout
  90. *
  91. * @param {Object} options - Options for {@link Transport#request}
  92. * @param {function} callback - Callback that handles errors and response
  93. *
  94. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  95. */
  96. SnapshotApi.prototype.cleanupRepository = function snapshotCleanupRepositoryApi(
  97. params,
  98. options,
  99. callback
  100. ) {
  101. [params, options, callback] = normalizeArguments(params, options, callback);
  102. // check required parameters
  103. if (params.repository == null) {
  104. const err = new this[kConfigurationError]('Missing required parameter: repository');
  105. return handleError(err, callback);
  106. }
  107. let { method, body, repository, ...querystring } = params;
  108. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  109. let path = '';
  110. if (method == null) method = 'POST';
  111. path = '/' + '_snapshot' + '/' + encodeURIComponent(repository) + '/' + '_cleanup';
  112. // build request object
  113. const request = {
  114. method,
  115. path,
  116. body: body || '',
  117. querystring,
  118. };
  119. return this.transport.request(request, options, callback);
  120. };
  121. /**
  122. * Clones indices from one snapshot into another snapshot in the same repository.
  123. *
  124. * @memberOf API-Snapshot
  125. *
  126. * @param {Object} params
  127. * @param {string} params.repository - A repository name
  128. * @param {string} params.snapshot - The name of the snapshot to clone from
  129. * @param {Object} params.body - The snapshot clone definition
  130. * @param {string} [params.target_snapshot] - The name of the cloned snapshot to create
  131. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  132. *
  133. * @param {Object} options - Options for {@link Transport#request}
  134. * @param {function} callback - Callback that handles errors and response
  135. *
  136. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  137. */
  138. SnapshotApi.prototype.clone = function snapshotCloneApi(params, options, callback) {
  139. [params, options, callback] = normalizeArguments(params, options, callback);
  140. // check required parameters
  141. if (params.repository == null) {
  142. const err = new this[kConfigurationError]('Missing required parameter: repository');
  143. return handleError(err, callback);
  144. }
  145. if (params.snapshot == null) {
  146. const err = new this[kConfigurationError]('Missing required parameter: snapshot');
  147. return handleError(err, callback);
  148. }
  149. if (params.target_snapshot == null && params.targetSnapshot == null) {
  150. const err = new this[kConfigurationError](
  151. 'Missing required parameter: target_snapshot or targetSnapshot'
  152. );
  153. return handleError(err, callback);
  154. }
  155. if (params.body == null) {
  156. const err = new this[kConfigurationError]('Missing required parameter: body');
  157. return handleError(err, callback);
  158. }
  159. // check required url components
  160. if (
  161. (params.target_snapshot != null || params.targetSnapshot != null) &&
  162. (params.snapshot == null || params.repository == null)
  163. ) {
  164. const err = new this[kConfigurationError](
  165. 'Missing required parameter of the url: snapshot, repository'
  166. );
  167. return handleError(err, callback);
  168. } else if (params.snapshot != null && params.repository == null) {
  169. const err = new this[kConfigurationError]('Missing required parameter of the url: repository');
  170. return handleError(err, callback);
  171. }
  172. let { method, body, repository, snapshot, targetSnapshot, target_snapshot, ...querystring } =
  173. params;
  174. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  175. let path = '';
  176. if (method == null) method = 'PUT';
  177. path =
  178. '/' +
  179. '_snapshot' +
  180. '/' +
  181. encodeURIComponent(repository) +
  182. '/' +
  183. encodeURIComponent(snapshot) +
  184. '/' +
  185. '_clone' +
  186. '/' +
  187. encodeURIComponent(target_snapshot || targetSnapshot);
  188. // build request object
  189. const request = {
  190. method,
  191. path,
  192. body: body || '',
  193. querystring,
  194. };
  195. return this.transport.request(request, options, callback);
  196. };
  197. /**
  198. * Creates a snapshot in a repository.
  199. *
  200. * @memberOf API-Snapshot
  201. *
  202. * @param {Object} params
  203. * @param {string} params.repository - A repository name
  204. * @param {string} params.snapshot - A snapshot name
  205. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  206. * @param {boolean} [params.wait_for_completion] - Should this request wait until the operation has completed before returning
  207. * @param {Object} [params.body] - The snapshot definition
  208. *
  209. * @param {Object} options - Options for {@link Transport#request}
  210. * @param {function} callback - Callback that handles errors and response
  211. *
  212. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  213. */
  214. SnapshotApi.prototype.create = function snapshotCreateApi(params, options, callback) {
  215. [params, options, callback] = normalizeArguments(params, options, callback);
  216. // check required parameters
  217. if (params.repository == null) {
  218. const err = new this[kConfigurationError]('Missing required parameter: repository');
  219. return handleError(err, callback);
  220. }
  221. if (params.snapshot == null) {
  222. const err = new this[kConfigurationError]('Missing required parameter: snapshot');
  223. return handleError(err, callback);
  224. }
  225. // check required url components
  226. if (params.snapshot != null && params.repository == null) {
  227. const err = new this[kConfigurationError]('Missing required parameter of the url: repository');
  228. return handleError(err, callback);
  229. }
  230. let { method, body, repository, snapshot, ...querystring } = params;
  231. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  232. let path = '';
  233. if (method == null) method = 'PUT';
  234. path =
  235. '/' + '_snapshot' + '/' + encodeURIComponent(repository) + '/' + encodeURIComponent(snapshot);
  236. // build request object
  237. const request = {
  238. method,
  239. path,
  240. body: body || '',
  241. querystring,
  242. };
  243. return this.transport.request(request, options, callback);
  244. };
  245. /**
  246. * Creates a repository.
  247. *
  248. * @memberOf API-Snapshot
  249. *
  250. * @param {Object} params
  251. * @param {string} params.repository - A repository name
  252. * @param {Object} params.body - The repository definition
  253. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  254. * @param {string} [params.timeout] - Explicit operation timeout
  255. * @param {boolean} [params.verify] - Whether to verify the repository after creation
  256. *
  257. * @param {Object} options - Options for {@link Transport#request}
  258. * @param {function} callback - Callback that handles errors and response
  259. *
  260. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  261. */
  262. SnapshotApi.prototype.createRepository = function snapshotCreateRepositoryApi(
  263. params,
  264. options,
  265. callback
  266. ) {
  267. [params, options, callback] = normalizeArguments(params, options, callback);
  268. // check required parameters
  269. if (params.repository == null) {
  270. const err = new this[kConfigurationError]('Missing required parameter: repository');
  271. return handleError(err, callback);
  272. }
  273. if (params.body == null) {
  274. const err = new this[kConfigurationError]('Missing required parameter: body');
  275. return handleError(err, callback);
  276. }
  277. let { method, body, repository, ...querystring } = params;
  278. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  279. let path = '';
  280. if (method == null) method = 'PUT';
  281. path = '/' + '_snapshot' + '/' + encodeURIComponent(repository);
  282. // build request object
  283. const request = {
  284. method,
  285. path,
  286. body: body || '',
  287. querystring,
  288. };
  289. return this.transport.request(request, options, callback);
  290. };
  291. /**
  292. * Deletes a snapshot.
  293. *
  294. * @memberOf API-Snapshot
  295. *
  296. * @param {Object} params
  297. * @param {string} [params.repository] - A repository name
  298. * @param {string} [params.snapshot] - A snapshot name
  299. * @param {string} [params.master_timeout] - (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
  300. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  301. *
  302. * @param {Object} options - Options for {@link Transport#request}
  303. * @param {function} callback - Callback that handles errors and response
  304. *
  305. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  306. */
  307. SnapshotApi.prototype.delete = function snapshotDeleteApi(params, options, callback) {
  308. [params, options, callback] = normalizeArguments(params, options, callback);
  309. // check required parameters
  310. if (params.repository == null) {
  311. const err = new this[kConfigurationError]('Missing required parameter: repository');
  312. return handleError(err, callback);
  313. }
  314. if (params.snapshot == null) {
  315. const err = new this[kConfigurationError]('Missing required parameter: snapshot');
  316. return handleError(err, callback);
  317. }
  318. // check required url components
  319. if (params.snapshot != null && params.repository == null) {
  320. const err = new this[kConfigurationError]('Missing required parameter of the url: repository');
  321. return handleError(err, callback);
  322. }
  323. let { method, body, repository, snapshot, ...querystring } = params;
  324. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  325. let path = '';
  326. if (method == null) method = 'DELETE';
  327. path =
  328. '/' + '_snapshot' + '/' + encodeURIComponent(repository) + '/' + encodeURIComponent(snapshot);
  329. // build request object
  330. const request = {
  331. method,
  332. path,
  333. body: body || '',
  334. querystring,
  335. };
  336. return this.transport.request(request, options, callback);
  337. };
  338. /**
  339. * Deletes a repository.
  340. *
  341. * @memberOf API-Snapshot
  342. *
  343. * @param {Object} params
  344. * @param {string} [params.repository] - Name of the snapshot repository to unregister. Wildcard (`*`) patterns are supported.
  345. * @param {string} [params.master_timeout] - (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
  346. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  347. * @param {string} [params.timeout] - Explicit operation timeout
  348. *
  349. * @param {Object} options - Options for {@link Transport#request}
  350. * @param {function} callback - Callback that handles errors and response
  351. *
  352. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  353. */
  354. SnapshotApi.prototype.deleteRepository = function snapshotDeleteRepositoryApi(
  355. params,
  356. options,
  357. callback
  358. ) {
  359. [params, options, callback] = normalizeArguments(params, options, callback);
  360. // check required parameters
  361. if (params.repository == null) {
  362. const err = new this[kConfigurationError]('Missing required parameter: repository');
  363. return handleError(err, callback);
  364. }
  365. let { method, body, repository, ...querystring } = params;
  366. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  367. let path = '';
  368. if (method == null) method = 'DELETE';
  369. path = '/' + '_snapshot' + '/' + encodeURIComponent(repository);
  370. // build request object
  371. const request = {
  372. method,
  373. path,
  374. body: body || '',
  375. querystring,
  376. };
  377. return this.transport.request(request, options, callback);
  378. };
  379. /**
  380. * Returns information about a snapshot.
  381. *
  382. * @memberOf API-Snapshot
  383. *
  384. * @param {Object} params
  385. * @param {string} [params.repository] - A repository name
  386. * @param {string} [params.snapshot] - A comma-separated list of snapshot names
  387. * @param {string} [params.master_timeout] - (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
  388. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  389. * @param {boolean} [params.ignore_unavailable] - Whether to ignore unavailable snapshots, defaults to false which means a SnapshotMissingException is thrown
  390. * @param {boolean} [params.index_details] - Whether to include details of each index in the snapshot, if those details are available. Defaults to false.
  391. * @param {boolean} [params.include_repository] - Whether to include the repository name in the snapshot info. Defaults to true.
  392. * @param {boolean} [params.verbose] - Whether to show verbose snapshot info or only show the basic info found in the repository index blob
  393. *
  394. * @param {Object} options - Options for {@link Transport#request}
  395. * @param {function} callback - Callback that handles errors and response
  396. *
  397. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  398. */
  399. SnapshotApi.prototype.get = function snapshotGetApi(params, options, callback) {
  400. [params, options, callback] = normalizeArguments(params, options, callback);
  401. // check required parameters
  402. if (params.repository == null) {
  403. const err = new this[kConfigurationError]('Missing required parameter: repository');
  404. return handleError(err, callback);
  405. }
  406. if (params.snapshot == null) {
  407. const err = new this[kConfigurationError]('Missing required parameter: snapshot');
  408. return handleError(err, callback);
  409. }
  410. // check required url components
  411. if (params.snapshot != null && params.repository == null) {
  412. const err = new this[kConfigurationError]('Missing required parameter of the url: repository');
  413. return handleError(err, callback);
  414. }
  415. let { method, body, repository, snapshot, ...querystring } = params;
  416. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  417. let path = '';
  418. if (method == null) method = 'GET';
  419. path =
  420. '/' + '_snapshot' + '/' + encodeURIComponent(repository) + '/' + encodeURIComponent(snapshot);
  421. // build request object
  422. const request = {
  423. method,
  424. path,
  425. body: null,
  426. querystring,
  427. };
  428. return this.transport.request(request, options, callback);
  429. };
  430. /**
  431. * Returns information about a snapshot.
  432. *
  433. * @memberOf API-Snapshot
  434. *
  435. * @param {Object} params
  436. * @param {string} [params.repository] - A comma-separated list of repository names
  437. * @param {string} [params.master_timeout] - (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to cluster_manager node
  438. * @param {boolean} [params.local] - Return local information, do not retrieve the state from cluster_manager node (default: false)
  439. *
  440. * @param {Object} options - Options for {@link Transport#request}
  441. * @param {function} callback - Callback that handles errors and response
  442. *
  443. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  444. */
  445. SnapshotApi.prototype.getRepository = function snapshotGetRepositoryApi(params, options, callback) {
  446. [params, options, callback] = normalizeArguments(params, options, callback);
  447. let { method, body, repository, ...querystring } = params;
  448. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  449. let path = '';
  450. if (repository != null) {
  451. if (method == null) method = 'GET';
  452. path = '/' + '_snapshot' + '/' + encodeURIComponent(repository);
  453. } else {
  454. if (method == null) method = 'GET';
  455. path = '/' + '_snapshot';
  456. }
  457. // build request object
  458. const request = {
  459. method,
  460. path,
  461. body: null,
  462. querystring,
  463. };
  464. return this.transport.request(request, options, callback);
  465. };
  466. /**
  467. * Analyzes a repository for correctness and performance
  468. *
  469. * @memberOf API-Snapshot
  470. *
  471. * @param {Object} params
  472. * @param {string} [params.repository] - A repository name
  473. * @param {number} [params.blob_count] - Number of blobs to create during the test. Defaults to 100.
  474. * @param {number} [params.concurrency] - Number of operations to run concurrently during the test. Defaults to 10.
  475. * @param {number} [params.read_node_count] - Number of nodes on which to read a blob after writing. Defaults to 10.
  476. * @param {number} [params.early_read_node_count] - Number of nodes on which to perform an early read on a blob, i.e. before writing has completed. Early reads are rare actions so the 'rare_action_probability' parameter is also relevant. Defaults to 2.
  477. * @param {number} [params.seed] - Seed for the random number generator used to create the test workload. Defaults to a random value.
  478. * @param {number} [params.rare_action_probability] - Probability of taking a rare action such as an early read or an overwrite. Defaults to 0.02.
  479. * @param {string} [params.max_blob_size] - Maximum size of a blob to create during the test, e.g '1gb' or '100mb'. Defaults to '10mb'.
  480. * @param {string} [params.max_total_data_size] - Maximum total size of all blobs to create during the test, e.g '1tb' or '100gb'. Defaults to '1gb'.
  481. * @param {string} [params.timeout] - Explicit operation timeout. Defaults to '30s'.
  482. * @param {boolean} [params.detailed] - Whether to return detailed results or a summary. Defaults to 'false' so that only the summary is returned.
  483. * @param {boolean} [params.rarely_abort_writes] - Whether to rarely abort writes before they complete. Defaults to 'true'.
  484. *
  485. * @param {Object} options - Options for {@link Transport#request}
  486. * @param {function} callback - Callback that handles errors and response
  487. *
  488. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  489. */
  490. SnapshotApi.prototype.repositoryAnalyze = function snapshotRepositoryAnalyzeApi(
  491. params,
  492. options,
  493. callback
  494. ) {
  495. [params, options, callback] = normalizeArguments(params, options, callback);
  496. // check required parameters
  497. if (params.repository == null) {
  498. const err = new this[kConfigurationError]('Missing required parameter: repository');
  499. return handleError(err, callback);
  500. }
  501. let { method, body, repository, ...querystring } = params;
  502. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  503. let path = '';
  504. if (method == null) method = 'POST';
  505. path = '/' + '_snapshot' + '/' + encodeURIComponent(repository) + '/' + '_analyze';
  506. // build request object
  507. const request = {
  508. method,
  509. path,
  510. body: body || '',
  511. querystring,
  512. };
  513. return this.transport.request(request, options, callback);
  514. };
  515. /**
  516. * Restores a snapshot.
  517. *
  518. * @memberOf API-Snapshot
  519. *
  520. * @param {Object} params
  521. * @param {string} [params.repository] - A repository name
  522. * @param {string} [params.snapshot] - A snapshot name
  523. * @param {string} [params.master_timeout] - (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
  524. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  525. * @param {boolean} [params.wait_for_completion] - Should this request wait until the operation has completed before returning
  526. * @param {Object} [params.body] - Details of what to restore
  527. *
  528. * @param {Object} options - Options for {@link Transport#request}
  529. * @param {function} callback - Callback that handles errors and response
  530. *
  531. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  532. */
  533. SnapshotApi.prototype.restore = function snapshotRestoreApi(params, options, callback) {
  534. [params, options, callback] = normalizeArguments(params, options, callback);
  535. // check required parameters
  536. if (params.repository == null) {
  537. const err = new this[kConfigurationError]('Missing required parameter: repository');
  538. return handleError(err, callback);
  539. }
  540. if (params.snapshot == null) {
  541. const err = new this[kConfigurationError]('Missing required parameter: snapshot');
  542. return handleError(err, callback);
  543. }
  544. // check required url components
  545. if (params.snapshot != null && params.repository == null) {
  546. const err = new this[kConfigurationError]('Missing required parameter of the url: repository');
  547. return handleError(err, callback);
  548. }
  549. let { method, body, repository, snapshot, ...querystring } = params;
  550. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  551. let path = '';
  552. if (method == null) method = 'POST';
  553. path =
  554. '/' +
  555. '_snapshot' +
  556. '/' +
  557. encodeURIComponent(repository) +
  558. '/' +
  559. encodeURIComponent(snapshot) +
  560. '/' +
  561. '_restore';
  562. // build request object
  563. const request = {
  564. method,
  565. path,
  566. body: body || '',
  567. querystring,
  568. };
  569. return this.transport.request(request, options, callback);
  570. };
  571. /**
  572. * Returns information about the status of a snapshot.
  573. *
  574. * @memberOf API-Snapshot
  575. *
  576. * @param {Object} params
  577. * @param {string} [params.repository] - A repository name
  578. * @param {string} [params.snapshot] - A comma-separated list of snapshot names
  579. * @param {string} [params.master_timeout] - (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
  580. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  581. * @param {boolean} [params.ignore_unavailable] - Whether to ignore unavailable snapshots, defaults to false which means a SnapshotMissingException is thrown
  582. *
  583. * @param {Object} options - Options for {@link Transport#request}
  584. * @param {function} callback - Callback that handles errors and response
  585. *
  586. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  587. */
  588. SnapshotApi.prototype.status = function snapshotStatusApi(params, options, callback) {
  589. [params, options, callback] = normalizeArguments(params, options, callback);
  590. // check required url components
  591. if (params.snapshot != null && params.repository == null) {
  592. const err = new this[kConfigurationError]('Missing required parameter of the url: repository');
  593. return handleError(err, callback);
  594. }
  595. let { method, body, repository, snapshot, ...querystring } = params;
  596. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  597. let path = '';
  598. if (repository != null && snapshot != null) {
  599. if (method == null) method = 'GET';
  600. path =
  601. '/' +
  602. '_snapshot' +
  603. '/' +
  604. encodeURIComponent(repository) +
  605. '/' +
  606. encodeURIComponent(snapshot) +
  607. '/' +
  608. '_status';
  609. } else if (repository != null) {
  610. if (method == null) method = 'GET';
  611. path = '/' + '_snapshot' + '/' + encodeURIComponent(repository) + '/' + '_status';
  612. } else {
  613. if (method == null) method = 'GET';
  614. path = '/' + '_snapshot' + '/' + '_status';
  615. }
  616. // build request object
  617. const request = {
  618. method,
  619. path,
  620. body: null,
  621. querystring,
  622. };
  623. return this.transport.request(request, options, callback);
  624. };
  625. /**
  626. * Verifies a repository.
  627. *
  628. * @memberOf API-Snapshot
  629. *
  630. * @param {Object} params
  631. * @param {string} [params.repository] - A repository name
  632. * @param {string} [params.master_timeout] - (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node
  633. * @param {string} [params.cluster_manager_timeout] - Explicit operation timeout for connection to cluster_manager node
  634. * @param {string} [params.timeout] - Explicit operation timeout
  635. *
  636. * @param {Object} options - Options for {@link Transport#request}
  637. * @param {function} callback - Callback that handles errors and response
  638. *
  639. * @returns {{abort: function(), then: function(), catch: function()}|Promise<never>|*}
  640. */
  641. SnapshotApi.prototype.verifyRepository = function snapshotVerifyRepositoryApi(
  642. params,
  643. options,
  644. callback
  645. ) {
  646. [params, options, callback] = normalizeArguments(params, options, callback);
  647. // check required parameters
  648. if (params.repository == null) {
  649. const err = new this[kConfigurationError]('Missing required parameter: repository');
  650. return handleError(err, callback);
  651. }
  652. let { method, body, repository, ...querystring } = params;
  653. querystring = snakeCaseKeys(acceptedQuerystring, snakeCase, querystring);
  654. let path = '';
  655. if (method == null) method = 'POST';
  656. path = '/' + '_snapshot' + '/' + encodeURIComponent(repository) + '/' + '_verify';
  657. // build request object
  658. const request = {
  659. method,
  660. path,
  661. body: body || '',
  662. querystring,
  663. };
  664. return this.transport.request(request, options, callback);
  665. };
  666. Object.defineProperties(SnapshotApi.prototype, {
  667. cleanup_repository: {
  668. get() {
  669. return this.cleanupRepository;
  670. },
  671. },
  672. create_repository: {
  673. get() {
  674. return this.createRepository;
  675. },
  676. },
  677. delete_repository: {
  678. get() {
  679. return this.deleteRepository;
  680. },
  681. },
  682. get_repository: {
  683. get() {
  684. return this.getRepository;
  685. },
  686. },
  687. repository_analyze: {
  688. get() {
  689. return this.repositoryAnalyze;
  690. },
  691. },
  692. verify_repository: {
  693. get() {
  694. return this.verifyRepository;
  695. },
  696. },
  697. });
  698. module.exports = SnapshotApi;