@opensearch-project/opensearch 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.eslintrc.json +9 -4
  2. package/ADMINS.md +13 -38
  3. package/CHANGELOG.md +24 -0
  4. package/COMPATIBILITY.md +4 -1
  5. package/MAINTAINERS.md +15 -75
  6. package/Makefile +2 -12
  7. package/README.md +4 -107
  8. package/USER_GUIDE.md +197 -0
  9. package/api/api/bulk.js +1 -2
  10. package/api/api/cat.js +1 -2
  11. package/api/api/clear_scroll.js +1 -2
  12. package/api/api/cluster.js +1 -2
  13. package/api/api/count.js +1 -2
  14. package/api/api/create.js +1 -2
  15. package/api/api/dangling_indices.js +1 -2
  16. package/api/api/delete.js +1 -2
  17. package/api/api/delete_by_query.js +1 -2
  18. package/api/api/delete_by_query_rethrottle.js +1 -2
  19. package/api/api/delete_script.js +1 -2
  20. package/api/api/exists.js +1 -2
  21. package/api/api/exists_source.js +1 -2
  22. package/api/api/explain.js +1 -2
  23. package/api/api/features.js +1 -2
  24. package/api/api/field_caps.js +1 -2
  25. package/api/api/get.js +1 -2
  26. package/api/api/get_script.js +1 -2
  27. package/api/api/get_script_context.js +1 -2
  28. package/api/api/get_script_languages.js +1 -2
  29. package/api/api/get_source.js +1 -2
  30. package/api/api/index.js +1 -2
  31. package/api/api/indices.js +1 -2
  32. package/api/api/info.js +1 -2
  33. package/api/api/ingest.js +1 -2
  34. package/api/api/mget.js +1 -2
  35. package/api/api/msearch.js +1 -2
  36. package/api/api/msearch_template.js +1 -2
  37. package/api/api/mtermvectors.js +1 -2
  38. package/api/api/nodes.js +1 -2
  39. package/api/api/ping.js +1 -2
  40. package/api/api/put_script.js +1 -2
  41. package/api/api/rank_eval.js +1 -2
  42. package/api/api/reindex.js +1 -2
  43. package/api/api/reindex_rethrottle.js +1 -2
  44. package/api/api/render_search_template.js +1 -2
  45. package/api/api/scripts_painless_execute.js +1 -2
  46. package/api/api/scroll.js +1 -2
  47. package/api/api/search.js +1 -2
  48. package/api/api/search_shards.js +1 -2
  49. package/api/api/search_template.js +1 -2
  50. package/api/api/shutdown.js +1 -2
  51. package/api/api/snapshot.js +1 -2
  52. package/api/api/tasks.js +1 -2
  53. package/api/api/terms_enum.js +1 -2
  54. package/api/api/termvectors.js +1 -2
  55. package/api/api/update.js +1 -2
  56. package/api/api/update_by_query.js +1 -2
  57. package/api/api/update_by_query_rethrottle.js +1 -2
  58. package/api/index.js +1 -2
  59. package/api/new.d.ts +1 -2
  60. package/api/opensearch_dashboards.d.ts +1 -2
  61. package/api/requestParams.d.ts +1 -2
  62. package/api/types.d.ts +1 -2
  63. package/api/utils.js +1 -2
  64. package/index.d.ts +445 -120
  65. package/index.js +2 -3
  66. package/index.mjs +1 -2
  67. package/jenkins/release.JenkinsFile +11 -0
  68. package/lib/Connection.d.ts +1 -2
  69. package/lib/Connection.js +5 -4
  70. package/lib/Helpers.d.ts +5 -4
  71. package/lib/Helpers.js +13 -17
  72. package/lib/Serializer.d.ts +1 -2
  73. package/lib/Serializer.js +1 -2
  74. package/lib/Transport.d.ts +10 -4
  75. package/lib/Transport.js +11 -6
  76. package/lib/aws/AwsSigv4Signer.js +167 -0
  77. package/lib/aws/errors.js +24 -0
  78. package/lib/aws/index.d.ts +39 -0
  79. package/lib/aws/index.js +19 -0
  80. package/lib/errors.d.ts +1 -2
  81. package/lib/errors.js +1 -2
  82. package/lib/pool/BaseConnectionPool.js +1 -2
  83. package/lib/pool/CloudConnectionPool.js +1 -2
  84. package/lib/pool/ConnectionPool.js +1 -2
  85. package/lib/pool/index.d.ts +1 -2
  86. package/lib/pool/index.js +1 -2
  87. package/package.json +27 -10
package/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -286,7 +285,7 @@ class Client extends OpenSearchAPI {
286
285
 
287
286
  close(callback) {
288
287
  if (callback == null) {
289
- return new Promise((resolve, reject) => {
288
+ return new Promise((resolve) => {
290
289
  this.close(resolve);
291
290
  });
292
291
  }
package/index.mjs CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -0,0 +1,11 @@
1
+ lib = library(identifier: 'jenkins@1.1.0', retriever: modernSCM([
2
+ $class: 'GitSCMSource',
3
+ remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
4
+ ]))
5
+
6
+ standardReleasePipelineWithGenericTrigger(
7
+ tokenIdCredential: 'jenkins-opensearch-js-generic-webhook-token',
8
+ causeString: 'A tag was cut on opensearch-project/opensearch-js repository causing this workflow to run',
9
+ publishRelease: true){
10
+ publishToNpm(repository: 'https://github.com/opensearch-project/opensearch-js', tag: "$tag")
11
+ }
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
package/lib/Connection.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -218,7 +217,7 @@ class Connection {
218
217
  origin: url.origin,
219
218
  // https://github.com/elastic/elasticsearch-js/issues/843
220
219
  port: url.port !== '' ? url.port : undefined,
221
- headers: this.headers,
220
+ headers: Object.assign({}, this.headers),
222
221
  agent: this.agent,
223
222
  };
224
223
 
@@ -249,7 +248,8 @@ class Connection {
249
248
  // We want to hide `auth`, `agent` and `ssl` since they made
250
249
  // the logs very hard to read. The user can still
251
250
  // access them with `instance.agent` and `instance.ssl`.
252
- [inspect.custom](depth, options) {
251
+ [inspect.custom]() {
252
+ // eslint-disable-next-line no-unused-vars
253
253
  const { authorization, ...headers } = this.headers;
254
254
 
255
255
  return {
@@ -265,6 +265,7 @@ class Connection {
265
265
  }
266
266
 
267
267
  toJSON() {
268
+ // eslint-disable-next-line no-unused-vars
268
269
  const { authorization, ...headers } = this.headers;
269
270
 
270
271
  return {
package/lib/Helpers.d.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -82,14 +81,14 @@ export interface BulkStats {
82
81
  aborted: boolean;
83
82
  }
84
83
 
85
- interface IndexAction {
84
+ interface IndexActionOperation {
86
85
  index: {
87
86
  _index: string;
88
87
  [key: string]: any;
89
88
  };
90
89
  }
91
90
 
92
- interface CreateAction {
91
+ interface CreateActionOperation {
93
92
  create: {
94
93
  _index: string;
95
94
  [key: string]: any;
@@ -110,6 +109,8 @@ interface DeleteAction {
110
109
  };
111
110
  }
112
111
 
112
+ type CreateAction = CreateActionOperation | [CreateActionOperation, unknown];
113
+ type IndexAction = IndexActionOperation | [IndexActionOperation, unknown];
113
114
  type UpdateAction = [UpdateActionOperation, Record<string, any>];
114
115
  type Action = IndexAction | CreateAction | UpdateAction | DeleteAction;
115
116
  type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
package/lib/Helpers.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -97,7 +96,6 @@ class Helpers {
97
96
  }
98
97
  params.scroll = params.scroll || '1m';
99
98
  appendFilterPath('_scroll_id', params, false);
100
- const { method, body, index, ...querystring } = params;
101
99
 
102
100
  let response = null;
103
101
  for (let i = 0; i <= maxRetries; i++) {
@@ -132,9 +130,8 @@ class Helpers {
132
130
  for (let i = 0; i <= maxRetries; i++) {
133
131
  response = await this[kClient].scroll(
134
132
  {
135
- scroll: querystring.scroll,
136
- rest_total_hits_as_int:
137
- querystring.rest_total_hits_as_int || querystring.restTotalHitsAsInt,
133
+ scroll: params.scroll,
134
+ rest_total_hits_as_int: params.rest_total_hits_as_int || params.restTotalHitsAsInt,
138
135
  body: { scroll_id },
139
136
  },
140
137
  options
@@ -199,7 +196,7 @@ class Helpers {
199
196
  let timeoutRef = null;
200
197
  const operationsStream = new Readable({
201
198
  objectMode: true,
202
- read(size) {},
199
+ read() {},
203
200
  });
204
201
 
205
202
  const p = iterate();
@@ -332,7 +329,7 @@ class Helpers {
332
329
  return { semaphore, finish };
333
330
 
334
331
  function finish() {
335
- return new Promise((resolve, reject) => {
332
+ return new Promise((resolve) => {
336
333
  if (running === 0) {
337
334
  resolve();
338
335
  } else {
@@ -346,7 +343,7 @@ class Helpers {
346
343
  running += 1;
347
344
  return pImmediate(send);
348
345
  } else {
349
- return new Promise((resolve, reject) => {
346
+ return new Promise((resolve) => {
350
347
  resolveSemaphore = resolve;
351
348
  });
352
349
  }
@@ -532,21 +529,20 @@ class Helpers {
532
529
  for await (const chunk of datasource) {
533
530
  if (shouldAbort === true) break;
534
531
  timeoutRef.refresh();
535
- const action = onDocument(chunk);
536
- const operation = Array.isArray(action)
537
- ? Object.keys(action[0])[0]
538
- : Object.keys(action)[0];
532
+ const result = onDocument(chunk);
533
+ const [action, payload] = Array.isArray(result) ? result : [result, chunk];
534
+ const operation = Object.keys(action)[0];
539
535
  if (operation === 'index' || operation === 'create') {
540
536
  actionBody = serializer.serialize(action);
541
- payloadBody = typeof chunk === 'string' ? chunk : serializer.serialize(chunk);
537
+ payloadBody = typeof payload === 'string' ? payload : serializer.serialize(payload);
542
538
  chunkBytes += Buffer.byteLength(actionBody) + Buffer.byteLength(payloadBody);
543
539
  bulkBody.push(actionBody, payloadBody);
544
540
  } else if (operation === 'update') {
545
- actionBody = serializer.serialize(action[0]);
541
+ actionBody = serializer.serialize(action);
546
542
  payloadBody =
547
543
  typeof chunk === 'string'
548
544
  ? `{"doc":${chunk}}`
549
- : serializer.serialize({ doc: chunk, ...action[1] });
545
+ : serializer.serialize({ doc: chunk, ...payload });
550
546
  chunkBytes += Buffer.byteLength(actionBody) + Buffer.byteLength(payloadBody);
551
547
  bulkBody.push(actionBody, payloadBody);
552
548
  } else if (operation === 'delete') {
@@ -649,7 +645,7 @@ class Helpers {
649
645
  running += 1;
650
646
  return pImmediate(send);
651
647
  } else {
652
- return new Promise((resolve, reject) => {
648
+ return new Promise((resolve) => {
653
649
  resolveSemaphore = resolve;
654
650
  });
655
651
  }
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
package/lib/Serializer.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -29,10 +28,10 @@
29
28
  */
30
29
 
31
30
  import { Readable as ReadableStream } from 'stream';
32
- import { ConnectionPool, CloudConnectionPool } from './pool';
33
31
  import Connection from './Connection';
34
- import Serializer from './Serializer';
35
32
  import * as errors from './errors';
33
+ import { CloudConnectionPool, ConnectionPool } from './pool';
34
+ import Serializer from './Serializer';
36
35
 
37
36
  export type ApiError =
38
37
  | errors.ConfigurationError
@@ -59,6 +58,11 @@ export interface generateRequestIdFn {
59
58
  (params: TransportRequestParams, options: TransportRequestOptions): any;
60
59
  }
61
60
 
61
+ export interface MemoryCircuitBreakerOptions {
62
+ enabled: boolean;
63
+ maxPercentage: number;
64
+ }
65
+
62
66
  interface TransportOptions {
63
67
  emit: (event: string | symbol, ...args: any[]) => boolean;
64
68
  connectionPool: ConnectionPool | CloudConnectionPool;
@@ -77,6 +81,7 @@ interface TransportOptions {
77
81
  generateRequestId?: generateRequestIdFn;
78
82
  name?: string;
79
83
  opaqueIdPrefix?: string;
84
+ memoryCircuitBreaker?: MemoryCircuitBreakerOptions;
80
85
  }
81
86
 
82
87
  export interface RequestEvent<TResponse = Record<string, any>, TContext = Context> {
@@ -172,6 +177,7 @@ export default class Transport {
172
177
  sniffInterval: number;
173
178
  sniffOnConnectionFault: boolean;
174
179
  opaqueIdPrefix: string | null;
180
+ memoryCircuitBreaker: MemoryCircuitBreakerOptions | undefined;
175
181
  sniffEndpoint: string;
176
182
  _sniffEnabled: boolean;
177
183
  _nextSniff: number;
package/lib/Transport.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -182,10 +181,14 @@ class Transport {
182
181
  let request = { abort: noop };
183
182
  const transportReturn = {
184
183
  then(onFulfilled, onRejected) {
185
- return p.then(onFulfilled, onRejected);
184
+ if (p != null) {
185
+ return p.then(onFulfilled, onRejected);
186
+ }
186
187
  },
187
188
  catch(onRejected) {
188
- return p.catch(onRejected);
189
+ if (p != null) {
190
+ return p.catch(onRejected);
191
+ }
189
192
  },
190
193
  abort() {
191
194
  meta.aborted = true;
@@ -194,7 +197,9 @@ class Transport {
194
197
  return this;
195
198
  },
196
199
  finally(onFinally) {
197
- return p.finally(onFinally);
200
+ if (p != null) {
201
+ return p.finally(onFinally);
202
+ }
198
203
  },
199
204
  };
200
205
 
@@ -676,7 +681,7 @@ function randomSelector(connections) {
676
681
  function generateRequestId() {
677
682
  const maxInt = 2147483647;
678
683
  let nextReqId = 0;
679
- return function genReqId(params, options) {
684
+ return function genReqId() {
680
685
  return (nextReqId = (nextReqId + 1) & maxInt);
681
686
  };
682
687
  }
@@ -0,0 +1,167 @@
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
+ 'use strict';
12
+ const Connection = require('../Connection');
13
+ const Transport = require('../Transport');
14
+ const aws4 = require('aws4');
15
+ const AwsSigv4SignerError = require('./errors');
16
+
17
+ const getAwsSDKCredentialsProvider = async () => {
18
+ // First try V3
19
+ try {
20
+ const awsV3 = await import('@aws-sdk/credential-provider-node');
21
+ if (typeof awsV3.defaultProvider === 'function') {
22
+ return awsV3.defaultProvider();
23
+ }
24
+ } catch (err) {
25
+ // Ignore
26
+ }
27
+ try {
28
+ const awsV2 = await import('aws-sdk');
29
+ if (awsV2.default && typeof awsV2.default.config.getCredentials === 'function') {
30
+ return () =>
31
+ new Promise((resolve, reject) => {
32
+ awsV2.default.config.getCredentials((err, credentials) => {
33
+ if (err) {
34
+ reject(err);
35
+ } else {
36
+ resolve(credentials);
37
+ }
38
+ });
39
+ });
40
+ }
41
+ } catch (err) {
42
+ // Ignore
43
+ }
44
+
45
+ throw new AwsSigv4SignerError(
46
+ 'Unable to find a valid AWS SDK, please provide a valid getCredentials function to AwsSigv4Signer options.'
47
+ );
48
+ };
49
+
50
+ const awsDefaultCredentialsProvider = () =>
51
+ new Promise((resolve, reject) => {
52
+ getAwsSDKCredentialsProvider()
53
+ .then((provider) => {
54
+ provider().then(resolve).catch(reject);
55
+ })
56
+ .catch((err) => {
57
+ reject(err);
58
+ });
59
+ });
60
+
61
+ function AwsSigv4Signer(opts) {
62
+ const credentialsState = {
63
+ credentials: null,
64
+ };
65
+ if (opts && (!opts.region || opts.region === null || opts.region === '')) {
66
+ throw new AwsSigv4SignerError('Region cannot be empty');
67
+ }
68
+ if (opts && typeof opts.getCredentials !== 'function') {
69
+ opts.getCredentials = awsDefaultCredentialsProvider;
70
+ }
71
+
72
+ function buildSignedRequestObject(request = {}) {
73
+ request.service = 'es';
74
+ request.region = opts.region;
75
+ request.headers = request.headers || {};
76
+ request.headers['host'] = request.hostname;
77
+ return aws4.sign(request, credentialsState.credentials);
78
+ }
79
+
80
+ class AwsSigv4SignerConnection extends Connection {
81
+ buildRequestObject(params) {
82
+ const request = super.buildRequestObject(params);
83
+ return buildSignedRequestObject(request);
84
+ }
85
+ }
86
+
87
+ class AwsSigv4SignerTransport extends Transport {
88
+ request(params, options = {}, callback = undefined) {
89
+ // options is optional so if options is a function, it's the callback.
90
+ if (typeof options === 'function') {
91
+ callback = options;
92
+ options = {};
93
+ }
94
+
95
+ const currentCredentials = credentialsState.credentials;
96
+ let expired = false;
97
+ if (!currentCredentials) {
98
+ // Credentials haven't been acquired yet.
99
+ expired = true;
100
+ }
101
+ // AWS SDK V2, needsRefresh should be available.
102
+ else if (typeof currentCredentials.needsRefresh === 'function') {
103
+ expired = currentCredentials.needsRefresh();
104
+ }
105
+ // AWS SDK V2, alternative to needsRefresh.
106
+ else if (currentCredentials.expired === true) {
107
+ expired = true;
108
+ }
109
+ // AWS SDK V2, alternative to needsRefresh and expired.
110
+ else if (currentCredentials.expireTime && currentCredentials.expireTime < new Date()) {
111
+ expired = true;
112
+ }
113
+ // AWS SDK V3, Credentials.expiration is a Date object
114
+ else if (currentCredentials.expiration && currentCredentials.expiration < new Date()) {
115
+ expired = true;
116
+ }
117
+
118
+ if (!expired) {
119
+ if (typeof callback === 'undefined') {
120
+ return super.request(params, options);
121
+ }
122
+ super.request(params, options, callback);
123
+ return;
124
+ }
125
+
126
+ // In AWS SDK V2 Credentials.refreshPromise should be available.
127
+ if (currentCredentials && typeof currentCredentials.refreshPromise === 'function') {
128
+ if (typeof callback === 'undefined') {
129
+ return currentCredentials.refreshPromise().then(() => {
130
+ return super.request(params, options);
131
+ });
132
+ } else {
133
+ currentCredentials
134
+ .refreshPromise()
135
+ .then(() => {
136
+ super.request(params, options, callback);
137
+ })
138
+ .catch(callback);
139
+ return;
140
+ }
141
+ }
142
+
143
+ // For AWS SDK V3 or when the client has not acquired credentials yet.
144
+ if (typeof callback === 'undefined') {
145
+ return opts.getCredentials().then((credentials) => {
146
+ credentialsState.credentials = credentials;
147
+ return super.request(params, options);
148
+ });
149
+ } else {
150
+ opts
151
+ .getCredentials()
152
+ .then((credentials) => {
153
+ credentialsState.credentials = credentials;
154
+ super.request(params, options, callback);
155
+ })
156
+ .catch(callback);
157
+ }
158
+ }
159
+ }
160
+
161
+ return {
162
+ Transport: AwsSigv4SignerTransport,
163
+ Connection: AwsSigv4SignerConnection,
164
+ buildSignedRequestObject,
165
+ };
166
+ }
167
+ module.exports = AwsSigv4Signer;
@@ -0,0 +1,24 @@
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
+ 'use strict';
12
+ const { OpenSearchClientError } = require('../errors');
13
+
14
+ class AwsSigv4SignerError extends OpenSearchClientError {
15
+ constructor(message, data) {
16
+ super(message, data);
17
+ Error.captureStackTrace(this, AwsSigv4SignerError);
18
+ this.name = 'AwsSigv4SignerError';
19
+ this.message = message || 'AwsSigv4Signer Error';
20
+ this.data = data;
21
+ }
22
+ }
23
+
24
+ module.exports = AwsSigv4SignerError;
@@ -0,0 +1,39 @@
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
+ /// <reference types="node" />
12
+
13
+ import { Credentials } from '@aws-sdk/types';
14
+ import Connection from '../Connection';
15
+ import Transport from '../Transport';
16
+ import * as http from 'http';
17
+ import { OpenSearchClientError } from '../errors';
18
+
19
+ interface AwsSigv4SignerOptions {
20
+ getCredentials?: () => Promise<Credentials>;
21
+ region: string;
22
+ }
23
+
24
+ interface AwsSigv4SignerResponse {
25
+ Connection: typeof Connection;
26
+ Transport: typeof Transport;
27
+ buildSignedRequestObject(request: any): http.ClientRequestArgs;
28
+ }
29
+
30
+ declare function AwsSigv4Signer (opts: AwsSigv4SignerOptions): AwsSigv4SignerResponse;
31
+
32
+ declare class AwsSigv4SignerError extends OpenSearchClientError {
33
+ name: string;
34
+ message: string;
35
+ data: any;
36
+ constructor(message: string, data: any);
37
+ }
38
+
39
+ export { AwsSigv4Signer, AwsSigv4SignerOptions, AwsSigv4SignerResponse, AwsSigv4SignerError };
@@ -0,0 +1,19 @@
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
+ 'use strict';
12
+
13
+ const AwsSigv4Signer = require('./AwsSigv4Signer');
14
+ const AwsSigv4SignerError = require('./errors');
15
+
16
+ module.exports = {
17
+ AwsSigv4Signer,
18
+ AwsSigv4SignerError,
19
+ };
package/lib/errors.d.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
package/lib/errors.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*
@@ -1,12 +1,11 @@
1
1
  /*
2
+ * Copyright OpenSearch Contributors
2
3
  * SPDX-License-Identifier: Apache-2.0
3
4
  *
4
5
  * The OpenSearch Contributors require contributions made to
5
6
  * this file be licensed under the Apache-2.0 license or a
6
7
  * compatible open source license.
7
8
  *
8
- * Modifications Copyright OpenSearch Contributors. See
9
- * GitHub history for details.
10
9
  */
11
10
 
12
11
  /*