From d78ae1ce5e05d57375e21075bc660e7fe8a71ea1 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Thu, 25 Aug 2022 00:31:31 +0000 Subject: [PATCH 01/25] Add AwsSigV4 signing functionality Signed-off-by: Harsha Vamsi Kalluri --- README.md | 87 +++++ index.d.ts | 2 + index.js | 2 + index.mjs | 1 + lib/AwsV4Signer.d.ts | 17 + lib/AwsV4Signer.js | 62 ++++ lib/errors.d.ts | 7 + lib/errors.js | 11 + package.json | 2 + test/types/awsv4signer.test-d.ts | 48 +++ test/unit/client.test.js | 68 ++++ yarn.lock | 550 +++++++++++++++++++++++++++++++ 12 files changed, 857 insertions(+) create mode 100644 lib/AwsV4Signer.d.ts create mode 100644 lib/AwsV4Signer.js create mode 100644 test/types/awsv4signer.test-d.ts diff --git a/README.md b/README.md index 0f90b2cac..6b782c1ac 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,93 @@ async function search() { search().catch(console.log); ``` +### With AWS SigV4 signing +```javascript +const host = ""; // Opensearch domain URL e.g. https://search-xxx.region.es.amazonaws.com +const { Client, AwsV4Signer } = require('@opensearch-project/opensearch'); +const { defaultProvider } = require("@aws-sdk/credential-provider-node"); + +async function getClient() { + const credentials = await defaultProvider()(); + var client = new Client({ + ...AwsV4Signer({ + credentials: credentials, + region: "us-west-2", + }), + node: host, + }); + return client; +} + +async function search() { + + var client = await getClient(); + + var index_name = "books-test-1"; + var settings = { + settings: { + index: { + number_of_shards: 4, + number_of_replicas: 3, + }, + }, + }; + + var response = await client.indices.create({ + index: index_name, + body: settings, + }); + + console.log("Creating index:"); + console.log(response.body); + + // Add a document to the index. + var document = { + title: "The Outsider", + author: "Stephen King", + year: "2018", + genre: "Crime fiction", + }; + + var id = "1"; + + var response = await client.index({ + id: id, + index: index_name, + body: document, + refresh: true, + }); + + console.log("Adding document:"); + console.log(response.body); + + var response = await client.bulk({ body: bulk_documents }); + console.log(response.body); + + // Search for the document. + var query = { + query: { + match: { + title: { + query: "The Outsider", + }, + }, + }, + }; + + var response = await client.search({ + index: index_name, + body: query, + }); + + console.log("Search results:"); + console.log(response.body.hits); +} + +search().catch(console.log); +``` + + ## Project Resources - [Project Website](https://opensearch.org/) diff --git a/index.d.ts b/index.d.ts index 8a6112c99..3015bb1cc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -56,6 +56,7 @@ import { ResurrectEvent, BasicAuth, } from './lib/pool'; +import AwsV4Signer from './lib/AwsV4Signer'; import Serializer from './lib/Serializer'; import Helpers from './lib/Helpers'; import * as errors from './lib/errors'; @@ -5050,4 +5051,5 @@ export { ClientOptions, NodeOptions, ClientExtendsCallbackOptions, + AwsV4Signer }; diff --git a/index.js b/index.js index e36a0b679..1e946c8bc 100644 --- a/index.js +++ b/index.js @@ -47,6 +47,7 @@ if (clientVersion.includes('-')) { // clean prerelease clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'; } +const AwsV4Signer = require('./lib/AwsV4Signer'); const kInitialOptions = Symbol('opensearchjs-initial-options'); const kChild = Symbol('opensearchjs-child'); @@ -348,4 +349,5 @@ module.exports = { Serializer, events, errors, + AwsV4Signer, }; diff --git a/index.mjs b/index.mjs index 75ef740d9..c1335abbf 100644 --- a/index.mjs +++ b/index.mjs @@ -38,3 +38,4 @@ export const Connection = mod.Connection; export const Serializer = mod.Serializer; export const events = mod.events; export const errors = mod.errors; +export const awsV4Signer = mod.AwsV4Signer; diff --git a/lib/AwsV4Signer.d.ts b/lib/AwsV4Signer.d.ts new file mode 100644 index 000000000..edcc67544 --- /dev/null +++ b/lib/AwsV4Signer.d.ts @@ -0,0 +1,17 @@ +import { Credentials } from '@aws-sdk/types'; +import Connection from './Connection'; +import * as http from 'http'; + +interface AwsV4SignerOptions { + credentials: Credentials; + region: string; +} + +export interface AwsV4SignerResponse { + Connection: Connection; + buildSignedRequestObject(request: any): http.ClientRequestArgs; +} + +export default function AwsV4Signer(opts: AwsV4SignerOptions): AwsV4SignerResponse; + +export {}; diff --git a/lib/AwsV4Signer.js b/lib/AwsV4Signer.js new file mode 100644 index 000000000..ca3b12d1b --- /dev/null +++ b/lib/AwsV4Signer.js @@ -0,0 +1,62 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; +const Connection = require('./Connection'); +const aws4 = require('aws4'); +const { AwsV4SignerError } = require('./errors'); + +function AwsV4Signer(opts) { + if (opts && (!opts.region || opts.region === null || opts.region === '')) { + throw new AwsV4SignerError('Region cannot be empty'); + } + if (opts && (!opts.credentials || opts.credentials === null || opts.credentials === '')) { + throw new AwsV4SignerError('Credentials cannot be empty'); + } + + function buildSignedRequestObject(request = {}) { + request.service = 'es'; + request.region = opts.region; + request.headers = request.headers || {}; + request.headers['host'] = request.hostname; + return aws4.sign(request, opts.credentials); + } + class AwsV4SignedConnection extends Connection { + buildRequestObject(params) { + const request = super.buildRequestObject(params); + return buildSignedRequestObject(request); + } + } + return { + Connection: AwsV4SignedConnection, + buildSignedRequestObject, + }; +} +module.exports = AwsV4Signer; diff --git a/lib/errors.d.ts b/lib/errors.d.ts index b49485963..66d176d7c 100644 --- a/lib/errors.d.ts +++ b/lib/errors.d.ts @@ -117,3 +117,10 @@ export declare class NotCompatibleError< meta: ApiResponse; constructor(meta: ApiResponse); } + +export declare class AwsV4SignerError extends OpenSearchClientError { + name: string; + message: string; + data: any; + constructor(message: string, data: any); +} diff --git a/lib/errors.js b/lib/errors.js index 068b63247..93d07a8b4 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -158,6 +158,16 @@ class NotCompatibleError extends OpenSearchClientError { } } +class AwsV4SignerError extends OpenSearchClientError { + constructor(message, data) { + super(message, data); + Error.captureStackTrace(this, AwsV4SignerError); + this.name = 'AwsV4SignerError'; + this.message = message || 'AwsV4Signer Error'; + this.data = data; + } +} + module.exports = { OpenSearchClientError, TimeoutError, @@ -169,4 +179,5 @@ module.exports = { ResponseError, RequestAbortedError, NotCompatibleError, + AwsV4SignerError, }; diff --git a/package.json b/package.json index 20a296676..36530c485 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,8 @@ "xmlbuilder2": "^2.4.1" }, "dependencies": { + "@aws-sdk/credential-provider-node": "^3.154.0", + "aws4": "^1.11.0", "debug": "^4.3.1", "hpagent": "^0.1.1", "ms": "^2.1.3", diff --git a/test/types/awsv4signer.test-d.ts b/test/types/awsv4signer.test-d.ts new file mode 100644 index 000000000..0b63c9897 --- /dev/null +++ b/test/types/awsv4signer.test-d.ts @@ -0,0 +1,48 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { expectType } from 'tsd'; +import { AwsV4Signer } from '../../'; +import { AwsV4SignerResponse } from '../../lib/AwsV4Signer'; + +const mockCreds = { + accessKeyId: 'mockCredAccessKeyId', + secretAccessKey: 'mockCredSecretAccessKey', +}; + +const mockRegion = 'us-west-2'; + +{ + const AwsV4SignerOptions = { credentials: mockCreds, region: mockRegion }; + + const auth = AwsV4Signer(AwsV4SignerOptions); + + expectType(auth); +} diff --git a/test/unit/client.test.js b/test/unit/client.test.js index 4a4f2bf98..bb5761fd8 100644 --- a/test/unit/client.test.js +++ b/test/unit/client.test.js @@ -33,9 +33,12 @@ const { test } = require('tap'); const { URL } = require('url'); const buffer = require('buffer'); +const { v4: uuidv4 } = require('uuid'); const intoStream = require('into-stream'); const { ConnectionPool, Transport, Connection, errors } = require('../../index'); const { Client, buildServer } = require('../utils'); +const { AwsV4Signer } = require('../../index'); +const { AwsV4SignerError } = require('../../lib/errors'); let clientVersion = require('../../package.json').version; if (clientVersion.includes('-')) { clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'; @@ -1189,3 +1192,68 @@ test('API compatibility header (x-ndjson)', (t) => { }); }); }); + +test('Sign with SigV4', (t) => { + t.plan(2); + + const mockCreds = { + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + }; + + const mockRegion = 'us-west-2'; + + const AwsV4SignerOptions = { credentials: mockCreds, region: mockRegion }; + + const auth = AwsV4Signer(AwsV4SignerOptions); + + const connection = new Connection({ + url: new URL('https://localhost:9200'), + }); + + const request = connection.buildRequestObject({ + path: '/hello', + method: 'GET', + headers: { + 'X-Custom-Test': true, + }, + }); + const signedRequest = auth.buildSignedRequestObject(request); + t.hasProp(signedRequest.headers, 'X-Amz-Date'); + t.hasProp(signedRequest.headers, 'Authorization'); +}); + +test('Sign with SigV4 failure (with empty region)', (t) => { + t.plan(2); + + const mockCreds = { + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + }; + + const AwsV4SignerOptions = { credentials: mockCreds }; + + try { + AwsV4Signer(AwsV4SignerOptions); + t.fail('Should fail'); + } catch (err) { + t.ok(err instanceof AwsV4SignerError); + t.equal(err.message, 'Region cannot be empty'); + } +}); + +test('Sign with SigV4 failure (with empty credentials)', (t) => { + t.plan(2); + + const mockRegion = 'us-west-2'; + + const AwsV4SignerOptions = { region: mockRegion }; + + try { + AwsV4Signer(AwsV4SignerOptions); + t.fail('Should fail'); + } catch (err) { + t.ok(err instanceof AwsV4SignerError); + t.equal(err.message, 'Credentials cannot be empty'); + } +}); diff --git a/yarn.lock b/yarn.lock index f7856331a..2d457c441 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,531 @@ # yarn lockfile v1 +"@aws-crypto/ie11-detection@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@aws-crypto/ie11-detection/-/ie11-detection-2.0.0.tgz#bb6c2facf8f03457e949dcf0921477397ffa4c6e" + integrity sha512-pkVXf/dq6PITJ0jzYZ69VhL8VFOFoPZLZqtU/12SGnzYuJOOGNfF41q9GxdI1yqC8R13Rq3jOLKDFpUJFT5eTA== + dependencies: + tslib "^1.11.1" + +"@aws-crypto/sha256-browser@2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-browser/-/sha256-browser-2.0.0.tgz#741c9024df55ec59b51e5b1f5d806a4852699fb5" + integrity sha512-rYXOQ8BFOaqMEHJrLHul/25ckWH6GTJtdLSajhlqGMx0PmSueAuvboCuZCTqEKlxR8CQOwRarxYMZZSYlhRA1A== + dependencies: + "@aws-crypto/ie11-detection" "^2.0.0" + "@aws-crypto/sha256-js" "^2.0.0" + "@aws-crypto/supports-web-crypto" "^2.0.0" + "@aws-crypto/util" "^2.0.0" + "@aws-sdk/types" "^3.1.0" + "@aws-sdk/util-locate-window" "^3.0.0" + "@aws-sdk/util-utf8-browser" "^3.0.0" + tslib "^1.11.1" + +"@aws-crypto/sha256-js@2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-js/-/sha256-js-2.0.0.tgz#f1f936039bdebd0b9e2dd834d65afdc2aac4efcb" + integrity sha512-VZY+mCY4Nmrs5WGfitmNqXzaE873fcIZDu54cbaDaaamsaTOP1DBImV9F4pICc3EHjQXujyE8jig+PFCaew9ig== + dependencies: + "@aws-crypto/util" "^2.0.0" + "@aws-sdk/types" "^3.1.0" + tslib "^1.11.1" + +"@aws-crypto/sha256-js@^2.0.0": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-js/-/sha256-js-2.0.1.tgz#79e1e6cf61f652ef2089c08d471c722ecf1626a9" + integrity sha512-mbHTBSPBvg6o/mN/c18Z/zifM05eJrapj5ggoOIeHIWckvkv5VgGi7r/wYpt+QAO2ySKXLNvH2d8L7bne4xrMQ== + dependencies: + "@aws-crypto/util" "^2.0.1" + "@aws-sdk/types" "^3.1.0" + tslib "^1.11.1" + +"@aws-crypto/supports-web-crypto@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@aws-crypto/supports-web-crypto/-/supports-web-crypto-2.0.0.tgz#fd6cde30b88f77d5a4f57b2c37c560d918014f9e" + integrity sha512-Ge7WQ3E0OC7FHYprsZV3h0QIcpdyJLvIeg+uTuHqRYm8D6qCFJoiC+edSzSyFiHtZf+NOQDJ1q46qxjtzIY2nA== + dependencies: + tslib "^1.11.1" + +"@aws-crypto/util@^2.0.0", "@aws-crypto/util@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@aws-crypto/util/-/util-2.0.1.tgz#976cf619cf85084ca85ec5eb947a6ac6b8b5c98c" + integrity sha512-JJmFFwvbm08lULw4Nm5QOLg8+lAQeC8aCXK5xrtxntYzYXCGfHwUJ4Is3770Q7HmICsXthGQ+ZsDL7C2uH3yBQ== + dependencies: + "@aws-sdk/types" "^3.1.0" + "@aws-sdk/util-utf8-browser" "^3.0.0" + tslib "^1.11.1" + +"@aws-sdk/abort-controller@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/abort-controller/-/abort-controller-3.127.0.tgz#60c98bffdb185d8eb5d3e43f30f57a32cc8687d6" + integrity sha512-G77FLYcl9egUoD3ZmR6TX94NMqBMeT53hBGrEE3uVUJV1CwfGKfaF007mPpRZnIB3avnJBQGEK6MrwlCfv2qAw== + dependencies: + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/client-sso@3.154.0": + version "3.154.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/client-sso/-/client-sso-3.154.0.tgz#8cb2e147137b72d16ab676533a62fb2711eb10ed" + integrity sha512-v5pJOkCxtxcSX1Cflskz9w+7kbP3PDsE6ce3zvmdCghCRAdM0SoJMffGlg/08VXwqW+GMJTZu+i+ojXMXhZTJw== + dependencies: + "@aws-crypto/sha256-browser" "2.0.0" + "@aws-crypto/sha256-js" "2.0.0" + "@aws-sdk/config-resolver" "3.130.0" + "@aws-sdk/fetch-http-handler" "3.131.0" + "@aws-sdk/hash-node" "3.127.0" + "@aws-sdk/invalid-dependency" "3.127.0" + "@aws-sdk/middleware-content-length" "3.127.0" + "@aws-sdk/middleware-host-header" "3.127.0" + "@aws-sdk/middleware-logger" "3.127.0" + "@aws-sdk/middleware-recursion-detection" "3.127.0" + "@aws-sdk/middleware-retry" "3.127.0" + "@aws-sdk/middleware-serde" "3.127.0" + "@aws-sdk/middleware-stack" "3.127.0" + "@aws-sdk/middleware-user-agent" "3.127.0" + "@aws-sdk/node-config-provider" "3.127.0" + "@aws-sdk/node-http-handler" "3.127.0" + "@aws-sdk/protocol-http" "3.127.0" + "@aws-sdk/smithy-client" "3.142.0" + "@aws-sdk/types" "3.127.0" + "@aws-sdk/url-parser" "3.127.0" + "@aws-sdk/util-base64-browser" "3.109.0" + "@aws-sdk/util-base64-node" "3.55.0" + "@aws-sdk/util-body-length-browser" "3.154.0" + "@aws-sdk/util-body-length-node" "3.55.0" + "@aws-sdk/util-defaults-mode-browser" "3.142.0" + "@aws-sdk/util-defaults-mode-node" "3.142.0" + "@aws-sdk/util-user-agent-browser" "3.127.0" + "@aws-sdk/util-user-agent-node" "3.127.0" + "@aws-sdk/util-utf8-browser" "3.109.0" + "@aws-sdk/util-utf8-node" "3.109.0" + tslib "^2.3.1" + +"@aws-sdk/config-resolver@3.130.0": + version "3.130.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/config-resolver/-/config-resolver-3.130.0.tgz#ba0fa915fa5613e87051a9826531e59cab4387b1" + integrity sha512-7dkCHHI9kRcHW6YNr9/2Ub6XkvU9Fu6H/BnlKbaKlDR8jq7QpaFhPhctOVi5D/NDpxJgALifexFne0dvo3piTw== + dependencies: + "@aws-sdk/signature-v4" "3.130.0" + "@aws-sdk/types" "3.127.0" + "@aws-sdk/util-config-provider" "3.109.0" + "@aws-sdk/util-middleware" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/credential-provider-env@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-env/-/credential-provider-env-3.127.0.tgz#06eb67461f7df8feb14abd3b459f682544d78e43" + integrity sha512-Ig7XhUikRBlnRTYT5JBGzWfYZp68X5vkFVIFCmsHHt/qVy0Nz9raZpmDHicdS1u67yxDkWgCPn/bNevWnM0GFg== + dependencies: + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/credential-provider-imds@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-imds/-/credential-provider-imds-3.127.0.tgz#1fc7b40bf21adcc2a897e47b72796bd8ebcc7d86" + integrity sha512-I6KlIBBzmJn/U1KikiC50PK3SspT9G5lkVLBaW5a6YfOcijqVTXfAN3kYzqhfeS0j4IgfJEwKVsjsZfmprJO5A== + dependencies: + "@aws-sdk/node-config-provider" "3.127.0" + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/types" "3.127.0" + "@aws-sdk/url-parser" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/credential-provider-ini@3.154.0": + version "3.154.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.154.0.tgz#825d7fd981b146380339f3ac4dcd81eb334bbe71" + integrity sha512-5p8vueRuAMo3cMBAHQCgAu6Kr+K6R64Bm1yccQu72HEy8zoyQsCKMV0tQS7dYbObfOGpIXZbHyESyTon0khI0g== + dependencies: + "@aws-sdk/credential-provider-env" "3.127.0" + "@aws-sdk/credential-provider-imds" "3.127.0" + "@aws-sdk/credential-provider-sso" "3.154.0" + "@aws-sdk/credential-provider-web-identity" "3.127.0" + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/shared-ini-file-loader" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/credential-provider-node@^3.154.0": + version "3.154.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-node/-/credential-provider-node-3.154.0.tgz#c37572dbb6731c288708d60ae62cbdb32def771e" + integrity sha512-pNxKtf/ye2574+QT2aKykSzKo3RnwCtWB7Tduo/8YlmQZL+/vX53BLcGj+fLOE1h7RbY5psF02dzbanvb4CVGg== + dependencies: + "@aws-sdk/credential-provider-env" "3.127.0" + "@aws-sdk/credential-provider-imds" "3.127.0" + "@aws-sdk/credential-provider-ini" "3.154.0" + "@aws-sdk/credential-provider-process" "3.127.0" + "@aws-sdk/credential-provider-sso" "3.154.0" + "@aws-sdk/credential-provider-web-identity" "3.127.0" + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/shared-ini-file-loader" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/credential-provider-process@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-process/-/credential-provider-process-3.127.0.tgz#6046a20013a3edd58b631668ed1d73dfd63a931c" + integrity sha512-6v0m2lqkO9J5fNlTl+HjriQNIdfg8mjVST544+5y9EnC/FVmTnIz64vfHveWdNkP/fehFx7wTimNENtoSqCn3A== + dependencies: + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/shared-ini-file-loader" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/credential-provider-sso@3.154.0": + version "3.154.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.154.0.tgz#e752a6406317fbb4609a19a0b420cfe527d8a682" + integrity sha512-w3EZo1IKLyE7rhurq56e8IZuMxr0bc3Qvkq+AJnDwTR4sm5TPp9RNJwo+/A0i7GOdhNufcTlaciZT9Izi3g4+A== + dependencies: + "@aws-sdk/client-sso" "3.154.0" + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/shared-ini-file-loader" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/credential-provider-web-identity@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.127.0.tgz#a56c390bf0148f20573abd022930b28df345043a" + integrity sha512-85ahDZnLYB3dqkW+cQ0bWt+NVqOoxomTrJoq3IC2q6muebeFrJ0pyf0JEW/RNRzBiUvvsZujzGdWifzWyQKfVg== + dependencies: + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/fetch-http-handler@3.131.0": + version "3.131.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/fetch-http-handler/-/fetch-http-handler-3.131.0.tgz#426721ba3c4e7687a6c12ce10bdc661900325815" + integrity sha512-eNxmPZQX2IUeBGWHNC7eNTekWn9VIPLYEMKJbKYUBJryxuTJ7TtLeyEK5oakUjMwP1AUvWT+CV7C+8L7uG1omQ== + dependencies: + "@aws-sdk/protocol-http" "3.127.0" + "@aws-sdk/querystring-builder" "3.127.0" + "@aws-sdk/types" "3.127.0" + "@aws-sdk/util-base64-browser" "3.109.0" + tslib "^2.3.1" + +"@aws-sdk/hash-node@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/hash-node/-/hash-node-3.127.0.tgz#2fbbeb509a515e6a5cfd6846c02cc1967961a40b" + integrity sha512-wx7DKlXdKebH4JcMsOevdsm2oDNMVm36kuMm0XWRIrFWQ/oq7OquDpEMJzWvGqWF/IfFUpb7FhAWZZpALwlcwA== + dependencies: + "@aws-sdk/types" "3.127.0" + "@aws-sdk/util-buffer-from" "3.55.0" + tslib "^2.3.1" + +"@aws-sdk/invalid-dependency@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/invalid-dependency/-/invalid-dependency-3.127.0.tgz#3a99603e1969f67278495b827243e9a391b8cfc4" + integrity sha512-bxvmtmJ6gIRfOHvh1jAPZBH2mzppEblPjEOFo4mOzXz4U3qPIxeuukCjboMnGK9QEpV2wObWcYYld0vxoRrfiA== + dependencies: + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/is-array-buffer@3.55.0": + version "3.55.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/is-array-buffer/-/is-array-buffer-3.55.0.tgz#c46122c5636f01d5895e5256a587768c3425ea7a" + integrity sha512-NbiPHVYuPxdqdFd6FxzzN3H1BQn/iWA3ri3Ry7AyLeP/tGs1yzEWMwf8BN8TSMALI0GXT6Sh0GDWy3Ok5xB6DA== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/middleware-content-length@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-content-length/-/middleware-content-length-3.127.0.tgz#662c1971fdb2dd7d34a9945ebd8da52578900434" + integrity sha512-AFmMaIEW3Rzg0TaKB9l/RENLowd7ZEEOpm0trYw1CgUUORWW/ydCsDT7pekPlC25CPbhUmWXCSA4xPFSYOVnDw== + dependencies: + "@aws-sdk/protocol-http" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/middleware-host-header@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-host-header/-/middleware-host-header-3.127.0.tgz#679f685bd8b4f221ed2c11e90b381d6904034ef9" + integrity sha512-e2gTLJb5lYP9lRV7hN3rKY2l4jv8OygOoHElZJ3Z8KPZskjHelYPcQ8XbdfhSXXxC3vc/0QqN0ResFt3W3Pplg== + dependencies: + "@aws-sdk/protocol-http" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/middleware-logger@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-logger/-/middleware-logger-3.127.0.tgz#b62fd148888f418bd74b0c9d76b80588224ee98f" + integrity sha512-jMNLcZB/ECA7OfkNBLNeAlrLRehyfnUeNQJHW3kcxs9h1+6VxaF6wY+WKozszLI7/3OBzQrFHBQCfRZV7ykSLg== + dependencies: + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/middleware-recursion-detection@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.127.0.tgz#84949efd4a05a4d00da3e9242825e3c9d715f800" + integrity sha512-tB6WX+Z1kUKTnn5h38XFrTCzoqPKjUZLUjN4Wb27/cbeSiTSKGAZcCXHOJm36Ukorl5arlybQTqGe689EU00Hw== + dependencies: + "@aws-sdk/protocol-http" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/middleware-retry@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-retry/-/middleware-retry-3.127.0.tgz#bcd0741ed676588101739083c6bd141d5c1911e1" + integrity sha512-ZSvg/AyGUacWnf3i8ZbyImtiCH+NyafF8uV7bITP7JkwPrG+VdNocJZOr88GRM0c1A0jfkOf7+oq+fInPwwiNA== + dependencies: + "@aws-sdk/protocol-http" "3.127.0" + "@aws-sdk/service-error-classification" "3.127.0" + "@aws-sdk/types" "3.127.0" + "@aws-sdk/util-middleware" "3.127.0" + tslib "^2.3.1" + uuid "^8.3.2" + +"@aws-sdk/middleware-serde@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-serde/-/middleware-serde-3.127.0.tgz#8732d71ed0d28c43e609fcc156b1a1ac307c0d5f" + integrity sha512-xmWMYV/t9M+b9yHjqaD1noDNJJViI2QwOH7TQZ9VbbrvdVtDrFuS9Sf9He80TBCJqeHShwQN9783W1I3Pu/8kw== + dependencies: + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/middleware-stack@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-stack/-/middleware-stack-3.127.0.tgz#d569d964256cdd4a5afd149de325296cf19762f6" + integrity sha512-S1IoUE5o1vCmjsF5nIE8zlItNOM1UE+lhmZeigF7knXJ9+a6ewMB6POAj/s4eoi0wcn0eSnAGsqJCWMSUjOPLA== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/middleware-user-agent@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.127.0.tgz#f676aac4ddaba64bb12b6d69b0ed7328479cf798" + integrity sha512-CHxgswoOzdkOEoIq7Oyob3Sx/4FYUv6BhUesAX7MNshaDDsTQPbSWjw5bqZDiL/gO+X/34fvqCVVpVD2GvxW/g== + dependencies: + "@aws-sdk/protocol-http" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/node-config-provider@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/node-config-provider/-/node-config-provider-3.127.0.tgz#43a460526f0c24a661264189712e0ff5475e9b45" + integrity sha512-bAHkASMhLZHT1yv2TX6OJGFV9Lc3t1gKfTMEKdXM2O2YhGfSx9A/qLeJm79oDfnILWQtSS2NicxlRDI2lYGf4g== + dependencies: + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/shared-ini-file-loader" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/node-http-handler@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/node-http-handler/-/node-http-handler-3.127.0.tgz#81c0a34061b233027bc673f3359c36555c0688d7" + integrity sha512-pyMKvheK8eDwWLgYIRsWy8wiyhsbYYcqkZQs3Eh6upI4E8iCY7eMmhWvHYCibvsO+UjsOwa4cAMOfwnv/Z9s8A== + dependencies: + "@aws-sdk/abort-controller" "3.127.0" + "@aws-sdk/protocol-http" "3.127.0" + "@aws-sdk/querystring-builder" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/property-provider@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/property-provider/-/property-provider-3.127.0.tgz#3b70d23354c35ea04c29c97f05cc4108c2e194ba" + integrity sha512-JxenxlTEkWfLrtJqIjaXaJzAVQbbscoCb5bNjmdud07ESLVfWRKJx2nAJdecHKYp2M5NQyqBuFhQ1ELSFYQKCA== + dependencies: + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/protocol-http@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/protocol-http/-/protocol-http-3.127.0.tgz#c1d7bb20f09f9e86fd885d3effb33850b618e549" + integrity sha512-UG83PVuKX40wilG2uRU0Fvz4OY8Bt+bSPOG776DFjwIXYzK7BwpJm9H2XI2HLhS5WxrJHhwrLBRgW6UiykMnFw== + dependencies: + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/querystring-builder@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/querystring-builder/-/querystring-builder-3.127.0.tgz#50a100d13bd13bb06ee92dcd9568e21a37fb9c49" + integrity sha512-tsoyp4lLPsASPDYWsezGAHD8VJsZbjUNATNAzTCFdH6p+4SKBK83Q5kfXCzxt13M+l3oKbxxIWLvS0kVQFyltQ== + dependencies: + "@aws-sdk/types" "3.127.0" + "@aws-sdk/util-uri-escape" "3.55.0" + tslib "^2.3.1" + +"@aws-sdk/querystring-parser@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/querystring-parser/-/querystring-parser-3.127.0.tgz#d485db0d24005e95bb4c9c478691cd805e5fc0f4" + integrity sha512-Vn/Dv+PqUSepp/DzLqq0LJJD8HdPefJCnLbO5WcHCARHSGlyGlZUFEM45k/oEHpTvgMXj/ORaP3A+tLwLu0AmA== + dependencies: + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/service-error-classification@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/service-error-classification/-/service-error-classification-3.127.0.tgz#64b69215b2525e3b6806856187ef54b00c0f85d1" + integrity sha512-wjZY9rnlA8SPrICUumTYicEKtK4/yKB62iadUk66hxe8MrH8JhuHH2NqIad0Pt/bK/YtNVhd3yb4pRapOeY5qQ== + +"@aws-sdk/shared-ini-file-loader@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/shared-ini-file-loader/-/shared-ini-file-loader-3.127.0.tgz#019c5512bf92f954f6aca6f6811e38fe048aadf6" + integrity sha512-S3Nn4KRTqoJsB/TbRZSWBBUrkckNMR0Juqz7bOB+wupVvddKP6IcpspSC/GX9zgJjVMV8iGisZ6AUsYsC5r+cA== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/signature-v4@3.130.0": + version "3.130.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/signature-v4/-/signature-v4-3.130.0.tgz#152085234311610a350fdcd9a7f877a83aa44cf1" + integrity sha512-g5G1a1NHL2uOoFfC2zQdZcj+wbjgBQPkx6xGdtqNKf9v2kS0n6ap5JUGEaqWE02lUlmWHsoMsS73hXtzwXaBRQ== + dependencies: + "@aws-sdk/is-array-buffer" "3.55.0" + "@aws-sdk/types" "3.127.0" + "@aws-sdk/util-hex-encoding" "3.109.0" + "@aws-sdk/util-middleware" "3.127.0" + "@aws-sdk/util-uri-escape" "3.55.0" + tslib "^2.3.1" + +"@aws-sdk/smithy-client@3.142.0": + version "3.142.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/smithy-client/-/smithy-client-3.142.0.tgz#d27abff1892de644ac25fc07305fbc0050d7d512" + integrity sha512-G38YWTfSFZb5cOH6IwLct530Uy8pnmJvJFeC1pd1nkKD4PRZb+bI2w4xXSX+znYdLA71RYK620OtVKJlB44PtA== + dependencies: + "@aws-sdk/middleware-stack" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/types@3.127.0", "@aws-sdk/types@^3.1.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/types/-/types-3.127.0.tgz#a7bafc47ee2328eee2453087521e6c3a39e7278d" + integrity sha512-e0wtx2IkOl7rwfKfLH5pPTzQ+d45V7b1WrjeL0WDI8kOu6w+sXmhNxI6uM2kf0k4NiTLN84lW290AEWupey9Og== + +"@aws-sdk/url-parser@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/url-parser/-/url-parser-3.127.0.tgz#7a5c6186e83dc6f823c989c0575aebe384e676b0" + integrity sha512-njZ7zn41JHRpNfr3BCesVXCLZE0zcWSfEdtRV0ICw0cU1FgYcKELSuY9+gLUB4ci6uc7gq7mPE8+w30FcM4QeA== + dependencies: + "@aws-sdk/querystring-parser" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/util-base64-browser@3.109.0": + version "3.109.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-base64-browser/-/util-base64-browser-3.109.0.tgz#e7faf5c4cbb88bc39b9c1c5a1a79e4c869e9f645" + integrity sha512-lAZ6fyDGiRLaIsKT9qh7P9FGuNyZ4gAbr1YOSQk/5mHtaTuUvxlPptZuInNM/0MPQm6lpcot00D8IWTucn4PbA== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-base64-node@3.55.0": + version "3.55.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-base64-node/-/util-base64-node-3.55.0.tgz#da9a3fd6752be49163572144793e6b23d0186ff4" + integrity sha512-UQ/ZuNoAc8CFMpSiRYmevaTsuRKzLwulZTnM8LNlIt9Wx1tpNvqp80cfvVj7yySKROtEi20wq29h31dZf1eYNQ== + dependencies: + "@aws-sdk/util-buffer-from" "3.55.0" + tslib "^2.3.1" + +"@aws-sdk/util-body-length-browser@3.154.0": + version "3.154.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-body-length-browser/-/util-body-length-browser-3.154.0.tgz#8c4c5d08c1923deeedf46006dc4db820ca606f56" + integrity sha512-TUuy7paVkBRQrB/XFCsL8iTW6g/ma0S3N8dYOiIMJdeTqTFryeyOGkBpYBgYFQL6zRMZpyu0jOM7GYEffGFOXw== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-body-length-node@3.55.0": + version "3.55.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-body-length-node/-/util-body-length-node-3.55.0.tgz#67049bbb6c62d794a1bb5a13b9a678988c925489" + integrity sha512-lU1d4I+9wJwydduXs0SxSfd+mHKjxeyd39VwOv6i2KSwWkPbji9UQqpflKLKw+r45jL7+xU/zfeTUg5Tt/3Gew== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-buffer-from@3.55.0": + version "3.55.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-buffer-from/-/util-buffer-from-3.55.0.tgz#e7c927974b07a29502aa1ad58509b91d0d7cf0f7" + integrity sha512-uVzKG1UgvnV7XX2FPTylBujYMKBPBaq/qFBxfl0LVNfrty7YjpfieQxAe6yRLD+T0Kir/WDQwGvYC+tOYG3IGA== + dependencies: + "@aws-sdk/is-array-buffer" "3.55.0" + tslib "^2.3.1" + +"@aws-sdk/util-config-provider@3.109.0": + version "3.109.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-config-provider/-/util-config-provider-3.109.0.tgz#7828b8894b2b23c289ffc5c106cbced7a5d6ee86" + integrity sha512-GrAZl/aBv0A28LkyNyq8SPJ5fmViCwz80fWLMeWx/6q5AbivuILogjlWwEZSvZ9zrlHOcFC0+AnCa5pQrjaslw== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-defaults-mode-browser@3.142.0": + version "3.142.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-defaults-mode-browser/-/util-defaults-mode-browser-3.142.0.tgz#808e136ba0b371a68d9d3a4aff7671ee39b68d88" + integrity sha512-vVB/CrodMmIfv4v54MyBlKO0sQSI/+Mvs4g5gMyVjmT4a+1gnktJQ9R6ZHQ2/ErGewcra6eH9MU5T0r1kYe0+w== + dependencies: + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/types" "3.127.0" + bowser "^2.11.0" + tslib "^2.3.1" + +"@aws-sdk/util-defaults-mode-node@3.142.0": + version "3.142.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-defaults-mode-node/-/util-defaults-mode-node-3.142.0.tgz#d2a8cec87a5295b81ec4315ff0a31bad799a2ac0" + integrity sha512-13d5RZLO13EDwll3COUq3D4KVsqM63kdf+YjG5mzXR1eXo6GVjghfQfiy0MYM6YbAjTfJxZQkc0nFgWLU8jdyg== + dependencies: + "@aws-sdk/config-resolver" "3.130.0" + "@aws-sdk/credential-provider-imds" "3.127.0" + "@aws-sdk/node-config-provider" "3.127.0" + "@aws-sdk/property-provider" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/util-hex-encoding@3.109.0": + version "3.109.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-hex-encoding/-/util-hex-encoding-3.109.0.tgz#93b20acc27c0a1d7d80f653bf19d3dd01c2ccc65" + integrity sha512-s8CgTNrn3cLkrdiohfxLuOYPCanzvHn/aH5RW6DaMoeQiG5Hl9QUiP/WtdQ9QQx3xvpQFpmvxIaSBwSgFNLQxA== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-locate-window@^3.0.0": + version "3.55.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-locate-window/-/util-locate-window-3.55.0.tgz#a4136a20ee1bfcb73967a6614caf769ef79db070" + integrity sha512-0sPmK2JaJE2BbTcnvybzob/VrFKCXKfN4CUKcvn0yGg/me7Bz+vtzQRB3Xp+YSx+7OtWxzv63wsvHoAnXvgxgg== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-middleware@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-middleware/-/util-middleware-3.127.0.tgz#266d6160886f272cb3e3c3eb5266abbac0c033bc" + integrity sha512-EwAPPed9TNqh+Wov2VStLn2NuJ/Wyt7IkZCbCsBuSNp3BFZ1V4gfwTjqtKCtB2LQgQ48MTgWgNCvrH0zjCSPGg== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-uri-escape@3.55.0": + version "3.55.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-uri-escape/-/util-uri-escape-3.55.0.tgz#ee57743c628a1c9f942dfe73205ce890ec011916" + integrity sha512-mmdDLUpFCN2nkfwlLdOM54lTD528GiGSPN1qb8XtGLgZsJUmg3uJSFIN2lPeSbEwJB3NFjVas/rnQC48i7mV8w== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-user-agent-browser@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.127.0.tgz#dc6c4c9049ebf238c321883593b2cd3d82b5e755" + integrity sha512-uO2oHmJswuYKJS+GiMdYI8izhpC9M7/jFFvnAmLlTEVwpEi1VX9KePAOF+u5AaBC2kzITo/7dg141XfRHZloIQ== + dependencies: + "@aws-sdk/types" "3.127.0" + bowser "^2.11.0" + tslib "^2.3.1" + +"@aws-sdk/util-user-agent-node@3.127.0": + version "3.127.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.127.0.tgz#368dc0c0e1160e8ca9e5ca21f3857004509aa06e" + integrity sha512-3P/M4ZDD2qMeeoCk7TE/Mw7cG5IjB87F6BP8nI8/oHuaz7j6fsI7D49SNpyjl8JApRynZ122Ad6hwQwRj3isYw== + dependencies: + "@aws-sdk/node-config-provider" "3.127.0" + "@aws-sdk/types" "3.127.0" + tslib "^2.3.1" + +"@aws-sdk/util-utf8-browser@3.109.0", "@aws-sdk/util-utf8-browser@^3.0.0": + version "3.109.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-utf8-browser/-/util-utf8-browser-3.109.0.tgz#d013272e1981b23a4c84ac06f154db686c0cf84e" + integrity sha512-FmcGSz0v7Bqpl1SE8G1Gc0CtDpug+rvqNCG/szn86JApD/f5x8oByjbEiAyTU2ZH2VevUntx6EW68ulHyH+x+w== + dependencies: + tslib "^2.3.1" + +"@aws-sdk/util-utf8-node@3.109.0": + version "3.109.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/util-utf8-node/-/util-utf8-node-3.109.0.tgz#89e06d916f5b246c7265f59bac742973ac0767ac" + integrity sha512-Ti/ZBdvz2eSTElsucjzNmzpyg2MwfD1rXmxD0hZuIF8bPON/0+sZYnWd5CbDw9kgmhy28dmKue086tbZ1G0iLQ== + dependencies: + "@aws-sdk/util-buffer-from" "3.55.0" + tslib "^2.3.1" + "@babel/code-frame@7.12.11": version "7.12.11" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" @@ -757,6 +1282,11 @@ auto-bind@4.0.0: resolved "https://registry.yarnpkg.com/auto-bind/-/auto-bind-4.0.0.tgz#e3589fc6c2da8f7ca43ba9f84fa52a744fc997fb" integrity sha512-Hdw8qdNiqdJ8LqT0iK0sVzkFbzg6fhnQqqfWhBDxcHZvU75+B+ayzTy8x+k5Ix0Y92XOhOUlx74ps+bA6BeYMQ== +aws4@^1.11.0: + version "1.11.0" + resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" + integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA== + babel-eslint@^10.1.0: version "10.1.0" resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232" @@ -803,6 +1333,11 @@ bl@^4.1.0: inherits "^2.0.4" readable-stream "^3.4.0" +bowser@^2.11.0: + version "2.11.0" + resolved "https://registry.yarnpkg.com/bowser/-/bowser-2.11.0.tgz#5ca3c35757a7aa5771500c70a73a9f91ef420a8f" + integrity sha512-AlcaJBi/pqqJBIQ8U9Mcpc9i8Aqxn88Skv5d+xBX006BY5u8N3mGLHa5Lgppa7L/HfwgwLgZ6NYs+Ag6uUmJRA== + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -3198,6 +3733,16 @@ tsd@^0.22.0: path-exists "^4.0.0" read-pkg-up "^7.0.0" +tslib@^1.11.1: + version "1.14.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" + integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== + +tslib@^2.3.1: + version "2.4.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3" + integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ== + type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" @@ -3277,6 +3822,11 @@ uuid@^3.3.3: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== +uuid@^8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + v8-compile-cache@^2.0.3: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee" From 59bbbf4c40c5aef64e8d84d3b2414678803a3550 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Thu, 25 Aug 2022 05:19:23 +0000 Subject: [PATCH 02/25] Adlicense text to signer types Signed-off-by: Harsha Vamsi Kalluri --- lib/AwsV4Signer.d.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/AwsV4Signer.d.ts b/lib/AwsV4Signer.d.ts index edcc67544..4bf768471 100644 --- a/lib/AwsV4Signer.d.ts +++ b/lib/AwsV4Signer.d.ts @@ -1,3 +1,33 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Credentials } from '@aws-sdk/types'; import Connection from './Connection'; import * as http from 'http'; From caf4d74f630e0d89d9a1b493e0b3569951384693 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Thu, 25 Aug 2022 21:18:01 +0000 Subject: [PATCH 03/25] Pulling aws signer into separate namespace Signed-off-by: Harsha Vamsi Kalluri --- index.d.ts | 562 ++++++++++++++++++++++++------- index.js | 2 +- lib/AwsV4Signer.d.ts | 47 --- lib/aws/AwsV4Signer.d.ts | 28 ++ lib/{ => aws}/AwsV4Signer.js | 21 +- lib/aws/errors.d.ts | 18 + lib/aws/errors.js | 27 ++ lib/errors.d.ts | 7 - lib/errors.js | 11 - test/types/awsv4signer.test-d.ts | 2 +- test/types/connection.test-d.ts | 4 +- test/unit/awsv4.test.js | 81 +++++ test/unit/client.test.js | 68 ---- 13 files changed, 604 insertions(+), 274 deletions(-) delete mode 100644 lib/AwsV4Signer.d.ts create mode 100644 lib/aws/AwsV4Signer.d.ts rename lib/{ => aws}/AwsV4Signer.js (60%) create mode 100644 lib/aws/errors.d.ts create mode 100644 lib/aws/errors.js create mode 100644 test/unit/awsv4.test.js diff --git a/index.d.ts b/index.d.ts index 3015bb1cc..17a4bb065 100644 --- a/index.d.ts +++ b/index.d.ts @@ -56,7 +56,7 @@ import { ResurrectEvent, BasicAuth, } from './lib/pool'; -import AwsV4Signer from './lib/AwsV4Signer'; +import AwsV4Signer from './lib/aws/AwsV4Signer'; import Serializer from './lib/Serializer'; import Helpers from './lib/Helpers'; import * as errors from './lib/errors'; @@ -93,7 +93,7 @@ interface NodeOptions { ssl?: TlsConnectionOptions; headers?: Record; roles?: { - cluster_manager?: boolean + cluster_manager?: boolean; /** * @deprecated use cluster_manager instead */ @@ -139,7 +139,7 @@ interface ClientOptions { password?: string; }; disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor'; - memoryCircuitBreaker?: MemoryCircuitBreakerOptions + memoryCircuitBreaker?: MemoryCircuitBreakerOptions; } declare class Client { @@ -195,123 +195,451 @@ declare class Client { callback: callbackFn ): TransportRequestCallback; cat: { - aliases, TContext = Context>(params?: RequestParams.CatAliases, options?: TransportRequestOptions): TransportRequestPromise> - aliases, TContext = Context>(callback: callbackFn): TransportRequestCallback - aliases, TContext = Context>(params: RequestParams.CatAliases, callback: callbackFn): TransportRequestCallback - aliases, TContext = Context>(params: RequestParams.CatAliases, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - allocation, TContext = Context>(params?: RequestParams.CatAllocation, options?: TransportRequestOptions): TransportRequestPromise> - allocation, TContext = Context>(callback: callbackFn): TransportRequestCallback - allocation, TContext = Context>(params: RequestParams.CatAllocation, callback: callbackFn): TransportRequestCallback - allocation, TContext = Context>(params: RequestParams.CatAllocation, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - cluster_manager, TContext = Context>(params?: RequestParams.CatClusterManager, options?: TransportRequestOptions): TransportRequestPromise> - cluster_manager, TContext = Context>(callback: callbackFn): TransportRequestCallback - cluster_manager, TContext = Context>(params: RequestParams.CatClusterManager, callback: callbackFn): TransportRequestCallback - cluster_manager, TContext = Context>(params: RequestParams.CatClusterManager, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - count, TContext = Context>(params?: RequestParams.CatCount, options?: TransportRequestOptions): TransportRequestPromise> - count, TContext = Context>(callback: callbackFn): TransportRequestCallback - count, TContext = Context>(params: RequestParams.CatCount, callback: callbackFn): TransportRequestCallback - count, TContext = Context>(params: RequestParams.CatCount, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - fielddata, TContext = Context>(params?: RequestParams.CatFielddata, options?: TransportRequestOptions): TransportRequestPromise> - fielddata, TContext = Context>(callback: callbackFn): TransportRequestCallback - fielddata, TContext = Context>(params: RequestParams.CatFielddata, callback: callbackFn): TransportRequestCallback - fielddata, TContext = Context>(params: RequestParams.CatFielddata, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - health, TContext = Context>(params?: RequestParams.CatHealth, options?: TransportRequestOptions): TransportRequestPromise> - health, TContext = Context>(callback: callbackFn): TransportRequestCallback - health, TContext = Context>(params: RequestParams.CatHealth, callback: callbackFn): TransportRequestCallback - health, TContext = Context>(params: RequestParams.CatHealth, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - help, TContext = Context>(params?: RequestParams.CatHelp, options?: TransportRequestOptions): TransportRequestPromise> - help, TContext = Context>(callback: callbackFn): TransportRequestCallback - help, TContext = Context>(params: RequestParams.CatHelp, callback: callbackFn): TransportRequestCallback - help, TContext = Context>(params: RequestParams.CatHelp, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - indices, TContext = Context>(params?: RequestParams.CatIndices, options?: TransportRequestOptions): TransportRequestPromise> - indices, TContext = Context>(callback: callbackFn): TransportRequestCallback - indices, TContext = Context>(params: RequestParams.CatIndices, callback: callbackFn): TransportRequestCallback - indices, TContext = Context>(params: RequestParams.CatIndices, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback + aliases, TContext = Context>( + params?: RequestParams.CatAliases, + options?: TransportRequestOptions + ): TransportRequestPromise>; + aliases, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + aliases, TContext = Context>( + params: RequestParams.CatAliases, + callback: callbackFn + ): TransportRequestCallback; + aliases, TContext = Context>( + params: RequestParams.CatAliases, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + allocation, TContext = Context>( + params?: RequestParams.CatAllocation, + options?: TransportRequestOptions + ): TransportRequestPromise>; + allocation, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + allocation, TContext = Context>( + params: RequestParams.CatAllocation, + callback: callbackFn + ): TransportRequestCallback; + allocation, TContext = Context>( + params: RequestParams.CatAllocation, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + cluster_manager, TContext = Context>( + params?: RequestParams.CatClusterManager, + options?: TransportRequestOptions + ): TransportRequestPromise>; + cluster_manager, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + cluster_manager, TContext = Context>( + params: RequestParams.CatClusterManager, + callback: callbackFn + ): TransportRequestCallback; + cluster_manager, TContext = Context>( + params: RequestParams.CatClusterManager, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + count, TContext = Context>( + params?: RequestParams.CatCount, + options?: TransportRequestOptions + ): TransportRequestPromise>; + count, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + count, TContext = Context>( + params: RequestParams.CatCount, + callback: callbackFn + ): TransportRequestCallback; + count, TContext = Context>( + params: RequestParams.CatCount, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + fielddata, TContext = Context>( + params?: RequestParams.CatFielddata, + options?: TransportRequestOptions + ): TransportRequestPromise>; + fielddata, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + fielddata, TContext = Context>( + params: RequestParams.CatFielddata, + callback: callbackFn + ): TransportRequestCallback; + fielddata, TContext = Context>( + params: RequestParams.CatFielddata, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + health, TContext = Context>( + params?: RequestParams.CatHealth, + options?: TransportRequestOptions + ): TransportRequestPromise>; + health, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + health, TContext = Context>( + params: RequestParams.CatHealth, + callback: callbackFn + ): TransportRequestCallback; + health, TContext = Context>( + params: RequestParams.CatHealth, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + help, TContext = Context>( + params?: RequestParams.CatHelp, + options?: TransportRequestOptions + ): TransportRequestPromise>; + help, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + help, TContext = Context>( + params: RequestParams.CatHelp, + callback: callbackFn + ): TransportRequestCallback; + help, TContext = Context>( + params: RequestParams.CatHelp, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + indices, TContext = Context>( + params?: RequestParams.CatIndices, + options?: TransportRequestOptions + ): TransportRequestPromise>; + indices, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + indices, TContext = Context>( + params: RequestParams.CatIndices, + callback: callbackFn + ): TransportRequestCallback; + indices, TContext = Context>( + params: RequestParams.CatIndices, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; /** - * // TODO: delete cat.master when it is removed from OpenSearch - * @deprecated use cat.cluster_manager instead - */ - master, TContext = Context>(params?: RequestParams.CatMaster, options?: TransportRequestOptions): TransportRequestPromise> + * // TODO: delete cat.master when it is removed from OpenSearch + * @deprecated use cat.cluster_manager instead + */ + master, TContext = Context>( + params?: RequestParams.CatMaster, + options?: TransportRequestOptions + ): TransportRequestPromise>; /** - * // TODO: delete cat.master when it is removed from OpenSearch - * @deprecated use cat.cluster_manager instead - */ - master, TContext = Context>(callback: callbackFn): TransportRequestCallback + * // TODO: delete cat.master when it is removed from OpenSearch + * @deprecated use cat.cluster_manager instead + */ + master, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; /** - * // TODO: delete cat.master when it is removed from OpenSearch - * @deprecated use cat.cluster_manager instead - */ - master, TContext = Context>(params: RequestParams.CatMaster, callback: callbackFn): TransportRequestCallback + * // TODO: delete cat.master when it is removed from OpenSearch + * @deprecated use cat.cluster_manager instead + */ + master, TContext = Context>( + params: RequestParams.CatMaster, + callback: callbackFn + ): TransportRequestCallback; /** - * // TODO: delete cat.master when it is removed from OpenSearch - * @deprecated use cat.cluster_manager instead - */ - master, TContext = Context>(params: RequestParams.CatMaster, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - nodeattrs, TContext = Context>(params?: RequestParams.CatNodeattrs, options?: TransportRequestOptions): TransportRequestPromise> - nodeattrs, TContext = Context>(callback: callbackFn): TransportRequestCallback - nodeattrs, TContext = Context>(params: RequestParams.CatNodeattrs, callback: callbackFn): TransportRequestCallback - nodeattrs, TContext = Context>(params: RequestParams.CatNodeattrs, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - nodes, TContext = Context>(params?: RequestParams.CatNodes, options?: TransportRequestOptions): TransportRequestPromise> - nodes, TContext = Context>(callback: callbackFn): TransportRequestCallback - nodes, TContext = Context>(params: RequestParams.CatNodes, callback: callbackFn): TransportRequestCallback - nodes, TContext = Context>(params: RequestParams.CatNodes, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - pending_tasks, TContext = Context>(params?: RequestParams.CatPendingTasks, options?: TransportRequestOptions): TransportRequestPromise> - pending_tasks, TContext = Context>(callback: callbackFn): TransportRequestCallback - pending_tasks, TContext = Context>(params: RequestParams.CatPendingTasks, callback: callbackFn): TransportRequestCallback - pending_tasks, TContext = Context>(params: RequestParams.CatPendingTasks, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - pendingTasks, TContext = Context>(params?: RequestParams.CatPendingTasks, options?: TransportRequestOptions): TransportRequestPromise> - pendingTasks, TContext = Context>(callback: callbackFn): TransportRequestCallback - pendingTasks, TContext = Context>(params: RequestParams.CatPendingTasks, callback: callbackFn): TransportRequestCallback - pendingTasks, TContext = Context>(params: RequestParams.CatPendingTasks, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - plugins, TContext = Context>(params?: RequestParams.CatPlugins, options?: TransportRequestOptions): TransportRequestPromise> - plugins, TContext = Context>(callback: callbackFn): TransportRequestCallback - plugins, TContext = Context>(params: RequestParams.CatPlugins, callback: callbackFn): TransportRequestCallback - plugins, TContext = Context>(params: RequestParams.CatPlugins, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - recovery, TContext = Context>(params?: RequestParams.CatRecovery, options?: TransportRequestOptions): TransportRequestPromise> - recovery, TContext = Context>(callback: callbackFn): TransportRequestCallback - recovery, TContext = Context>(params: RequestParams.CatRecovery, callback: callbackFn): TransportRequestCallback - recovery, TContext = Context>(params: RequestParams.CatRecovery, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - repositories, TContext = Context>(params?: RequestParams.CatRepositories, options?: TransportRequestOptions): TransportRequestPromise> - repositories, TContext = Context>(callback: callbackFn): TransportRequestCallback - repositories, TContext = Context>(params: RequestParams.CatRepositories, callback: callbackFn): TransportRequestCallback - repositories, TContext = Context>(params: RequestParams.CatRepositories, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - segments, TContext = Context>(params?: RequestParams.CatSegments, options?: TransportRequestOptions): TransportRequestPromise> - segments, TContext = Context>(callback: callbackFn): TransportRequestCallback - segments, TContext = Context>(params: RequestParams.CatSegments, callback: callbackFn): TransportRequestCallback - segments, TContext = Context>(params: RequestParams.CatSegments, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - shards, TContext = Context>(params?: RequestParams.CatShards, options?: TransportRequestOptions): TransportRequestPromise> - shards, TContext = Context>(callback: callbackFn): TransportRequestCallback - shards, TContext = Context>(params: RequestParams.CatShards, callback: callbackFn): TransportRequestCallback - shards, TContext = Context>(params: RequestParams.CatShards, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - snapshots, TContext = Context>(params?: RequestParams.CatSnapshots, options?: TransportRequestOptions): TransportRequestPromise> - snapshots, TContext = Context>(callback: callbackFn): TransportRequestCallback - snapshots, TContext = Context>(params: RequestParams.CatSnapshots, callback: callbackFn): TransportRequestCallback - snapshots, TContext = Context>(params: RequestParams.CatSnapshots, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - tasks, TContext = Context>(params?: RequestParams.CatTasks, options?: TransportRequestOptions): TransportRequestPromise> - tasks, TContext = Context>(callback: callbackFn): TransportRequestCallback - tasks, TContext = Context>(params: RequestParams.CatTasks, callback: callbackFn): TransportRequestCallback - tasks, TContext = Context>(params: RequestParams.CatTasks, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - templates, TContext = Context>(params?: RequestParams.CatTemplates, options?: TransportRequestOptions): TransportRequestPromise> - templates, TContext = Context>(callback: callbackFn): TransportRequestCallback - templates, TContext = Context>(params: RequestParams.CatTemplates, callback: callbackFn): TransportRequestCallback - templates, TContext = Context>(params: RequestParams.CatTemplates, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - thread_pool, TContext = Context>(params?: RequestParams.CatThreadPool, options?: TransportRequestOptions): TransportRequestPromise> - thread_pool, TContext = Context>(callback: callbackFn): TransportRequestCallback - thread_pool, TContext = Context>(params: RequestParams.CatThreadPool, callback: callbackFn): TransportRequestCallback - thread_pool, TContext = Context>(params: RequestParams.CatThreadPool, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - threadPool, TContext = Context>(params?: RequestParams.CatThreadPool, options?: TransportRequestOptions): TransportRequestPromise> - threadPool, TContext = Context>(callback: callbackFn): TransportRequestCallback - threadPool, TContext = Context>(params: RequestParams.CatThreadPool, callback: callbackFn): TransportRequestCallback - threadPool, TContext = Context>(params: RequestParams.CatThreadPool, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - } - clear_scroll, TRequestBody extends RequestBody = Record, TContext = Context>(params?: RequestParams.ClearScroll, options?: TransportRequestOptions): TransportRequestPromise> - clear_scroll, TRequestBody extends RequestBody = Record, TContext = Context>(callback: callbackFn): TransportRequestCallback - clear_scroll, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.ClearScroll, callback: callbackFn): TransportRequestCallback - clear_scroll, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.ClearScroll, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback - clearScroll, TRequestBody extends RequestBody = Record, TContext = Context>(params?: RequestParams.ClearScroll, options?: TransportRequestOptions): TransportRequestPromise> - clearScroll, TRequestBody extends RequestBody = Record, TContext = Context>(callback: callbackFn): TransportRequestCallback - clearScroll, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.ClearScroll, callback: callbackFn): TransportRequestCallback - clearScroll, TRequestBody extends RequestBody = Record, TContext = Context>(params: RequestParams.ClearScroll, options: TransportRequestOptions, callback: callbackFn): TransportRequestCallback + * // TODO: delete cat.master when it is removed from OpenSearch + * @deprecated use cat.cluster_manager instead + */ + master, TContext = Context>( + params: RequestParams.CatMaster, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + nodeattrs, TContext = Context>( + params?: RequestParams.CatNodeattrs, + options?: TransportRequestOptions + ): TransportRequestPromise>; + nodeattrs, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + nodeattrs, TContext = Context>( + params: RequestParams.CatNodeattrs, + callback: callbackFn + ): TransportRequestCallback; + nodeattrs, TContext = Context>( + params: RequestParams.CatNodeattrs, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + nodes, TContext = Context>( + params?: RequestParams.CatNodes, + options?: TransportRequestOptions + ): TransportRequestPromise>; + nodes, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + nodes, TContext = Context>( + params: RequestParams.CatNodes, + callback: callbackFn + ): TransportRequestCallback; + nodes, TContext = Context>( + params: RequestParams.CatNodes, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + pending_tasks, TContext = Context>( + params?: RequestParams.CatPendingTasks, + options?: TransportRequestOptions + ): TransportRequestPromise>; + pending_tasks, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + pending_tasks, TContext = Context>( + params: RequestParams.CatPendingTasks, + callback: callbackFn + ): TransportRequestCallback; + pending_tasks, TContext = Context>( + params: RequestParams.CatPendingTasks, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + pendingTasks, TContext = Context>( + params?: RequestParams.CatPendingTasks, + options?: TransportRequestOptions + ): TransportRequestPromise>; + pendingTasks, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + pendingTasks, TContext = Context>( + params: RequestParams.CatPendingTasks, + callback: callbackFn + ): TransportRequestCallback; + pendingTasks, TContext = Context>( + params: RequestParams.CatPendingTasks, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + plugins, TContext = Context>( + params?: RequestParams.CatPlugins, + options?: TransportRequestOptions + ): TransportRequestPromise>; + plugins, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + plugins, TContext = Context>( + params: RequestParams.CatPlugins, + callback: callbackFn + ): TransportRequestCallback; + plugins, TContext = Context>( + params: RequestParams.CatPlugins, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + recovery, TContext = Context>( + params?: RequestParams.CatRecovery, + options?: TransportRequestOptions + ): TransportRequestPromise>; + recovery, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + recovery, TContext = Context>( + params: RequestParams.CatRecovery, + callback: callbackFn + ): TransportRequestCallback; + recovery, TContext = Context>( + params: RequestParams.CatRecovery, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + repositories, TContext = Context>( + params?: RequestParams.CatRepositories, + options?: TransportRequestOptions + ): TransportRequestPromise>; + repositories, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + repositories, TContext = Context>( + params: RequestParams.CatRepositories, + callback: callbackFn + ): TransportRequestCallback; + repositories, TContext = Context>( + params: RequestParams.CatRepositories, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + segments, TContext = Context>( + params?: RequestParams.CatSegments, + options?: TransportRequestOptions + ): TransportRequestPromise>; + segments, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + segments, TContext = Context>( + params: RequestParams.CatSegments, + callback: callbackFn + ): TransportRequestCallback; + segments, TContext = Context>( + params: RequestParams.CatSegments, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + shards, TContext = Context>( + params?: RequestParams.CatShards, + options?: TransportRequestOptions + ): TransportRequestPromise>; + shards, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + shards, TContext = Context>( + params: RequestParams.CatShards, + callback: callbackFn + ): TransportRequestCallback; + shards, TContext = Context>( + params: RequestParams.CatShards, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + snapshots, TContext = Context>( + params?: RequestParams.CatSnapshots, + options?: TransportRequestOptions + ): TransportRequestPromise>; + snapshots, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + snapshots, TContext = Context>( + params: RequestParams.CatSnapshots, + callback: callbackFn + ): TransportRequestCallback; + snapshots, TContext = Context>( + params: RequestParams.CatSnapshots, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + tasks, TContext = Context>( + params?: RequestParams.CatTasks, + options?: TransportRequestOptions + ): TransportRequestPromise>; + tasks, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + tasks, TContext = Context>( + params: RequestParams.CatTasks, + callback: callbackFn + ): TransportRequestCallback; + tasks, TContext = Context>( + params: RequestParams.CatTasks, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + templates, TContext = Context>( + params?: RequestParams.CatTemplates, + options?: TransportRequestOptions + ): TransportRequestPromise>; + templates, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + templates, TContext = Context>( + params: RequestParams.CatTemplates, + callback: callbackFn + ): TransportRequestCallback; + templates, TContext = Context>( + params: RequestParams.CatTemplates, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + thread_pool, TContext = Context>( + params?: RequestParams.CatThreadPool, + options?: TransportRequestOptions + ): TransportRequestPromise>; + thread_pool, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + thread_pool, TContext = Context>( + params: RequestParams.CatThreadPool, + callback: callbackFn + ): TransportRequestCallback; + thread_pool, TContext = Context>( + params: RequestParams.CatThreadPool, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + threadPool, TContext = Context>( + params?: RequestParams.CatThreadPool, + options?: TransportRequestOptions + ): TransportRequestPromise>; + threadPool, TContext = Context>( + callback: callbackFn + ): TransportRequestCallback; + threadPool, TContext = Context>( + params: RequestParams.CatThreadPool, + callback: callbackFn + ): TransportRequestCallback; + threadPool, TContext = Context>( + params: RequestParams.CatThreadPool, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + }; + clear_scroll< + TResponse = Record, + TRequestBody extends RequestBody = Record, + TContext = Context + >( + params?: RequestParams.ClearScroll, + options?: TransportRequestOptions + ): TransportRequestPromise>; + clear_scroll< + TResponse = Record, + TRequestBody extends RequestBody = Record, + TContext = Context + >(callback: callbackFn): TransportRequestCallback; + clear_scroll< + TResponse = Record, + TRequestBody extends RequestBody = Record, + TContext = Context + >( + params: RequestParams.ClearScroll, + callback: callbackFn + ): TransportRequestCallback; + clear_scroll< + TResponse = Record, + TRequestBody extends RequestBody = Record, + TContext = Context + >( + params: RequestParams.ClearScroll, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; + clearScroll< + TResponse = Record, + TRequestBody extends RequestBody = Record, + TContext = Context + >( + params?: RequestParams.ClearScroll, + options?: TransportRequestOptions + ): TransportRequestPromise>; + clearScroll< + TResponse = Record, + TRequestBody extends RequestBody = Record, + TContext = Context + >(callback: callbackFn): TransportRequestCallback; + clearScroll< + TResponse = Record, + TRequestBody extends RequestBody = Record, + TContext = Context + >( + params: RequestParams.ClearScroll, + callback: callbackFn + ): TransportRequestCallback; + clearScroll< + TResponse = Record, + TRequestBody extends RequestBody = Record, + TContext = Context + >( + params: RequestParams.ClearScroll, + options: TransportRequestOptions, + callback: callbackFn + ): TransportRequestCallback; cluster: { allocation_explain< TResponse = Record, @@ -5051,5 +5379,5 @@ export { ClientOptions, NodeOptions, ClientExtendsCallbackOptions, - AwsV4Signer + AwsV4Signer, }; diff --git a/index.js b/index.js index 1e946c8bc..bf3ce9993 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ if (clientVersion.includes('-')) { // clean prerelease clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'; } -const AwsV4Signer = require('./lib/AwsV4Signer'); +const AwsV4Signer = require('./lib/aws/AwsV4Signer'); const kInitialOptions = Symbol('opensearchjs-initial-options'); const kChild = Symbol('opensearchjs-child'); diff --git a/lib/AwsV4Signer.d.ts b/lib/AwsV4Signer.d.ts deleted file mode 100644 index 4bf768471..000000000 --- a/lib/AwsV4Signer.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { Credentials } from '@aws-sdk/types'; -import Connection from './Connection'; -import * as http from 'http'; - -interface AwsV4SignerOptions { - credentials: Credentials; - region: string; -} - -export interface AwsV4SignerResponse { - Connection: Connection; - buildSignedRequestObject(request: any): http.ClientRequestArgs; -} - -export default function AwsV4Signer(opts: AwsV4SignerOptions): AwsV4SignerResponse; - -export {}; diff --git a/lib/aws/AwsV4Signer.d.ts b/lib/aws/AwsV4Signer.d.ts new file mode 100644 index 000000000..877269774 --- /dev/null +++ b/lib/aws/AwsV4Signer.d.ts @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { Credentials } from '@aws-sdk/types'; +import Connection from '../Connection'; +import * as http from 'http'; + +interface AwsV4SignerOptions { + credentials: Credentials; + region: string; +} + +export interface AwsV4SignerResponse { + Connection: Connection; + buildSignedRequestObject(request: any): http.ClientRequestArgs; +} + +export default function AwsV4Signer(opts: AwsV4SignerOptions): AwsV4SignerResponse; + +export {}; diff --git a/lib/AwsV4Signer.js b/lib/aws/AwsV4Signer.js similarity index 60% rename from lib/AwsV4Signer.js rename to lib/aws/AwsV4Signer.js index ca3b12d1b..843d6b25e 100644 --- a/lib/AwsV4Signer.js +++ b/lib/aws/AwsV4Signer.js @@ -9,27 +9,8 @@ * GitHub history for details. */ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - 'use strict'; -const Connection = require('./Connection'); +const Connection = require('../Connection'); const aws4 = require('aws4'); const { AwsV4SignerError } = require('./errors'); diff --git a/lib/aws/errors.d.ts b/lib/aws/errors.d.ts new file mode 100644 index 000000000..b49d3ddd8 --- /dev/null +++ b/lib/aws/errors.d.ts @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ +import { OpenSearchClientError } from '../errors'; + +export declare class AwsV4SignerError extends OpenSearchClientError { + name: string; + message: string; + data: any; + constructor(message: string, data: any); +} diff --git a/lib/aws/errors.js b/lib/aws/errors.js new file mode 100644 index 000000000..8252563f2 --- /dev/null +++ b/lib/aws/errors.js @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +'use strict'; +const { OpenSearchClientError } = require('../errors'); + +class AwsV4SignerError extends OpenSearchClientError { + constructor(message, data) { + super(message, data); + Error.captureStackTrace(this, AwsV4SignerError); + this.name = 'AwsV4SignerError'; + this.message = message || 'AwsV4Signer Error'; + this.data = data; + } +} + +module.exports = { + AwsV4SignerError, +}; diff --git a/lib/errors.d.ts b/lib/errors.d.ts index 66d176d7c..b49485963 100644 --- a/lib/errors.d.ts +++ b/lib/errors.d.ts @@ -117,10 +117,3 @@ export declare class NotCompatibleError< meta: ApiResponse; constructor(meta: ApiResponse); } - -export declare class AwsV4SignerError extends OpenSearchClientError { - name: string; - message: string; - data: any; - constructor(message: string, data: any); -} diff --git a/lib/errors.js b/lib/errors.js index 93d07a8b4..068b63247 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -158,16 +158,6 @@ class NotCompatibleError extends OpenSearchClientError { } } -class AwsV4SignerError extends OpenSearchClientError { - constructor(message, data) { - super(message, data); - Error.captureStackTrace(this, AwsV4SignerError); - this.name = 'AwsV4SignerError'; - this.message = message || 'AwsV4Signer Error'; - this.data = data; - } -} - module.exports = { OpenSearchClientError, TimeoutError, @@ -179,5 +169,4 @@ module.exports = { ResponseError, RequestAbortedError, NotCompatibleError, - AwsV4SignerError, }; diff --git a/test/types/awsv4signer.test-d.ts b/test/types/awsv4signer.test-d.ts index 0b63c9897..3e5cb9e3b 100644 --- a/test/types/awsv4signer.test-d.ts +++ b/test/types/awsv4signer.test-d.ts @@ -30,7 +30,7 @@ import { expectType } from 'tsd'; import { AwsV4Signer } from '../../'; -import { AwsV4SignerResponse } from '../../lib/AwsV4Signer'; +import { AwsV4SignerResponse } from '../../lib/aws/AwsV4Signer'; const mockCreds = { accessKeyId: 'mockCredAccessKeyId', diff --git a/test/types/connection.test-d.ts b/test/types/connection.test-d.ts index 7e7606c69..1abbc0ccb 100644 --- a/test/types/connection.test-d.ts +++ b/test/types/connection.test-d.ts @@ -42,8 +42,8 @@ import { ConnectionOptions } from '../../lib/Connection'; agent: { keepAlive: false }, status: 'alive', roles: {}, - auth: { username: 'username', password: 'password' } - }) + auth: { username: 'username', password: 'password' }, + }); expectType(conn); expectType(conn.url); diff --git a/test/unit/awsv4.test.js b/test/unit/awsv4.test.js new file mode 100644 index 000000000..f16b7df53 --- /dev/null +++ b/test/unit/awsv4.test.js @@ -0,0 +1,81 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ +const { test } = require('tap'); +const { URL } = require('url'); +const { v4: uuidv4 } = require('uuid'); +const { AwsV4Signer } = require('../../index'); +const { AwsV4SignerError } = require('../../lib/aws/errors'); +const { Connection } = require('../../index'); + +test('Sign with SigV4', (t) => { + t.plan(2); + + const mockCreds = { + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + }; + + const mockRegion = 'us-west-2'; + + const AwsV4SignerOptions = { credentials: mockCreds, region: mockRegion }; + + const auth = AwsV4Signer(AwsV4SignerOptions); + + const connection = new Connection({ + url: new URL('https://localhost:9200'), + }); + + const request = connection.buildRequestObject({ + path: '/hello', + method: 'GET', + headers: { + 'X-Custom-Test': true, + }, + }); + const signedRequest = auth.buildSignedRequestObject(request); + t.hasProp(signedRequest.headers, 'X-Amz-Date'); + t.hasProp(signedRequest.headers, 'Authorization'); +}); + +test('Sign with SigV4 failure (with empty region)', (t) => { + t.plan(2); + + const mockCreds = { + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + }; + + const AwsV4SignerOptions = { credentials: mockCreds }; + + try { + AwsV4Signer(AwsV4SignerOptions); + t.fail('Should fail'); + } catch (err) { + t.ok(err instanceof AwsV4SignerError); + t.equal(err.message, 'Region cannot be empty'); + } +}); + +test('Sign with SigV4 failure (with empty credentials)', (t) => { + t.plan(2); + + const mockRegion = 'us-west-2'; + + const AwsV4SignerOptions = { region: mockRegion }; + + try { + AwsV4Signer(AwsV4SignerOptions); + t.fail('Should fail'); + } catch (err) { + t.ok(err instanceof AwsV4SignerError); + t.equal(err.message, 'Credentials cannot be empty'); + } +}); diff --git a/test/unit/client.test.js b/test/unit/client.test.js index bb5761fd8..4a4f2bf98 100644 --- a/test/unit/client.test.js +++ b/test/unit/client.test.js @@ -33,12 +33,9 @@ const { test } = require('tap'); const { URL } = require('url'); const buffer = require('buffer'); -const { v4: uuidv4 } = require('uuid'); const intoStream = require('into-stream'); const { ConnectionPool, Transport, Connection, errors } = require('../../index'); const { Client, buildServer } = require('../utils'); -const { AwsV4Signer } = require('../../index'); -const { AwsV4SignerError } = require('../../lib/errors'); let clientVersion = require('../../package.json').version; if (clientVersion.includes('-')) { clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'; @@ -1192,68 +1189,3 @@ test('API compatibility header (x-ndjson)', (t) => { }); }); }); - -test('Sign with SigV4', (t) => { - t.plan(2); - - const mockCreds = { - accessKeyId: uuidv4(), - secretAccessKey: uuidv4(), - }; - - const mockRegion = 'us-west-2'; - - const AwsV4SignerOptions = { credentials: mockCreds, region: mockRegion }; - - const auth = AwsV4Signer(AwsV4SignerOptions); - - const connection = new Connection({ - url: new URL('https://localhost:9200'), - }); - - const request = connection.buildRequestObject({ - path: '/hello', - method: 'GET', - headers: { - 'X-Custom-Test': true, - }, - }); - const signedRequest = auth.buildSignedRequestObject(request); - t.hasProp(signedRequest.headers, 'X-Amz-Date'); - t.hasProp(signedRequest.headers, 'Authorization'); -}); - -test('Sign with SigV4 failure (with empty region)', (t) => { - t.plan(2); - - const mockCreds = { - accessKeyId: uuidv4(), - secretAccessKey: uuidv4(), - }; - - const AwsV4SignerOptions = { credentials: mockCreds }; - - try { - AwsV4Signer(AwsV4SignerOptions); - t.fail('Should fail'); - } catch (err) { - t.ok(err instanceof AwsV4SignerError); - t.equal(err.message, 'Region cannot be empty'); - } -}); - -test('Sign with SigV4 failure (with empty credentials)', (t) => { - t.plan(2); - - const mockRegion = 'us-west-2'; - - const AwsV4SignerOptions = { region: mockRegion }; - - try { - AwsV4Signer(AwsV4SignerOptions); - t.fail('Should fail'); - } catch (err) { - t.ok(err instanceof AwsV4SignerError); - t.equal(err.message, 'Credentials cannot be empty'); - } -}); From 7faaae1af75effa5e062226e82324678d0b911bd Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Fri, 26 Aug 2022 16:27:30 +0000 Subject: [PATCH 04/25] Adding separate injection point for v4Signer Signed-off-by: Harsha Vamsi Kalluri --- README.md | 7 ++++--- index.d.ts | 2 -- index.js | 2 -- index.mjs | 1 - package.json | 1 + test/types/awsv4signer.test-d.ts | 8 ++++---- test/unit/awsv4.test.js | 2 +- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6b782c1ac..4cba3c6f4 100644 --- a/README.md +++ b/README.md @@ -154,8 +154,9 @@ search().catch(console.log); ### With AWS SigV4 signing ```javascript -const host = ""; // Opensearch domain URL e.g. https://search-xxx.region.es.amazonaws.com -const { Client, AwsV4Signer } = require('@opensearch-project/opensearch'); +const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com +const { Client } = require('@opensearch-project/opensearch'); +const AwsV4Signer = require('@opensearch-project/opensearch/AwsV4Signer'); const { defaultProvider } = require("@aws-sdk/credential-provider-node"); async function getClient() { @@ -165,7 +166,7 @@ async function getClient() { credentials: credentials, region: "us-west-2", }), - node: host, + node: endpoint, }); return client; } diff --git a/index.d.ts b/index.d.ts index 17a4bb065..6e9ac2a82 100644 --- a/index.d.ts +++ b/index.d.ts @@ -56,7 +56,6 @@ import { ResurrectEvent, BasicAuth, } from './lib/pool'; -import AwsV4Signer from './lib/aws/AwsV4Signer'; import Serializer from './lib/Serializer'; import Helpers from './lib/Helpers'; import * as errors from './lib/errors'; @@ -5379,5 +5378,4 @@ export { ClientOptions, NodeOptions, ClientExtendsCallbackOptions, - AwsV4Signer, }; diff --git a/index.js b/index.js index bf3ce9993..e36a0b679 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,6 @@ if (clientVersion.includes('-')) { // clean prerelease clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'; } -const AwsV4Signer = require('./lib/aws/AwsV4Signer'); const kInitialOptions = Symbol('opensearchjs-initial-options'); const kChild = Symbol('opensearchjs-child'); @@ -349,5 +348,4 @@ module.exports = { Serializer, events, errors, - AwsV4Signer, }; diff --git a/index.mjs b/index.mjs index c1335abbf..75ef740d9 100644 --- a/index.mjs +++ b/index.mjs @@ -38,4 +38,3 @@ export const Connection = mod.Connection; export const Serializer = mod.Serializer; export const events = mod.events; export const errors = mod.errors; -export const awsV4Signer = mod.AwsV4Signer; diff --git a/package.json b/package.json index 36530c485..907066196 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "require": "./index.js", "import": "./index.mjs" }, + "./awsV4Signer": "./lib/aws/AwsV4Signer.js", "./": "./" }, "homepage": "https://www.opensearch.org/", diff --git a/test/types/awsv4signer.test-d.ts b/test/types/awsv4signer.test-d.ts index 3e5cb9e3b..253a7ddf9 100644 --- a/test/types/awsv4signer.test-d.ts +++ b/test/types/awsv4signer.test-d.ts @@ -29,12 +29,12 @@ */ import { expectType } from 'tsd'; -import { AwsV4Signer } from '../../'; -import { AwsV4SignerResponse } from '../../lib/aws/AwsV4Signer'; +const { v4: uuidv4 } = require('uuid'); +import AwsV4Signer, { AwsV4SignerResponse } from '../../lib/aws/AwsV4Signer'; const mockCreds = { - accessKeyId: 'mockCredAccessKeyId', - secretAccessKey: 'mockCredSecretAccessKey', + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), }; const mockRegion = 'us-west-2'; diff --git a/test/unit/awsv4.test.js b/test/unit/awsv4.test.js index f16b7df53..5895e7928 100644 --- a/test/unit/awsv4.test.js +++ b/test/unit/awsv4.test.js @@ -11,7 +11,7 @@ const { test } = require('tap'); const { URL } = require('url'); const { v4: uuidv4 } = require('uuid'); -const { AwsV4Signer } = require('../../index'); +const AwsV4Signer = require('../../lib/aws/AwsV4Signer'); const { AwsV4SignerError } = require('../../lib/aws/errors'); const { Connection } = require('../../index'); From 6a671794bcee945d8dbab9a3bdb2c0caa279ea02 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Fri, 26 Aug 2022 23:07:47 +0000 Subject: [PATCH 05/25] Fix name spacing and bump version Signed-off-by: Harsha Vamsi Kalluri --- README.md | 3 +- lib/aws/{AwsV4Signer.js => AwsSigv4Signer.js} | 14 +++--- lib/aws/errors.js | 12 ++--- lib/aws/{AwsV4Signer.d.ts => index.d.ts} | 18 +++++-- lib/aws/{errors.d.ts => index.js} | 16 ++++--- package.json | 14 +++++- test/types/awssigv4signer.test-d.ts | 29 +++++++++++ test/types/awsv4signer.test-d.ts | 48 ------------------- .../{awsv4.test.js => awssigv4signer.test.js} | 20 ++++---- 9 files changed, 88 insertions(+), 86 deletions(-) rename lib/aws/{AwsV4Signer.js => AwsSigv4Signer.js} (75%) rename lib/aws/{AwsV4Signer.d.ts => index.d.ts} (53%) rename lib/aws/{errors.d.ts => index.js} (57%) create mode 100644 test/types/awssigv4signer.test-d.ts delete mode 100644 test/types/awsv4signer.test-d.ts rename test/unit/{awsv4.test.js => awssigv4signer.test.js} (73%) diff --git a/README.md b/README.md index 4cba3c6f4..32e816e5d 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ OpenSearch Node.js client - [Example use](#example-use) - [Setup](#setup) - [Sample code](#sample-code) + - [With AWS SigV4 signing](#with-aws-sigv4-signing) - [Project Resources](#project-resources) - [Code of Conduct](#code-of-conduct) - [License](#license) @@ -156,7 +157,7 @@ search().catch(console.log); ```javascript const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com const { Client } = require('@opensearch-project/opensearch'); -const AwsV4Signer = require('@opensearch-project/opensearch/AwsV4Signer'); +const { AwsSigV4Signer } = require('@opensearch-project/opensearch/aws'); const { defaultProvider } = require("@aws-sdk/credential-provider-node"); async function getClient() { diff --git a/lib/aws/AwsV4Signer.js b/lib/aws/AwsSigv4Signer.js similarity index 75% rename from lib/aws/AwsV4Signer.js rename to lib/aws/AwsSigv4Signer.js index 843d6b25e..3c6f4d519 100644 --- a/lib/aws/AwsV4Signer.js +++ b/lib/aws/AwsSigv4Signer.js @@ -12,14 +12,14 @@ 'use strict'; const Connection = require('../Connection'); const aws4 = require('aws4'); -const { AwsV4SignerError } = require('./errors'); +const AwsSigv4SignerError = require('./errors'); -function AwsV4Signer(opts) { +function AwsSigv4Signer(opts) { if (opts && (!opts.region || opts.region === null || opts.region === '')) { - throw new AwsV4SignerError('Region cannot be empty'); + throw new AwsSigv4SignerError('Region cannot be empty'); } if (opts && (!opts.credentials || opts.credentials === null || opts.credentials === '')) { - throw new AwsV4SignerError('Credentials cannot be empty'); + throw new AwsSigv4SignerError('Credentials cannot be empty'); } function buildSignedRequestObject(request = {}) { @@ -29,15 +29,15 @@ function AwsV4Signer(opts) { request.headers['host'] = request.hostname; return aws4.sign(request, opts.credentials); } - class AwsV4SignedConnection extends Connection { + class AwsSigv4SignerConnection extends Connection { buildRequestObject(params) { const request = super.buildRequestObject(params); return buildSignedRequestObject(request); } } return { - Connection: AwsV4SignedConnection, + Connection: AwsSigv4SignerConnection, buildSignedRequestObject, }; } -module.exports = AwsV4Signer; +module.exports = AwsSigv4Signer; diff --git a/lib/aws/errors.js b/lib/aws/errors.js index 8252563f2..b93e80274 100644 --- a/lib/aws/errors.js +++ b/lib/aws/errors.js @@ -12,16 +12,14 @@ 'use strict'; const { OpenSearchClientError } = require('../errors'); -class AwsV4SignerError extends OpenSearchClientError { +class AwsSigv4SignerError extends OpenSearchClientError { constructor(message, data) { super(message, data); - Error.captureStackTrace(this, AwsV4SignerError); - this.name = 'AwsV4SignerError'; - this.message = message || 'AwsV4Signer Error'; + Error.captureStackTrace(this, AwsSigv4SignerError); + this.name = 'AwsSigv4SignerError'; + this.message = message || 'AwsSigv4Signer Error'; this.data = data; } } -module.exports = { - AwsV4SignerError, -}; +module.exports = AwsSigv4SignerError; diff --git a/lib/aws/AwsV4Signer.d.ts b/lib/aws/index.d.ts similarity index 53% rename from lib/aws/AwsV4Signer.d.ts rename to lib/aws/index.d.ts index 877269774..9f97913ed 100644 --- a/lib/aws/AwsV4Signer.d.ts +++ b/lib/aws/index.d.ts @@ -9,20 +9,30 @@ * GitHub history for details. */ +/// + import { Credentials } from '@aws-sdk/types'; import Connection from '../Connection'; import * as http from 'http'; +import { OpenSearchClientError } from '../errors'; -interface AwsV4SignerOptions { +interface AwsSigv4SignerOptions { credentials: Credentials; region: string; } -export interface AwsV4SignerResponse { +interface AwsSigv4SignerResponse { Connection: Connection; buildSignedRequestObject(request: any): http.ClientRequestArgs; } -export default function AwsV4Signer(opts: AwsV4SignerOptions): AwsV4SignerResponse; +declare function AwsSigv4Signer(opts: AwsSigv4SignerOptions): AwsSigv4SignerResponse; + +declare class AwsSigv4SignerError extends OpenSearchClientError { + name: string; + message: string; + data: any; + constructor(message: string, data: any); +} -export {}; +export { AwsSigv4Signer, AwsSigv4SignerOptions, AwsSigv4SignerResponse, AwsSigv4SignerError }; diff --git a/lib/aws/errors.d.ts b/lib/aws/index.js similarity index 57% rename from lib/aws/errors.d.ts rename to lib/aws/index.js index b49d3ddd8..8586dbb18 100644 --- a/lib/aws/errors.d.ts +++ b/lib/aws/index.js @@ -8,11 +8,13 @@ * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. */ -import { OpenSearchClientError } from '../errors'; -export declare class AwsV4SignerError extends OpenSearchClientError { - name: string; - message: string; - data: any; - constructor(message: string, data: any); -} +'use strict'; + +const AwsSigv4Signer = require('./AwsSigv4Signer'); +const AwsSigv4SignerError = require('./errors'); + +module.exports = { + AwsSigv4Signer, + AwsSigv4SignerError, +}; diff --git a/package.json b/package.json index 907066196..df845a119 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,21 @@ "require": "./index.js", "import": "./index.mjs" }, - "./awsV4Signer": "./lib/aws/AwsV4Signer.js", + "./aws": "./lib/aws/index.js", "./": "./" }, + "typesVersions": { + "*": { + ".": [ + "index.d.ts" + ], + "aws": [ + "./lib/aws/index.d.ts" + ] + } + }, "homepage": "https://www.opensearch.org/", - "version": "2.0.0", + "version": "2.1.0", "versionCanary": "7.10.0-canary.6", "keywords": [ "opensearch", diff --git a/test/types/awssigv4signer.test-d.ts b/test/types/awssigv4signer.test-d.ts new file mode 100644 index 000000000..ca9e2f4a2 --- /dev/null +++ b/test/types/awssigv4signer.test-d.ts @@ -0,0 +1,29 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import { expectType } from 'tsd'; +const { v4: uuidv4 } = require('uuid'); +import { AwsSigv4SignerResponse, AwsSigv4Signer } from '../../lib/aws'; + +const mockCreds = { + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), +}; + +const mockRegion = 'us-west-2'; + +{ + const AwsSigv4SignerOptions = { credentials: mockCreds, region: mockRegion }; + + const auth = AwsSigv4Signer(AwsSigv4SignerOptions); + + expectType(auth); +} diff --git a/test/types/awsv4signer.test-d.ts b/test/types/awsv4signer.test-d.ts deleted file mode 100644 index 253a7ddf9..000000000 --- a/test/types/awsv4signer.test-d.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { expectType } from 'tsd'; -const { v4: uuidv4 } = require('uuid'); -import AwsV4Signer, { AwsV4SignerResponse } from '../../lib/aws/AwsV4Signer'; - -const mockCreds = { - accessKeyId: uuidv4(), - secretAccessKey: uuidv4(), -}; - -const mockRegion = 'us-west-2'; - -{ - const AwsV4SignerOptions = { credentials: mockCreds, region: mockRegion }; - - const auth = AwsV4Signer(AwsV4SignerOptions); - - expectType(auth); -} diff --git a/test/unit/awsv4.test.js b/test/unit/awssigv4signer.test.js similarity index 73% rename from test/unit/awsv4.test.js rename to test/unit/awssigv4signer.test.js index 5895e7928..c3a7e9e56 100644 --- a/test/unit/awsv4.test.js +++ b/test/unit/awssigv4signer.test.js @@ -11,8 +11,8 @@ const { test } = require('tap'); const { URL } = require('url'); const { v4: uuidv4 } = require('uuid'); -const AwsV4Signer = require('../../lib/aws/AwsV4Signer'); -const { AwsV4SignerError } = require('../../lib/aws/errors'); +const AwsSigv4Signer = require('../../lib/aws/AwsSigv4Signer'); +const AwsSigv4SignerError = require('../../lib/aws/errors'); const { Connection } = require('../../index'); test('Sign with SigV4', (t) => { @@ -25,9 +25,9 @@ test('Sign with SigV4', (t) => { const mockRegion = 'us-west-2'; - const AwsV4SignerOptions = { credentials: mockCreds, region: mockRegion }; + const AwsSigv4SignerOptions = { credentials: mockCreds, region: mockRegion }; - const auth = AwsV4Signer(AwsV4SignerOptions); + const auth = AwsSigv4Signer(AwsSigv4SignerOptions); const connection = new Connection({ url: new URL('https://localhost:9200'), @@ -53,13 +53,13 @@ test('Sign with SigV4 failure (with empty region)', (t) => { secretAccessKey: uuidv4(), }; - const AwsV4SignerOptions = { credentials: mockCreds }; + const AwsSigv4SignerOptions = { credentials: mockCreds }; try { - AwsV4Signer(AwsV4SignerOptions); + AwsSigv4Signer(AwsSigv4SignerOptions); t.fail('Should fail'); } catch (err) { - t.ok(err instanceof AwsV4SignerError); + t.ok(err instanceof AwsSigv4SignerError); t.equal(err.message, 'Region cannot be empty'); } }); @@ -69,13 +69,13 @@ test('Sign with SigV4 failure (with empty credentials)', (t) => { const mockRegion = 'us-west-2'; - const AwsV4SignerOptions = { region: mockRegion }; + const AwsSigv4SignerOptions = { region: mockRegion }; try { - AwsV4Signer(AwsV4SignerOptions); + AwsSigv4Signer(AwsSigv4SignerOptions); t.fail('Should fail'); } catch (err) { - t.ok(err instanceof AwsV4SignerError); + t.ok(err instanceof AwsSigv4SignerError); t.equal(err.message, 'Credentials cannot be empty'); } }); From 90a443daac086119d52ca58d78f4fa138c0d7bef Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Fri, 26 Aug 2022 23:08:25 +0000 Subject: [PATCH 06/25] Typo in readme Signed-off-by: Harsha Vamsi Kalluri --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32e816e5d..466b94ca9 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ search().catch(console.log); ```javascript const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com const { Client } = require('@opensearch-project/opensearch'); -const { AwsSigV4Signer } = require('@opensearch-project/opensearch/aws'); +const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); const { defaultProvider } = require("@aws-sdk/credential-provider-node"); async function getClient() { From e50e8fc4f9a98d876f7d00bbe0a96975af501b79 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Mon, 29 Aug 2022 19:33:19 +0000 Subject: [PATCH 07/25] Adding 0BSD to allow license Signed-off-by: Harsha Vamsi Kalluri --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index df845a119..db0704923 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:coverage-ui": "tap test/{unit,acceptance}/{*,**/*}.test.js --coverage --coverage-report=html --nyc-arg=\"--exclude=api\"", "lint": "eslint .", "lint:fix": "eslint . --fix", - "license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause'", + "license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause;0BSD'", "build-esm": "npx gen-esm-wrapper . index.mjs && eslint --fix index.mjs" }, "author": "opensearch-project", From f58e21e5b75ba2d2e4d09875398a0fabb88e33f8 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Mon, 29 Aug 2022 20:06:24 +0000 Subject: [PATCH 08/25] Split code snippets into USER GUIDE Signed-off-by: Harsha Vamsi Kalluri --- README.md | 197 +------------------------------------------------- USER_GUIDE.md | 150 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 194 deletions(-) create mode 100644 USER_GUIDE.md diff --git a/README.md b/README.md index 466b94ca9..a5432f33e 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,7 @@ OpenSearch Node.js client - [Welcome!](#welcome) - [Example use](#example-use) - [Setup](#setup) - - [Sample code](#sample-code) - - [With AWS SigV4 signing](#with-aws-sigv4-signing) +- [Sample code](#sample-code) - [Project Resources](#project-resources) - [Code of Conduct](#code-of-conduct) - [License](#license) @@ -45,200 +44,10 @@ Then require the client: const { Client } = require('@opensearch-project/opensearch'); ``` -### Sample code +## Sample code -```javascript -'use strict'; - -var host = 'localhost'; -var protocol = 'https'; -var port = 9200; -var auth = 'admin:admin'; // For testing only. Don't store credentials in code. -var ca_certs_path = '/full/path/to/root-ca.pem'; - -// Optional client certificates if you don't want to use HTTP basic authentication. -// var client_cert_path = '/full/path/to/client.pem' -// var client_key_path = '/full/path/to/client-key.pem' - -// Create a client with SSL/TLS enabled. -var { Client } = require('@opensearch-project/opensearch'); -var fs = require('fs'); -var client = new Client({ - node: protocol + '://' + auth + '@' + host + ':' + port, - ssl: { - ca: fs.readFileSync(ca_certs_path), - // You can turn off certificate verification (rejectUnauthorized: false) if you're using self-signed certificates with a hostname mismatch. - // cert: fs.readFileSync(client_cert_path), - // key: fs.readFileSync(client_key_path) - }, -}); - -async function search() { - // Create an index with non-default settings. - var index_name = 'books'; - var settings = { - settings: { - index: { - number_of_shards: 4, - number_of_replicas: 3, - }, - }, - }; - - var response = await client.indices.create({ - index: index_name, - body: settings, - }); - - console.log('Creating index:'); - console.log(response.body); - - // Add a document to the index. - var document = { - title: 'The Outsider', - author: 'Stephen King', - year: '2018', - genre: 'Crime fiction', - }; - - var id = '1'; - - var response = await client.index({ - id: id, - index: index_name, - body: document, - refresh: true, - }); - - console.log('Adding document:'); - console.log(response.body); - - // Search for the document. - var query = { - query: { - match: { - title: { - query: 'The Outsider', - }, - }, - }, - }; - - var response = await client.search({ - index: index_name, - body: query, - }); - - console.log('Search results:'); - console.log(response.body.hits); - - // Delete the document. - var response = await client.delete({ - index: index_name, - id: id, - }); - - console.log('Deleting document:'); - console.log(response.body); - - // Delete the index. - var response = await client.indices.delete({ - index: index_name, - }); - - console.log('Deleting index:'); - console.log(response.body); -} - -search().catch(console.log); -``` - -### With AWS SigV4 signing -```javascript -const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com -const { Client } = require('@opensearch-project/opensearch'); -const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); -const { defaultProvider } = require("@aws-sdk/credential-provider-node"); - -async function getClient() { - const credentials = await defaultProvider()(); - var client = new Client({ - ...AwsV4Signer({ - credentials: credentials, - region: "us-west-2", - }), - node: endpoint, - }); - return client; -} - -async function search() { - - var client = await getClient(); - - var index_name = "books-test-1"; - var settings = { - settings: { - index: { - number_of_shards: 4, - number_of_replicas: 3, - }, - }, - }; - - var response = await client.indices.create({ - index: index_name, - body: settings, - }); - - console.log("Creating index:"); - console.log(response.body); +Please see the [USER_GUIDE](USER_GUIDE.md) for code snippets. - // Add a document to the index. - var document = { - title: "The Outsider", - author: "Stephen King", - year: "2018", - genre: "Crime fiction", - }; - - var id = "1"; - - var response = await client.index({ - id: id, - index: index_name, - body: document, - refresh: true, - }); - - console.log("Adding document:"); - console.log(response.body); - - var response = await client.bulk({ body: bulk_documents }); - console.log(response.body); - - // Search for the document. - var query = { - query: { - match: { - title: { - query: "The Outsider", - }, - }, - }, - }; - - var response = await client.search({ - index: index_name, - body: query, - }); - - console.log("Search results:"); - console.log(response.body.hits); -} - -search().catch(console.log); -``` ## Project Resources diff --git a/USER_GUIDE.md b/USER_GUIDE.md new file mode 100644 index 000000000..d5e64fd39 --- /dev/null +++ b/USER_GUIDE.md @@ -0,0 +1,150 @@ +# User Guide + +- [Initializing a Client](#initializing-a-client) +- [Initializing a Client with AWS SigV4 Signing](#initializing-a-client-with-aws-sigv4-signing) +- [Creating an Index](#creating-an-index) +- [Add a Document to the Index](#add-a-document-to-the-index) +- [Search for the Document](#search-for-the-document) +- [Delete the document](#delete-the-document) +- [Delete the index](#delete-the-index) + + +## Initializing a Client +```javascript +'use strict'; + +var host = 'localhost'; +var protocol = 'https'; +var port = 9200; +var auth = 'admin:admin'; // For testing only. Don't store credentials in code. +var ca_certs_path = '/full/path/to/root-ca.pem'; + +// Optional client certificates if you don't want to use HTTP basic authentication. +// var client_cert_path = '/full/path/to/client.pem' +// var client_key_path = '/full/path/to/client-key.pem' + +// Create a client with SSL/TLS enabled. +var { Client } = require('@opensearch-project/opensearch'); +var fs = require('fs'); +var client = new Client({ + node: protocol + '://' + auth + '@' + host + ':' + port, + ssl: { + ca: fs.readFileSync(ca_certs_path), + // You can turn off certificate verification (rejectUnauthorized: false) if you're using self-signed certificates with a hostname mismatch. + // cert: fs.readFileSync(client_cert_path), + // key: fs.readFileSync(client_key_path) + }, +}); +``` + +## Initializing a Client with AWS SigV4 Signing + +```javascript +const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com +const { Client } = require('@opensearch-project/opensearch'); +const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); +const { defaultProvider } = require("@aws-sdk/credential-provider-node"); + +async function getClient() { + const credentials = await defaultProvider()(); + var client = new Client({ + ...AwsV4Signer({ + credentials: credentials, + region: "us-west-2", + }), + node: endpoint, + }); + return client; +} +``` + +## Creating an Index + +```javascript + var index_name = 'books'; + var settings = { + settings: { + index: { + number_of_shards: 4, + number_of_replicas: 3, + }, + }, + }; + + var response = await client.indices.create({ + index: index_name, + body: settings, + }); + + console.log('Creating index:'); + console.log(response.body); +``` + +## Add a Document to the Index + +```javascript + var document = { + title: 'The Outsider', + author: 'Stephen King', + year: '2018', + genre: 'Crime fiction', + }; + + var id = '1'; + + var response = await client.index({ + id: id, + index: index_name, + body: document, + refresh: true, + }); + + console.log('Adding document:'); + console.log(response.body); +``` + +## Search for the Document + +```javascript + var query = { + query: { + match: { + title: { + query: 'The Outsider', + }, + }, + }, + }; + + var response = await client.search({ + index: index_name, + body: query, + }); + + console.log('Search results:'); + console.log(response.body.hits); +``` + +## Delete the document + +```javascript + var response = await client.delete({ + index: index_name, + id: id, + }); + + console.log('Deleting document:'); + console.log(response.body); +``` + +## Delete the index + +```javascript + var response = await client.indices.delete({ + index: index_name, + }); + + console.log('Deleting index:'); + console.log(response.body); +} +``` \ No newline at end of file From f1e5a16dbc7232bd7ea6ae7e99223f151aa53504 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Mon, 29 Aug 2022 20:15:54 +0000 Subject: [PATCH 09/25] Remove un-used package and update license Signed-off-by: Harsha Vamsi Kalluri --- package.json | 3 +- yarn.lock | 545 --------------------------------------------------- 2 files changed, 1 insertion(+), 547 deletions(-) diff --git a/package.json b/package.json index db0704923..567f7aad9 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:coverage-ui": "tap test/{unit,acceptance}/{*,**/*}.test.js --coverage --coverage-report=html --nyc-arg=\"--exclude=api\"", "lint": "eslint .", "lint:fix": "eslint . --fix", - "license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause;0BSD'", + "license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause'", "build-esm": "npx gen-esm-wrapper . index.mjs && eslint --fix index.mjs" }, "author": "opensearch-project", @@ -88,7 +88,6 @@ "xmlbuilder2": "^2.4.1" }, "dependencies": { - "@aws-sdk/credential-provider-node": "^3.154.0", "aws4": "^1.11.0", "debug": "^4.3.1", "hpagent": "^0.1.1", diff --git a/yarn.lock b/yarn.lock index 2d457c441..6cb7255c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,531 +2,6 @@ # yarn lockfile v1 -"@aws-crypto/ie11-detection@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@aws-crypto/ie11-detection/-/ie11-detection-2.0.0.tgz#bb6c2facf8f03457e949dcf0921477397ffa4c6e" - integrity sha512-pkVXf/dq6PITJ0jzYZ69VhL8VFOFoPZLZqtU/12SGnzYuJOOGNfF41q9GxdI1yqC8R13Rq3jOLKDFpUJFT5eTA== - dependencies: - tslib "^1.11.1" - -"@aws-crypto/sha256-browser@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-browser/-/sha256-browser-2.0.0.tgz#741c9024df55ec59b51e5b1f5d806a4852699fb5" - integrity sha512-rYXOQ8BFOaqMEHJrLHul/25ckWH6GTJtdLSajhlqGMx0PmSueAuvboCuZCTqEKlxR8CQOwRarxYMZZSYlhRA1A== - dependencies: - "@aws-crypto/ie11-detection" "^2.0.0" - "@aws-crypto/sha256-js" "^2.0.0" - "@aws-crypto/supports-web-crypto" "^2.0.0" - "@aws-crypto/util" "^2.0.0" - "@aws-sdk/types" "^3.1.0" - "@aws-sdk/util-locate-window" "^3.0.0" - "@aws-sdk/util-utf8-browser" "^3.0.0" - tslib "^1.11.1" - -"@aws-crypto/sha256-js@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-js/-/sha256-js-2.0.0.tgz#f1f936039bdebd0b9e2dd834d65afdc2aac4efcb" - integrity sha512-VZY+mCY4Nmrs5WGfitmNqXzaE873fcIZDu54cbaDaaamsaTOP1DBImV9F4pICc3EHjQXujyE8jig+PFCaew9ig== - dependencies: - "@aws-crypto/util" "^2.0.0" - "@aws-sdk/types" "^3.1.0" - tslib "^1.11.1" - -"@aws-crypto/sha256-js@^2.0.0": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-js/-/sha256-js-2.0.1.tgz#79e1e6cf61f652ef2089c08d471c722ecf1626a9" - integrity sha512-mbHTBSPBvg6o/mN/c18Z/zifM05eJrapj5ggoOIeHIWckvkv5VgGi7r/wYpt+QAO2ySKXLNvH2d8L7bne4xrMQ== - dependencies: - "@aws-crypto/util" "^2.0.1" - "@aws-sdk/types" "^3.1.0" - tslib "^1.11.1" - -"@aws-crypto/supports-web-crypto@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@aws-crypto/supports-web-crypto/-/supports-web-crypto-2.0.0.tgz#fd6cde30b88f77d5a4f57b2c37c560d918014f9e" - integrity sha512-Ge7WQ3E0OC7FHYprsZV3h0QIcpdyJLvIeg+uTuHqRYm8D6qCFJoiC+edSzSyFiHtZf+NOQDJ1q46qxjtzIY2nA== - dependencies: - tslib "^1.11.1" - -"@aws-crypto/util@^2.0.0", "@aws-crypto/util@^2.0.1": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@aws-crypto/util/-/util-2.0.1.tgz#976cf619cf85084ca85ec5eb947a6ac6b8b5c98c" - integrity sha512-JJmFFwvbm08lULw4Nm5QOLg8+lAQeC8aCXK5xrtxntYzYXCGfHwUJ4Is3770Q7HmICsXthGQ+ZsDL7C2uH3yBQ== - dependencies: - "@aws-sdk/types" "^3.1.0" - "@aws-sdk/util-utf8-browser" "^3.0.0" - tslib "^1.11.1" - -"@aws-sdk/abort-controller@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/abort-controller/-/abort-controller-3.127.0.tgz#60c98bffdb185d8eb5d3e43f30f57a32cc8687d6" - integrity sha512-G77FLYcl9egUoD3ZmR6TX94NMqBMeT53hBGrEE3uVUJV1CwfGKfaF007mPpRZnIB3avnJBQGEK6MrwlCfv2qAw== - dependencies: - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/client-sso@3.154.0": - version "3.154.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/client-sso/-/client-sso-3.154.0.tgz#8cb2e147137b72d16ab676533a62fb2711eb10ed" - integrity sha512-v5pJOkCxtxcSX1Cflskz9w+7kbP3PDsE6ce3zvmdCghCRAdM0SoJMffGlg/08VXwqW+GMJTZu+i+ojXMXhZTJw== - dependencies: - "@aws-crypto/sha256-browser" "2.0.0" - "@aws-crypto/sha256-js" "2.0.0" - "@aws-sdk/config-resolver" "3.130.0" - "@aws-sdk/fetch-http-handler" "3.131.0" - "@aws-sdk/hash-node" "3.127.0" - "@aws-sdk/invalid-dependency" "3.127.0" - "@aws-sdk/middleware-content-length" "3.127.0" - "@aws-sdk/middleware-host-header" "3.127.0" - "@aws-sdk/middleware-logger" "3.127.0" - "@aws-sdk/middleware-recursion-detection" "3.127.0" - "@aws-sdk/middleware-retry" "3.127.0" - "@aws-sdk/middleware-serde" "3.127.0" - "@aws-sdk/middleware-stack" "3.127.0" - "@aws-sdk/middleware-user-agent" "3.127.0" - "@aws-sdk/node-config-provider" "3.127.0" - "@aws-sdk/node-http-handler" "3.127.0" - "@aws-sdk/protocol-http" "3.127.0" - "@aws-sdk/smithy-client" "3.142.0" - "@aws-sdk/types" "3.127.0" - "@aws-sdk/url-parser" "3.127.0" - "@aws-sdk/util-base64-browser" "3.109.0" - "@aws-sdk/util-base64-node" "3.55.0" - "@aws-sdk/util-body-length-browser" "3.154.0" - "@aws-sdk/util-body-length-node" "3.55.0" - "@aws-sdk/util-defaults-mode-browser" "3.142.0" - "@aws-sdk/util-defaults-mode-node" "3.142.0" - "@aws-sdk/util-user-agent-browser" "3.127.0" - "@aws-sdk/util-user-agent-node" "3.127.0" - "@aws-sdk/util-utf8-browser" "3.109.0" - "@aws-sdk/util-utf8-node" "3.109.0" - tslib "^2.3.1" - -"@aws-sdk/config-resolver@3.130.0": - version "3.130.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/config-resolver/-/config-resolver-3.130.0.tgz#ba0fa915fa5613e87051a9826531e59cab4387b1" - integrity sha512-7dkCHHI9kRcHW6YNr9/2Ub6XkvU9Fu6H/BnlKbaKlDR8jq7QpaFhPhctOVi5D/NDpxJgALifexFne0dvo3piTw== - dependencies: - "@aws-sdk/signature-v4" "3.130.0" - "@aws-sdk/types" "3.127.0" - "@aws-sdk/util-config-provider" "3.109.0" - "@aws-sdk/util-middleware" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/credential-provider-env@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-env/-/credential-provider-env-3.127.0.tgz#06eb67461f7df8feb14abd3b459f682544d78e43" - integrity sha512-Ig7XhUikRBlnRTYT5JBGzWfYZp68X5vkFVIFCmsHHt/qVy0Nz9raZpmDHicdS1u67yxDkWgCPn/bNevWnM0GFg== - dependencies: - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/credential-provider-imds@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-imds/-/credential-provider-imds-3.127.0.tgz#1fc7b40bf21adcc2a897e47b72796bd8ebcc7d86" - integrity sha512-I6KlIBBzmJn/U1KikiC50PK3SspT9G5lkVLBaW5a6YfOcijqVTXfAN3kYzqhfeS0j4IgfJEwKVsjsZfmprJO5A== - dependencies: - "@aws-sdk/node-config-provider" "3.127.0" - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/types" "3.127.0" - "@aws-sdk/url-parser" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/credential-provider-ini@3.154.0": - version "3.154.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.154.0.tgz#825d7fd981b146380339f3ac4dcd81eb334bbe71" - integrity sha512-5p8vueRuAMo3cMBAHQCgAu6Kr+K6R64Bm1yccQu72HEy8zoyQsCKMV0tQS7dYbObfOGpIXZbHyESyTon0khI0g== - dependencies: - "@aws-sdk/credential-provider-env" "3.127.0" - "@aws-sdk/credential-provider-imds" "3.127.0" - "@aws-sdk/credential-provider-sso" "3.154.0" - "@aws-sdk/credential-provider-web-identity" "3.127.0" - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/shared-ini-file-loader" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/credential-provider-node@^3.154.0": - version "3.154.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-node/-/credential-provider-node-3.154.0.tgz#c37572dbb6731c288708d60ae62cbdb32def771e" - integrity sha512-pNxKtf/ye2574+QT2aKykSzKo3RnwCtWB7Tduo/8YlmQZL+/vX53BLcGj+fLOE1h7RbY5psF02dzbanvb4CVGg== - dependencies: - "@aws-sdk/credential-provider-env" "3.127.0" - "@aws-sdk/credential-provider-imds" "3.127.0" - "@aws-sdk/credential-provider-ini" "3.154.0" - "@aws-sdk/credential-provider-process" "3.127.0" - "@aws-sdk/credential-provider-sso" "3.154.0" - "@aws-sdk/credential-provider-web-identity" "3.127.0" - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/shared-ini-file-loader" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/credential-provider-process@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-process/-/credential-provider-process-3.127.0.tgz#6046a20013a3edd58b631668ed1d73dfd63a931c" - integrity sha512-6v0m2lqkO9J5fNlTl+HjriQNIdfg8mjVST544+5y9EnC/FVmTnIz64vfHveWdNkP/fehFx7wTimNENtoSqCn3A== - dependencies: - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/shared-ini-file-loader" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/credential-provider-sso@3.154.0": - version "3.154.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.154.0.tgz#e752a6406317fbb4609a19a0b420cfe527d8a682" - integrity sha512-w3EZo1IKLyE7rhurq56e8IZuMxr0bc3Qvkq+AJnDwTR4sm5TPp9RNJwo+/A0i7GOdhNufcTlaciZT9Izi3g4+A== - dependencies: - "@aws-sdk/client-sso" "3.154.0" - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/shared-ini-file-loader" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/credential-provider-web-identity@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.127.0.tgz#a56c390bf0148f20573abd022930b28df345043a" - integrity sha512-85ahDZnLYB3dqkW+cQ0bWt+NVqOoxomTrJoq3IC2q6muebeFrJ0pyf0JEW/RNRzBiUvvsZujzGdWifzWyQKfVg== - dependencies: - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/fetch-http-handler@3.131.0": - version "3.131.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/fetch-http-handler/-/fetch-http-handler-3.131.0.tgz#426721ba3c4e7687a6c12ce10bdc661900325815" - integrity sha512-eNxmPZQX2IUeBGWHNC7eNTekWn9VIPLYEMKJbKYUBJryxuTJ7TtLeyEK5oakUjMwP1AUvWT+CV7C+8L7uG1omQ== - dependencies: - "@aws-sdk/protocol-http" "3.127.0" - "@aws-sdk/querystring-builder" "3.127.0" - "@aws-sdk/types" "3.127.0" - "@aws-sdk/util-base64-browser" "3.109.0" - tslib "^2.3.1" - -"@aws-sdk/hash-node@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/hash-node/-/hash-node-3.127.0.tgz#2fbbeb509a515e6a5cfd6846c02cc1967961a40b" - integrity sha512-wx7DKlXdKebH4JcMsOevdsm2oDNMVm36kuMm0XWRIrFWQ/oq7OquDpEMJzWvGqWF/IfFUpb7FhAWZZpALwlcwA== - dependencies: - "@aws-sdk/types" "3.127.0" - "@aws-sdk/util-buffer-from" "3.55.0" - tslib "^2.3.1" - -"@aws-sdk/invalid-dependency@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/invalid-dependency/-/invalid-dependency-3.127.0.tgz#3a99603e1969f67278495b827243e9a391b8cfc4" - integrity sha512-bxvmtmJ6gIRfOHvh1jAPZBH2mzppEblPjEOFo4mOzXz4U3qPIxeuukCjboMnGK9QEpV2wObWcYYld0vxoRrfiA== - dependencies: - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/is-array-buffer@3.55.0": - version "3.55.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/is-array-buffer/-/is-array-buffer-3.55.0.tgz#c46122c5636f01d5895e5256a587768c3425ea7a" - integrity sha512-NbiPHVYuPxdqdFd6FxzzN3H1BQn/iWA3ri3Ry7AyLeP/tGs1yzEWMwf8BN8TSMALI0GXT6Sh0GDWy3Ok5xB6DA== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/middleware-content-length@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-content-length/-/middleware-content-length-3.127.0.tgz#662c1971fdb2dd7d34a9945ebd8da52578900434" - integrity sha512-AFmMaIEW3Rzg0TaKB9l/RENLowd7ZEEOpm0trYw1CgUUORWW/ydCsDT7pekPlC25CPbhUmWXCSA4xPFSYOVnDw== - dependencies: - "@aws-sdk/protocol-http" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/middleware-host-header@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-host-header/-/middleware-host-header-3.127.0.tgz#679f685bd8b4f221ed2c11e90b381d6904034ef9" - integrity sha512-e2gTLJb5lYP9lRV7hN3rKY2l4jv8OygOoHElZJ3Z8KPZskjHelYPcQ8XbdfhSXXxC3vc/0QqN0ResFt3W3Pplg== - dependencies: - "@aws-sdk/protocol-http" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/middleware-logger@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-logger/-/middleware-logger-3.127.0.tgz#b62fd148888f418bd74b0c9d76b80588224ee98f" - integrity sha512-jMNLcZB/ECA7OfkNBLNeAlrLRehyfnUeNQJHW3kcxs9h1+6VxaF6wY+WKozszLI7/3OBzQrFHBQCfRZV7ykSLg== - dependencies: - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/middleware-recursion-detection@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.127.0.tgz#84949efd4a05a4d00da3e9242825e3c9d715f800" - integrity sha512-tB6WX+Z1kUKTnn5h38XFrTCzoqPKjUZLUjN4Wb27/cbeSiTSKGAZcCXHOJm36Ukorl5arlybQTqGe689EU00Hw== - dependencies: - "@aws-sdk/protocol-http" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/middleware-retry@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-retry/-/middleware-retry-3.127.0.tgz#bcd0741ed676588101739083c6bd141d5c1911e1" - integrity sha512-ZSvg/AyGUacWnf3i8ZbyImtiCH+NyafF8uV7bITP7JkwPrG+VdNocJZOr88GRM0c1A0jfkOf7+oq+fInPwwiNA== - dependencies: - "@aws-sdk/protocol-http" "3.127.0" - "@aws-sdk/service-error-classification" "3.127.0" - "@aws-sdk/types" "3.127.0" - "@aws-sdk/util-middleware" "3.127.0" - tslib "^2.3.1" - uuid "^8.3.2" - -"@aws-sdk/middleware-serde@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-serde/-/middleware-serde-3.127.0.tgz#8732d71ed0d28c43e609fcc156b1a1ac307c0d5f" - integrity sha512-xmWMYV/t9M+b9yHjqaD1noDNJJViI2QwOH7TQZ9VbbrvdVtDrFuS9Sf9He80TBCJqeHShwQN9783W1I3Pu/8kw== - dependencies: - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/middleware-stack@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-stack/-/middleware-stack-3.127.0.tgz#d569d964256cdd4a5afd149de325296cf19762f6" - integrity sha512-S1IoUE5o1vCmjsF5nIE8zlItNOM1UE+lhmZeigF7knXJ9+a6ewMB6POAj/s4eoi0wcn0eSnAGsqJCWMSUjOPLA== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/middleware-user-agent@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.127.0.tgz#f676aac4ddaba64bb12b6d69b0ed7328479cf798" - integrity sha512-CHxgswoOzdkOEoIq7Oyob3Sx/4FYUv6BhUesAX7MNshaDDsTQPbSWjw5bqZDiL/gO+X/34fvqCVVpVD2GvxW/g== - dependencies: - "@aws-sdk/protocol-http" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/node-config-provider@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/node-config-provider/-/node-config-provider-3.127.0.tgz#43a460526f0c24a661264189712e0ff5475e9b45" - integrity sha512-bAHkASMhLZHT1yv2TX6OJGFV9Lc3t1gKfTMEKdXM2O2YhGfSx9A/qLeJm79oDfnILWQtSS2NicxlRDI2lYGf4g== - dependencies: - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/shared-ini-file-loader" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/node-http-handler@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/node-http-handler/-/node-http-handler-3.127.0.tgz#81c0a34061b233027bc673f3359c36555c0688d7" - integrity sha512-pyMKvheK8eDwWLgYIRsWy8wiyhsbYYcqkZQs3Eh6upI4E8iCY7eMmhWvHYCibvsO+UjsOwa4cAMOfwnv/Z9s8A== - dependencies: - "@aws-sdk/abort-controller" "3.127.0" - "@aws-sdk/protocol-http" "3.127.0" - "@aws-sdk/querystring-builder" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/property-provider@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/property-provider/-/property-provider-3.127.0.tgz#3b70d23354c35ea04c29c97f05cc4108c2e194ba" - integrity sha512-JxenxlTEkWfLrtJqIjaXaJzAVQbbscoCb5bNjmdud07ESLVfWRKJx2nAJdecHKYp2M5NQyqBuFhQ1ELSFYQKCA== - dependencies: - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/protocol-http@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/protocol-http/-/protocol-http-3.127.0.tgz#c1d7bb20f09f9e86fd885d3effb33850b618e549" - integrity sha512-UG83PVuKX40wilG2uRU0Fvz4OY8Bt+bSPOG776DFjwIXYzK7BwpJm9H2XI2HLhS5WxrJHhwrLBRgW6UiykMnFw== - dependencies: - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/querystring-builder@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/querystring-builder/-/querystring-builder-3.127.0.tgz#50a100d13bd13bb06ee92dcd9568e21a37fb9c49" - integrity sha512-tsoyp4lLPsASPDYWsezGAHD8VJsZbjUNATNAzTCFdH6p+4SKBK83Q5kfXCzxt13M+l3oKbxxIWLvS0kVQFyltQ== - dependencies: - "@aws-sdk/types" "3.127.0" - "@aws-sdk/util-uri-escape" "3.55.0" - tslib "^2.3.1" - -"@aws-sdk/querystring-parser@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/querystring-parser/-/querystring-parser-3.127.0.tgz#d485db0d24005e95bb4c9c478691cd805e5fc0f4" - integrity sha512-Vn/Dv+PqUSepp/DzLqq0LJJD8HdPefJCnLbO5WcHCARHSGlyGlZUFEM45k/oEHpTvgMXj/ORaP3A+tLwLu0AmA== - dependencies: - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/service-error-classification@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/service-error-classification/-/service-error-classification-3.127.0.tgz#64b69215b2525e3b6806856187ef54b00c0f85d1" - integrity sha512-wjZY9rnlA8SPrICUumTYicEKtK4/yKB62iadUk66hxe8MrH8JhuHH2NqIad0Pt/bK/YtNVhd3yb4pRapOeY5qQ== - -"@aws-sdk/shared-ini-file-loader@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/shared-ini-file-loader/-/shared-ini-file-loader-3.127.0.tgz#019c5512bf92f954f6aca6f6811e38fe048aadf6" - integrity sha512-S3Nn4KRTqoJsB/TbRZSWBBUrkckNMR0Juqz7bOB+wupVvddKP6IcpspSC/GX9zgJjVMV8iGisZ6AUsYsC5r+cA== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/signature-v4@3.130.0": - version "3.130.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/signature-v4/-/signature-v4-3.130.0.tgz#152085234311610a350fdcd9a7f877a83aa44cf1" - integrity sha512-g5G1a1NHL2uOoFfC2zQdZcj+wbjgBQPkx6xGdtqNKf9v2kS0n6ap5JUGEaqWE02lUlmWHsoMsS73hXtzwXaBRQ== - dependencies: - "@aws-sdk/is-array-buffer" "3.55.0" - "@aws-sdk/types" "3.127.0" - "@aws-sdk/util-hex-encoding" "3.109.0" - "@aws-sdk/util-middleware" "3.127.0" - "@aws-sdk/util-uri-escape" "3.55.0" - tslib "^2.3.1" - -"@aws-sdk/smithy-client@3.142.0": - version "3.142.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/smithy-client/-/smithy-client-3.142.0.tgz#d27abff1892de644ac25fc07305fbc0050d7d512" - integrity sha512-G38YWTfSFZb5cOH6IwLct530Uy8pnmJvJFeC1pd1nkKD4PRZb+bI2w4xXSX+znYdLA71RYK620OtVKJlB44PtA== - dependencies: - "@aws-sdk/middleware-stack" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/types@3.127.0", "@aws-sdk/types@^3.1.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/types/-/types-3.127.0.tgz#a7bafc47ee2328eee2453087521e6c3a39e7278d" - integrity sha512-e0wtx2IkOl7rwfKfLH5pPTzQ+d45V7b1WrjeL0WDI8kOu6w+sXmhNxI6uM2kf0k4NiTLN84lW290AEWupey9Og== - -"@aws-sdk/url-parser@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/url-parser/-/url-parser-3.127.0.tgz#7a5c6186e83dc6f823c989c0575aebe384e676b0" - integrity sha512-njZ7zn41JHRpNfr3BCesVXCLZE0zcWSfEdtRV0ICw0cU1FgYcKELSuY9+gLUB4ci6uc7gq7mPE8+w30FcM4QeA== - dependencies: - "@aws-sdk/querystring-parser" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/util-base64-browser@3.109.0": - version "3.109.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-base64-browser/-/util-base64-browser-3.109.0.tgz#e7faf5c4cbb88bc39b9c1c5a1a79e4c869e9f645" - integrity sha512-lAZ6fyDGiRLaIsKT9qh7P9FGuNyZ4gAbr1YOSQk/5mHtaTuUvxlPptZuInNM/0MPQm6lpcot00D8IWTucn4PbA== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-base64-node@3.55.0": - version "3.55.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-base64-node/-/util-base64-node-3.55.0.tgz#da9a3fd6752be49163572144793e6b23d0186ff4" - integrity sha512-UQ/ZuNoAc8CFMpSiRYmevaTsuRKzLwulZTnM8LNlIt9Wx1tpNvqp80cfvVj7yySKROtEi20wq29h31dZf1eYNQ== - dependencies: - "@aws-sdk/util-buffer-from" "3.55.0" - tslib "^2.3.1" - -"@aws-sdk/util-body-length-browser@3.154.0": - version "3.154.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-body-length-browser/-/util-body-length-browser-3.154.0.tgz#8c4c5d08c1923deeedf46006dc4db820ca606f56" - integrity sha512-TUuy7paVkBRQrB/XFCsL8iTW6g/ma0S3N8dYOiIMJdeTqTFryeyOGkBpYBgYFQL6zRMZpyu0jOM7GYEffGFOXw== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-body-length-node@3.55.0": - version "3.55.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-body-length-node/-/util-body-length-node-3.55.0.tgz#67049bbb6c62d794a1bb5a13b9a678988c925489" - integrity sha512-lU1d4I+9wJwydduXs0SxSfd+mHKjxeyd39VwOv6i2KSwWkPbji9UQqpflKLKw+r45jL7+xU/zfeTUg5Tt/3Gew== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-buffer-from@3.55.0": - version "3.55.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-buffer-from/-/util-buffer-from-3.55.0.tgz#e7c927974b07a29502aa1ad58509b91d0d7cf0f7" - integrity sha512-uVzKG1UgvnV7XX2FPTylBujYMKBPBaq/qFBxfl0LVNfrty7YjpfieQxAe6yRLD+T0Kir/WDQwGvYC+tOYG3IGA== - dependencies: - "@aws-sdk/is-array-buffer" "3.55.0" - tslib "^2.3.1" - -"@aws-sdk/util-config-provider@3.109.0": - version "3.109.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-config-provider/-/util-config-provider-3.109.0.tgz#7828b8894b2b23c289ffc5c106cbced7a5d6ee86" - integrity sha512-GrAZl/aBv0A28LkyNyq8SPJ5fmViCwz80fWLMeWx/6q5AbivuILogjlWwEZSvZ9zrlHOcFC0+AnCa5pQrjaslw== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-defaults-mode-browser@3.142.0": - version "3.142.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-defaults-mode-browser/-/util-defaults-mode-browser-3.142.0.tgz#808e136ba0b371a68d9d3a4aff7671ee39b68d88" - integrity sha512-vVB/CrodMmIfv4v54MyBlKO0sQSI/+Mvs4g5gMyVjmT4a+1gnktJQ9R6ZHQ2/ErGewcra6eH9MU5T0r1kYe0+w== - dependencies: - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/types" "3.127.0" - bowser "^2.11.0" - tslib "^2.3.1" - -"@aws-sdk/util-defaults-mode-node@3.142.0": - version "3.142.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-defaults-mode-node/-/util-defaults-mode-node-3.142.0.tgz#d2a8cec87a5295b81ec4315ff0a31bad799a2ac0" - integrity sha512-13d5RZLO13EDwll3COUq3D4KVsqM63kdf+YjG5mzXR1eXo6GVjghfQfiy0MYM6YbAjTfJxZQkc0nFgWLU8jdyg== - dependencies: - "@aws-sdk/config-resolver" "3.130.0" - "@aws-sdk/credential-provider-imds" "3.127.0" - "@aws-sdk/node-config-provider" "3.127.0" - "@aws-sdk/property-provider" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/util-hex-encoding@3.109.0": - version "3.109.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-hex-encoding/-/util-hex-encoding-3.109.0.tgz#93b20acc27c0a1d7d80f653bf19d3dd01c2ccc65" - integrity sha512-s8CgTNrn3cLkrdiohfxLuOYPCanzvHn/aH5RW6DaMoeQiG5Hl9QUiP/WtdQ9QQx3xvpQFpmvxIaSBwSgFNLQxA== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-locate-window@^3.0.0": - version "3.55.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-locate-window/-/util-locate-window-3.55.0.tgz#a4136a20ee1bfcb73967a6614caf769ef79db070" - integrity sha512-0sPmK2JaJE2BbTcnvybzob/VrFKCXKfN4CUKcvn0yGg/me7Bz+vtzQRB3Xp+YSx+7OtWxzv63wsvHoAnXvgxgg== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-middleware@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-middleware/-/util-middleware-3.127.0.tgz#266d6160886f272cb3e3c3eb5266abbac0c033bc" - integrity sha512-EwAPPed9TNqh+Wov2VStLn2NuJ/Wyt7IkZCbCsBuSNp3BFZ1V4gfwTjqtKCtB2LQgQ48MTgWgNCvrH0zjCSPGg== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-uri-escape@3.55.0": - version "3.55.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-uri-escape/-/util-uri-escape-3.55.0.tgz#ee57743c628a1c9f942dfe73205ce890ec011916" - integrity sha512-mmdDLUpFCN2nkfwlLdOM54lTD528GiGSPN1qb8XtGLgZsJUmg3uJSFIN2lPeSbEwJB3NFjVas/rnQC48i7mV8w== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-user-agent-browser@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.127.0.tgz#dc6c4c9049ebf238c321883593b2cd3d82b5e755" - integrity sha512-uO2oHmJswuYKJS+GiMdYI8izhpC9M7/jFFvnAmLlTEVwpEi1VX9KePAOF+u5AaBC2kzITo/7dg141XfRHZloIQ== - dependencies: - "@aws-sdk/types" "3.127.0" - bowser "^2.11.0" - tslib "^2.3.1" - -"@aws-sdk/util-user-agent-node@3.127.0": - version "3.127.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.127.0.tgz#368dc0c0e1160e8ca9e5ca21f3857004509aa06e" - integrity sha512-3P/M4ZDD2qMeeoCk7TE/Mw7cG5IjB87F6BP8nI8/oHuaz7j6fsI7D49SNpyjl8JApRynZ122Ad6hwQwRj3isYw== - dependencies: - "@aws-sdk/node-config-provider" "3.127.0" - "@aws-sdk/types" "3.127.0" - tslib "^2.3.1" - -"@aws-sdk/util-utf8-browser@3.109.0", "@aws-sdk/util-utf8-browser@^3.0.0": - version "3.109.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-utf8-browser/-/util-utf8-browser-3.109.0.tgz#d013272e1981b23a4c84ac06f154db686c0cf84e" - integrity sha512-FmcGSz0v7Bqpl1SE8G1Gc0CtDpug+rvqNCG/szn86JApD/f5x8oByjbEiAyTU2ZH2VevUntx6EW68ulHyH+x+w== - dependencies: - tslib "^2.3.1" - -"@aws-sdk/util-utf8-node@3.109.0": - version "3.109.0" - resolved "https://registry.yarnpkg.com/@aws-sdk/util-utf8-node/-/util-utf8-node-3.109.0.tgz#89e06d916f5b246c7265f59bac742973ac0767ac" - integrity sha512-Ti/ZBdvz2eSTElsucjzNmzpyg2MwfD1rXmxD0hZuIF8bPON/0+sZYnWd5CbDw9kgmhy28dmKue086tbZ1G0iLQ== - dependencies: - "@aws-sdk/util-buffer-from" "3.55.0" - tslib "^2.3.1" - "@babel/code-frame@7.12.11": version "7.12.11" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" @@ -1333,11 +808,6 @@ bl@^4.1.0: inherits "^2.0.4" readable-stream "^3.4.0" -bowser@^2.11.0: - version "2.11.0" - resolved "https://registry.yarnpkg.com/bowser/-/bowser-2.11.0.tgz#5ca3c35757a7aa5771500c70a73a9f91ef420a8f" - integrity sha512-AlcaJBi/pqqJBIQ8U9Mcpc9i8Aqxn88Skv5d+xBX006BY5u8N3mGLHa5Lgppa7L/HfwgwLgZ6NYs+Ag6uUmJRA== - brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -3733,16 +3203,6 @@ tsd@^0.22.0: path-exists "^4.0.0" read-pkg-up "^7.0.0" -tslib@^1.11.1: - version "1.14.1" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" - integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== - -tslib@^2.3.1: - version "2.4.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3" - integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ== - type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" @@ -3822,11 +3282,6 @@ uuid@^3.3.3: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.3.2: - version "8.3.2" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" - integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== - v8-compile-cache@^2.0.3: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee" From 6d7b79cc0df384f1c9e376885b18310f02b43409 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Mon, 29 Aug 2022 21:17:48 +0000 Subject: [PATCH 10/25] Fix language in user guide Signed-off-by: Harsha Vamsi Kalluri --- USER_GUIDE.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index d5e64fd39..66448e7a7 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -1,8 +1,8 @@ # User Guide - [Initializing a Client](#initializing-a-client) -- [Initializing a Client with AWS SigV4 Signing](#initializing-a-client-with-aws-sigv4-signing) -- [Creating an Index](#creating-an-index) + - [To authenticate with the Amazon OpenSearch Service use AwsSigv4Signer](#to-authenticate-with-the-amazon-opensearch-service-use-awssigv4signer) +- [Create an Index](#create-an-index) - [Add a Document to the Index](#add-a-document-to-the-index) - [Search for the Document](#search-for-the-document) - [Delete the document](#delete-the-document) @@ -37,7 +37,7 @@ var client = new Client({ }); ``` -## Initializing a Client with AWS SigV4 Signing +### To authenticate with the [Amazon OpenSearch Service](https://aws.amazon.com/opensearch-service/) use AwsSigv4Signer ```javascript const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com @@ -58,7 +58,7 @@ async function getClient() { } ``` -## Creating an Index +## Create an Index ```javascript var index_name = 'books'; From 8505f851922a33701d5902173cd0eb02be8a34b3 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Mon, 29 Aug 2022 21:37:39 +0000 Subject: [PATCH 11/25] Add types to dev dependencies Signed-off-by: Harsha Vamsi Kalluri --- package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/package.json b/package.json index 567f7aad9..b113fd1df 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "company": "Elasticsearch BV" }, "devDependencies": { + "@aws-sdk/types": "^3.160.0", "@sinonjs/fake-timers": "github:sinonjs/fake-timers#0bfffc1", "@types/node": "^15.3.1", "babel-eslint": "^10.1.0", diff --git a/yarn.lock b/yarn.lock index ac176ceb8..ec440d5ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@aws-sdk/types@^3.160.0": + version "3.160.0" + resolved "https://registry.yarnpkg.com/@aws-sdk/types/-/types-3.160.0.tgz#94894019ccc7d4fb44c36814051473a2b3988d55" + integrity sha512-sDpDVw/B80USIERcig55dxvPTv+FbYXjUipRIv3wcQ6ePEHIRfqyvdGaTHZGoWYpOW8GFNEbVc2BGFF2ff4ZdA== + "@babel/code-frame@7.12.11": version "7.12.11" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" From 562d6834bbc3cb13a22dc1bed6862602518871ad Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Mon, 29 Aug 2022 18:44:11 -0700 Subject: [PATCH 12/25] Update USER_GUIDE.md Co-authored-by: Graeme Signed-off-by: Harsha Vamsi Kalluri --- USER_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 66448e7a7..18020bdc5 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -48,7 +48,7 @@ const { defaultProvider } = require("@aws-sdk/credential-provider-node"); async function getClient() { const credentials = await defaultProvider()(); var client = new Client({ - ...AwsV4Signer({ + ...AwsSigv4Signer({ credentials: credentials, region: "us-west-2", }), From 341df4fafec8c605a87d2ed85738f66fd3527f52 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Thu, 1 Sep 2022 05:44:51 +0700 Subject: [PATCH 13/25] add credentials refresh options Signed-off-by: rawpixel-vincent --- USER_GUIDE.md | 40 +++++++++++++++-------------- lib/aws/AwsSigv4Signer.js | 39 +++++++++++++++++++++++++--- lib/aws/index.d.ts | 6 +++-- test/types/awssigv4signer.test-d.ts | 11 +++++--- test/unit/awssigv4signer.test.js | 30 +++++++++++++++------- 5 files changed, 89 insertions(+), 37 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 18020bdc5..5b5a09606 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -1,13 +1,13 @@ # User Guide -- [Initializing a Client](#initializing-a-client) - - [To authenticate with the Amazon OpenSearch Service use AwsSigv4Signer](#to-authenticate-with-the-amazon-opensearch-service-use-awssigv4signer) -- [Create an Index](#create-an-index) -- [Add a Document to the Index](#add-a-document-to-the-index) -- [Search for the Document](#search-for-the-document) -- [Delete the document](#delete-the-document) -- [Delete the index](#delete-the-index) - +- [User Guide](#user-guide) + - [Initializing a Client](#initializing-a-client) + - [To authenticate with Amazon OpenSearch Service using AwsSigv4Signer](#to-authenticate-with-amazon-opensearch-service-using-awssigv4signer) + - [Create an Index](#create-an-index) + - [Add a Document to the Index](#add-a-document-to-the-index) + - [Search for the Document](#search-for-the-document) + - [Delete the document](#delete-the-document) + - [Delete the index](#delete-the-index) ## Initializing a Client ```javascript @@ -37,24 +37,26 @@ var client = new Client({ }); ``` -### To authenticate with the [Amazon OpenSearch Service](https://aws.amazon.com/opensearch-service/) use AwsSigv4Signer +### To authenticate with [Amazon OpenSearch Service](https://aws.amazon.com/opensearch-service/) using AwsSigv4Signer ```javascript -const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com +const { defaultProvider } = require("@aws-sdk/credential-provider-node"); const { Client } = require('@opensearch-project/opensearch'); const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); -const { defaultProvider } = require("@aws-sdk/credential-provider-node"); async function getClient() { - const credentials = await defaultProvider()(); - var client = new Client({ - ...AwsSigv4Signer({ - credentials: credentials, - region: "us-west-2", - }), + const connection = await AwsSigv4Signer({ + getCredentials: async () => { + const credentials = await defaultProvider()(); + return credentials; + }, + refresh: false, // Enable refreshing credentials. + refreshInterval: 1000 * 1000 * 60 * 14, // default to 14 minutes, must be set to a value below the expiration time of the credentials. + }); + return new Client({ + ...connection, node: endpoint, }); - return client; } ``` @@ -80,7 +82,7 @@ async function getClient() { console.log(response.body); ``` -## Add a Document to the Index +## Add a Document to the Index ```javascript var document = { diff --git a/lib/aws/AwsSigv4Signer.js b/lib/aws/AwsSigv4Signer.js index 3c6f4d519..e35ddd82e 100644 --- a/lib/aws/AwsSigv4Signer.js +++ b/lib/aws/AwsSigv4Signer.js @@ -14,12 +14,42 @@ const Connection = require('../Connection'); const aws4 = require('aws4'); const AwsSigv4SignerError = require('./errors'); -function AwsSigv4Signer(opts) { +const DEFAULT_REFRESH_INTERVAL = 1000 * 60 * 14; // 14 minutes. + +/** + * @returns {Promise} + */ +async function AwsSigv4Signer(opts) { + const credentialsState = { + credentials: null, + refreshInterval: null, + }; if (opts && (!opts.region || opts.region === null || opts.region === '')) { throw new AwsSigv4SignerError('Region cannot be empty'); } - if (opts && (!opts.credentials || opts.credentials === null || opts.credentials === '')) { - throw new AwsSigv4SignerError('Credentials cannot be empty'); + if (opts && typeof opts.getCredentials !== 'function') { + throw new AwsSigv4SignerError('getCredentials function is required'); + } + + try { + credentialsState.credentials = await opts.getCredentials(); + } catch (error) { + throw new AwsSigv4SignerError('fetching credentials failed', error); + } + + if (opts && opts.refresh === true && !credentialsState.refreshInterval) { + credentialsState.refreshInterval = setInterval( + async () => { + try { + credentialsState.credentials = await opts.getCredentials(); + } catch (error) { + throw new AwsSigv4SignerError('fetching credentials failed', error); + } + }, + typeof opts.refreshInterval === 'number' + ? Math.max(opts.refreshInterval, DEFAULT_REFRESH_INTERVAL) + : DEFAULT_REFRESH_INTERVAL + ); } function buildSignedRequestObject(request = {}) { @@ -27,7 +57,7 @@ function AwsSigv4Signer(opts) { request.region = opts.region; request.headers = request.headers || {}; request.headers['host'] = request.hostname; - return aws4.sign(request, opts.credentials); + return aws4.sign(request, credentialsState.credentials); } class AwsSigv4SignerConnection extends Connection { buildRequestObject(params) { @@ -35,6 +65,7 @@ function AwsSigv4Signer(opts) { return buildSignedRequestObject(request); } } + return { Connection: AwsSigv4SignerConnection, buildSignedRequestObject, diff --git a/lib/aws/index.d.ts b/lib/aws/index.d.ts index 9f97913ed..fabf40c98 100644 --- a/lib/aws/index.d.ts +++ b/lib/aws/index.d.ts @@ -17,8 +17,10 @@ import * as http from 'http'; import { OpenSearchClientError } from '../errors'; interface AwsSigv4SignerOptions { - credentials: Credentials; + getCredentials: () => Promise; region: string; + refresh?: boolean; + refreshInterval?: number; } interface AwsSigv4SignerResponse { @@ -26,7 +28,7 @@ interface AwsSigv4SignerResponse { buildSignedRequestObject(request: any): http.ClientRequestArgs; } -declare function AwsSigv4Signer(opts: AwsSigv4SignerOptions): AwsSigv4SignerResponse; +declare function AwsSigv4Signer(opts: AwsSigv4SignerOptions): Promise; declare class AwsSigv4SignerError extends OpenSearchClientError { name: string; diff --git a/test/types/awssigv4signer.test-d.ts b/test/types/awssigv4signer.test-d.ts index ca9e2f4a2..291e71900 100644 --- a/test/types/awssigv4signer.test-d.ts +++ b/test/types/awssigv4signer.test-d.ts @@ -9,11 +9,12 @@ * GitHub history for details. */ +import { Credentials } from '@aws-sdk/types'; import { expectType } from 'tsd'; const { v4: uuidv4 } = require('uuid'); import { AwsSigv4SignerResponse, AwsSigv4Signer } from '../../lib/aws'; -const mockCreds = { +const mockCreds: Credentials = { accessKeyId: uuidv4(), secretAccessKey: uuidv4(), }; @@ -21,9 +22,13 @@ const mockCreds = { const mockRegion = 'us-west-2'; { - const AwsSigv4SignerOptions = { credentials: mockCreds, region: mockRegion }; + const AwsSigv4SignerOptions = { + getCredentials: () => Promise.resolve(mockCreds), + region: mockRegion, + refresh: true, + }; const auth = AwsSigv4Signer(AwsSigv4SignerOptions); - expectType(auth); + expectType>(auth); } diff --git a/test/unit/awssigv4signer.test.js b/test/unit/awssigv4signer.test.js index c3a7e9e56..de51b45c2 100644 --- a/test/unit/awssigv4signer.test.js +++ b/test/unit/awssigv4signer.test.js @@ -15,7 +15,7 @@ const AwsSigv4Signer = require('../../lib/aws/AwsSigv4Signer'); const AwsSigv4SignerError = require('../../lib/aws/errors'); const { Connection } = require('../../index'); -test('Sign with SigV4', (t) => { +test('Sign with SigV4', async (t) => { t.plan(2); const mockCreds = { @@ -25,9 +25,15 @@ test('Sign with SigV4', (t) => { const mockRegion = 'us-west-2'; - const AwsSigv4SignerOptions = { credentials: mockCreds, region: mockRegion }; + const AwsSigv4SignerOptions = { + getCredentials: () => + new Promise((resolve) => { + setTimeout(() => resolve(mockCreds), 100); + }), + region: mockRegion, + }; - const auth = AwsSigv4Signer(AwsSigv4SignerOptions); + const auth = await AwsSigv4Signer(AwsSigv4SignerOptions); const connection = new Connection({ url: new URL('https://localhost:9200'), @@ -40,12 +46,13 @@ test('Sign with SigV4', (t) => { 'X-Custom-Test': true, }, }); + const signedRequest = auth.buildSignedRequestObject(request); t.hasProp(signedRequest.headers, 'X-Amz-Date'); t.hasProp(signedRequest.headers, 'Authorization'); }); -test('Sign with SigV4 failure (with empty region)', (t) => { +test('Sign with SigV4 failure (with empty region)', async (t) => { t.plan(2); const mockCreds = { @@ -53,10 +60,15 @@ test('Sign with SigV4 failure (with empty region)', (t) => { secretAccessKey: uuidv4(), }; - const AwsSigv4SignerOptions = { credentials: mockCreds }; + const AwsSigv4SignerOptions = { + getCredentials: () => + new Promise((resolve) => { + setTimeout(() => resolve(mockCreds), 100); + }), + }; try { - AwsSigv4Signer(AwsSigv4SignerOptions); + await AwsSigv4Signer(AwsSigv4SignerOptions); t.fail('Should fail'); } catch (err) { t.ok(err instanceof AwsSigv4SignerError); @@ -64,7 +76,7 @@ test('Sign with SigV4 failure (with empty region)', (t) => { } }); -test('Sign with SigV4 failure (with empty credentials)', (t) => { +test('Sign with SigV4 failure (without getCredentials function)', async (t) => { t.plan(2); const mockRegion = 'us-west-2'; @@ -72,10 +84,10 @@ test('Sign with SigV4 failure (with empty credentials)', (t) => { const AwsSigv4SignerOptions = { region: mockRegion }; try { - AwsSigv4Signer(AwsSigv4SignerOptions); + await AwsSigv4Signer(AwsSigv4SignerOptions); t.fail('Should fail'); } catch (err) { t.ok(err instanceof AwsSigv4SignerError); - t.equal(err.message, 'Credentials cannot be empty'); + t.equal(err.message, 'getCredentials function is required'); } }); From f629fa19daa3b322ddbe9ff8aa0deeab4115994f Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Thu, 1 Sep 2022 05:50:37 +0700 Subject: [PATCH 14/25] fix AwsSigv4Signer type with Promise Signed-off-by: rawpixel-vincent --- lib/aws/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/aws/index.d.ts b/lib/aws/index.d.ts index fabf40c98..0853a68ce 100644 --- a/lib/aws/index.d.ts +++ b/lib/aws/index.d.ts @@ -28,7 +28,7 @@ interface AwsSigv4SignerResponse { buildSignedRequestObject(request: any): http.ClientRequestArgs; } -declare function AwsSigv4Signer(opts: AwsSigv4SignerOptions): Promise; +type AwsSigv4Signer = (opts: AwsSigv4SignerOptions) => Promise; declare class AwsSigv4SignerError extends OpenSearchClientError { name: string; From c952ba0d2fa8836f5b8a0a72cbbb19456e860bda Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Thu, 1 Sep 2022 06:24:54 +0700 Subject: [PATCH 15/25] remove JSDoc Signed-off-by: rawpixel-vincent --- lib/aws/AwsSigv4Signer.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/aws/AwsSigv4Signer.js b/lib/aws/AwsSigv4Signer.js index e35ddd82e..b02db3018 100644 --- a/lib/aws/AwsSigv4Signer.js +++ b/lib/aws/AwsSigv4Signer.js @@ -16,9 +16,6 @@ const AwsSigv4SignerError = require('./errors'); const DEFAULT_REFRESH_INTERVAL = 1000 * 60 * 14; // 14 minutes. -/** - * @returns {Promise} - */ async function AwsSigv4Signer(opts) { const credentialsState = { credentials: null, From 4abf7ea46c47bb8fee1ba00fdf8f59f9b6b06fc2 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Thu, 1 Sep 2022 17:40:37 +0700 Subject: [PATCH 16/25] update example usage Signed-off-by: rawpixel-vincent --- USER_GUIDE.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 5b5a09606..2d3092b09 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -44,14 +44,33 @@ const { defaultProvider } = require("@aws-sdk/credential-provider-node"); const { Client } = require('@opensearch-project/opensearch'); const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); +const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com + async function getClient() { const connection = await AwsSigv4Signer({ + // Must return an AWS.Credential object. + // Example with aws sdk V3: getCredentials: async () => { const credentials = await defaultProvider()(); return credentials; }, - refresh: false, // Enable refreshing credentials. - refreshInterval: 1000 * 1000 * 60 * 14, // default to 14 minutes, must be set to a value below the expiration time of the credentials. + // Or with v2 for example: + getCredentials: () => + new Promise((resolve, reject) => { + const awsConfig = new AWS.Config({ + region: 'us-east-1', + credentialProvider: new AWS.CredentialProviderChain(), + }); + awsConfig.getCredentials((err, credentials) => { + if (err) { + reject(err); + } else { + resolve(credentials); + } + }); + }), + refresh: true, // Optional, enable refreshing credentials, disabled by default. + refreshInterval: 1000 * 60 * 14, // optional, default to 14 minutes, must be set to a value below the expiration time of the credentials. }); return new Client({ ...connection, From 48e5b3ade617b73d8a4a81edc0515fbee97bc992 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Fri, 2 Sep 2022 21:28:28 +0700 Subject: [PATCH 17/25] update credentials refresh strategy Signed-off-by: rawpixel-vincent --- USER_GUIDE.md | 7 +- lib/aws/AwsSigv4Signer.js | 65 ++++++++++++----- lib/aws/index.d.ts | 6 +- test/types/awssigv4signer.test-d.ts | 10 +-- test/unit/awssigv4signer.test.js | 108 ++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+), 29 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 2d3092b09..538f2435f 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -48,7 +48,10 @@ const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es. async function getClient() { const connection = await AwsSigv4Signer({ - // Must return an AWS.Credential object. + region: 'us-east-1', + // Must return an AWS.Credentials object. + // This function is used when initializing the client and + // when the credentials are expired. // Example with aws sdk V3: getCredentials: async () => { const credentials = await defaultProvider()(); @@ -69,8 +72,6 @@ async function getClient() { } }); }), - refresh: true, // Optional, enable refreshing credentials, disabled by default. - refreshInterval: 1000 * 60 * 14, // optional, default to 14 minutes, must be set to a value below the expiration time of the credentials. }); return new Client({ ...connection, diff --git a/lib/aws/AwsSigv4Signer.js b/lib/aws/AwsSigv4Signer.js index b02db3018..ec6649cb7 100644 --- a/lib/aws/AwsSigv4Signer.js +++ b/lib/aws/AwsSigv4Signer.js @@ -11,15 +11,13 @@ 'use strict'; const Connection = require('../Connection'); +const Transport = require('../Transport'); const aws4 = require('aws4'); const AwsSigv4SignerError = require('./errors'); -const DEFAULT_REFRESH_INTERVAL = 1000 * 60 * 14; // 14 minutes. - async function AwsSigv4Signer(opts) { const credentialsState = { credentials: null, - refreshInterval: null, }; if (opts && (!opts.region || opts.region === null || opts.region === '')) { throw new AwsSigv4SignerError('Region cannot be empty'); @@ -34,21 +32,6 @@ async function AwsSigv4Signer(opts) { throw new AwsSigv4SignerError('fetching credentials failed', error); } - if (opts && opts.refresh === true && !credentialsState.refreshInterval) { - credentialsState.refreshInterval = setInterval( - async () => { - try { - credentialsState.credentials = await opts.getCredentials(); - } catch (error) { - throw new AwsSigv4SignerError('fetching credentials failed', error); - } - }, - typeof opts.refreshInterval === 'number' - ? Math.max(opts.refreshInterval, DEFAULT_REFRESH_INTERVAL) - : DEFAULT_REFRESH_INTERVAL - ); - } - function buildSignedRequestObject(request = {}) { request.service = 'es'; request.region = opts.region; @@ -63,9 +46,55 @@ async function AwsSigv4Signer(opts) { } } + class AwsSigv4SignerTransport extends Transport { + request(params, options = {}, callback = undefined) { + // options is optional, + // so if it is omitted, options will be the callback + if (typeof options === 'function') { + callback = options; + options = {}; + } + + /** @type {import('aws-sdk').Credentials} */ + const currentCredentials = credentialsState.credentials; + + const expired = + (typeof currentCredentials.expired !== 'undefined' && currentCredentials.expired) || + (typeof currentCredentials.expiration !== 'undefined' && + currentCredentials.expiration < new Date()) || + (typeof currentCredentials.expired === 'undefined' && + typeof currentCredentials.expiration === 'undefined'); + + if (expired) { + // Promise support + if (typeof callback === 'undefined') { + return opts.getCredentials().then((newCredentials) => { + credentialsState.credentials = newCredentials; + return super.request(params, options); + }); + } + + // Callback support + opts + .getCredentials() + .then((newCredentials) => { + credentialsState.credentials = newCredentials; + return super.request(params, options, callback); + }) + .catch(callback); + } else if (typeof callback === 'undefined') { + return super.request(params, options); + } else { + super.request(params, options, callback); + } + } + } + return { + Transport: AwsSigv4SignerTransport, Connection: AwsSigv4SignerConnection, buildSignedRequestObject, + credentialsState, }; } module.exports = AwsSigv4Signer; diff --git a/lib/aws/index.d.ts b/lib/aws/index.d.ts index 0853a68ce..d1537fead 100644 --- a/lib/aws/index.d.ts +++ b/lib/aws/index.d.ts @@ -13,22 +13,22 @@ import { Credentials } from '@aws-sdk/types'; import Connection from '../Connection'; +import Transport from '../Transport'; import * as http from 'http'; import { OpenSearchClientError } from '../errors'; interface AwsSigv4SignerOptions { getCredentials: () => Promise; region: string; - refresh?: boolean; - refreshInterval?: number; } interface AwsSigv4SignerResponse { Connection: Connection; + Transport: Transport, buildSignedRequestObject(request: any): http.ClientRequestArgs; } -type AwsSigv4Signer = (opts: AwsSigv4SignerOptions) => Promise; +declare function AwsSigv4Signer (opts: AwsSigv4SignerOptions): Promise; declare class AwsSigv4SignerError extends OpenSearchClientError { name: string; diff --git a/test/types/awssigv4signer.test-d.ts b/test/types/awssigv4signer.test-d.ts index 291e71900..ac060a4a9 100644 --- a/test/types/awssigv4signer.test-d.ts +++ b/test/types/awssigv4signer.test-d.ts @@ -8,24 +8,24 @@ * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. */ - -import { Credentials } from '@aws-sdk/types'; import { expectType } from 'tsd'; const { v4: uuidv4 } = require('uuid'); import { AwsSigv4SignerResponse, AwsSigv4Signer } from '../../lib/aws'; -const mockCreds: Credentials = { +const mockCreds = { accessKeyId: uuidv4(), secretAccessKey: uuidv4(), + expired: false, + expiration: new Date(), + sessionToken: uuidv4(), }; -const mockRegion = 'us-west-2'; +const mockRegion = 'us-east-1'; { const AwsSigv4SignerOptions = { getCredentials: () => Promise.resolve(mockCreds), region: mockRegion, - refresh: true, }; const auth = AwsSigv4Signer(AwsSigv4SignerOptions); diff --git a/test/unit/awssigv4signer.test.js b/test/unit/awssigv4signer.test.js index de51b45c2..df681c441 100644 --- a/test/unit/awssigv4signer.test.js +++ b/test/unit/awssigv4signer.test.js @@ -14,6 +14,7 @@ const { v4: uuidv4 } = require('uuid'); const AwsSigv4Signer = require('../../lib/aws/AwsSigv4Signer'); const AwsSigv4SignerError = require('../../lib/aws/errors'); const { Connection } = require('../../index'); +const { Client, buildServer } = require('../utils'); test('Sign with SigV4', async (t) => { t.plan(2); @@ -91,3 +92,110 @@ test('Sign with SigV4 failure (without getCredentials function)', async (t) => { t.equal(err.message, 'getCredentials function is required'); } }); + +test('Basic aws (promises)', (t) => { + t.plan(1); + + function handler(req, res) { + res.setHeader('Content-Type', 'application/json;utf=8'); + res.end(JSON.stringify({ hello: 'world' })); + } + + buildServer(handler, ({ port }, server) => { + const mockCreds = { + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + expired: false, + }; + + const mockRegion = 'us-east-1'; + + const AwsSigv4SignerOptions = { + region: mockRegion, + getCredentials: () => + new Promise((resolve) => { + setTimeout(() => { + resolve(mockCreds); + }, 100); + }), + }; + const client = new Client({ + ...AwsSigv4Signer(AwsSigv4SignerOptions), + node: `http://localhost:${port}`, + }); + + client + .search({ + index: 'test', + q: 'foo:bar', + }) + .then(({ body }) => { + t.same(body, { hello: 'world' }); + server.stop(); + }) + .catch(t.fail); + }); +}); + +test('Basic with expired token (promises)', (t) => { + t.plan(1); + + function handler(req, res) { + res.setHeader('Content-Type', 'application/json;utf=8'); + res.end(JSON.stringify({ hello: 'world' })); + } + + buildServer(handler, async ({ port }, server) => { + const mockCredsExpired = { + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + expiration: new Date(Date.now() - 1000), + }; + + const mockCredsRenewed = { + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + expiration: new Date(Date.now() - 1000), + }; + + const mockRegion = 'us-east-1'; + + const getCredentials = () => { + let currentCreds = null; + return () => + new Promise((resolve) => { + setTimeout(() => { + if (currentCreds) { + resolve(mockCredsRenewed); + } else { + currentCreds = mockCredsExpired; + resolve(mockCredsExpired); + } + }, 100); + }); + }; + + const AwsSigv4SignerOptions = { + getCredentials: getCredentials(), + region: mockRegion, + }; + + const auth = await AwsSigv4Signer(AwsSigv4SignerOptions); + + const client = new Client({ + ...auth, + node: `http://localhost:${port}`, + }); + + client + .search({ + index: 'test', + q: 'foo:bar', + }) + .then(({ body }) => { + t.same(body, { hello: 'world' }); + server.stop(); + }) + .catch(t.fail); + }); +}); From e376ef46e801cd5ed572a68641890e0520c2541e Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Sat, 3 Sep 2022 22:14:07 +0700 Subject: [PATCH 18/25] update credentials refresh and expiration Signed-off-by: rawpixel-vincent --- USER_GUIDE.md | 38 +++--- lib/aws/AwsSigv4Signer.js | 76 +++++++----- lib/aws/index.d.ts | 4 +- test/types/awssigv4signer.test-d.ts | 4 +- test/unit/awssigv4signer.test.js | 175 +++++++++++++++++++++------- 5 files changed, 199 insertions(+), 98 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 538f2435f..c7e16d109 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -40,31 +40,27 @@ var client = new Client({ ### To authenticate with [Amazon OpenSearch Service](https://aws.amazon.com/opensearch-service/) using AwsSigv4Signer ```javascript -const { defaultProvider } = require("@aws-sdk/credential-provider-node"); +const AWS = require('aws-sdk'); // V2 SDK. +const { defaultProvider } = require("@aws-sdk/credential-provider-node"); // V3 SDK. const { Client } = require('@opensearch-project/opensearch'); const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); -const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com - -async function getClient() { - const connection = await AwsSigv4Signer({ +const client = new Client({ + ...AwsSigv4Signer({ region: 'us-east-1', - // Must return an AWS.Credentials object. - // This function is used when initializing the client and + // Must return a Promise that resolve to an AWS.Credentials object. + // This function is used to acquire the credentials when the client start and // when the credentials are expired. + // Credentials.refreshPromise is used instead to refresh the credentials + // when availabe (aws sdk v2) + // Example with aws sdk V3: - getCredentials: async () => { - const credentials = await defaultProvider()(); - return credentials; - }, + getCredentials: defaultProvider(), + // Or with v2 for example: getCredentials: () => new Promise((resolve, reject) => { - const awsConfig = new AWS.Config({ - region: 'us-east-1', - credentialProvider: new AWS.CredentialProviderChain(), - }); - awsConfig.getCredentials((err, credentials) => { + AWS.config.getCredentials((err, credentials) => { if (err) { reject(err); } else { @@ -72,12 +68,10 @@ async function getClient() { } }); }), - }); - return new Client({ - ...connection, - node: endpoint, - }); -} + }), + node: "", // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com +}); + ``` ## Create an Index diff --git a/lib/aws/AwsSigv4Signer.js b/lib/aws/AwsSigv4Signer.js index ec6649cb7..d32a97298 100644 --- a/lib/aws/AwsSigv4Signer.js +++ b/lib/aws/AwsSigv4Signer.js @@ -15,9 +15,10 @@ const Transport = require('../Transport'); const aws4 = require('aws4'); const AwsSigv4SignerError = require('./errors'); -async function AwsSigv4Signer(opts) { +function AwsSigv4Signer(opts) { const credentialsState = { credentials: null, + acquiredAt: 0, }; if (opts && (!opts.region || opts.region === null || opts.region === '')) { throw new AwsSigv4SignerError('Region cannot be empty'); @@ -26,12 +27,6 @@ async function AwsSigv4Signer(opts) { throw new AwsSigv4SignerError('getCredentials function is required'); } - try { - credentialsState.credentials = await opts.getCredentials(); - } catch (error) { - throw new AwsSigv4SignerError('fetching credentials failed', error); - } - function buildSignedRequestObject(request = {}) { request.service = 'es'; request.region = opts.region; @@ -39,6 +34,7 @@ async function AwsSigv4Signer(opts) { request.headers['host'] = request.hostname; return aws4.sign(request, credentialsState.credentials); } + class AwsSigv4SignerConnection extends Connection { buildRequestObject(params) { const request = super.buildRequestObject(params); @@ -51,41 +47,68 @@ async function AwsSigv4Signer(opts) { // options is optional, // so if it is omitted, options will be the callback if (typeof options === 'function') { + // eslint-disable-next-line no-param-reassign callback = options; + // eslint-disable-next-line no-param-reassign options = {}; } - /** @type {import('aws-sdk').Credentials} */ const currentCredentials = credentialsState.credentials; + let expired = false; + if (!currentCredentials) { + expired = true; + } else if (typeof currentCredentials.needsRefresh === 'function') { + expired = currentCredentials.needsRefresh(); + } else if (currentCredentials.expired === true) { + expired = true; + } else if (currentCredentials.expireTime && currentCredentials.expireTime < new Date()) { + expired = true; + } else if (currentCredentials.expiration && currentCredentials.expiration < new Date()) { + expired = true; + } - const expired = - (typeof currentCredentials.expired !== 'undefined' && currentCredentials.expired) || - (typeof currentCredentials.expiration !== 'undefined' && - currentCredentials.expiration < new Date()) || - (typeof currentCredentials.expired === 'undefined' && - typeof currentCredentials.expiration === 'undefined'); + if (!expired) { + if (typeof callback === 'undefined') { + return super.request(params, options); + } - if (expired) { - // Promise support + super.request(params, options, callback); + return; + } + + if (currentCredentials && typeof currentCredentials.refreshPromise === 'function') { if (typeof callback === 'undefined') { - return opts.getCredentials().then((newCredentials) => { - credentialsState.credentials = newCredentials; + return currentCredentials.refreshPromise().then(() => { + credentialsState.acquiredAt = Date.now(); return super.request(params, options); }); + } else { + currentCredentials + .refreshPromise() + .then(() => { + credentialsState.acquiredAt = Date.now(); + super.request(params, options, callback); + }) + .catch(callback); + return; } + } - // Callback support + if (typeof callback === 'undefined') { + return opts.getCredentials().then((credentials) => { + credentialsState.acquiredAt = Date.now(); + credentialsState.credentials = credentials; + return super.request(params, options); + }); + } else { opts .getCredentials() - .then((newCredentials) => { - credentialsState.credentials = newCredentials; - return super.request(params, options, callback); + .then((credentials) => { + credentialsState.acquiredAt = Date.now(); + credentialsState.credentials = credentials; + super.request(params, options, callback); }) .catch(callback); - } else if (typeof callback === 'undefined') { - return super.request(params, options); - } else { - super.request(params, options, callback); } } } @@ -94,7 +117,6 @@ async function AwsSigv4Signer(opts) { Transport: AwsSigv4SignerTransport, Connection: AwsSigv4SignerConnection, buildSignedRequestObject, - credentialsState, }; } module.exports = AwsSigv4Signer; diff --git a/lib/aws/index.d.ts b/lib/aws/index.d.ts index d1537fead..52fc8f859 100644 --- a/lib/aws/index.d.ts +++ b/lib/aws/index.d.ts @@ -24,11 +24,11 @@ interface AwsSigv4SignerOptions { interface AwsSigv4SignerResponse { Connection: Connection; - Transport: Transport, + Transport: Transport; buildSignedRequestObject(request: any): http.ClientRequestArgs; } -declare function AwsSigv4Signer (opts: AwsSigv4SignerOptions): Promise; +declare function AwsSigv4Signer (opts: AwsSigv4SignerOptions): AwsSigv4SignerResponse; declare class AwsSigv4SignerError extends OpenSearchClientError { name: string; diff --git a/test/types/awssigv4signer.test-d.ts b/test/types/awssigv4signer.test-d.ts index ac060a4a9..f45e38dbe 100644 --- a/test/types/awssigv4signer.test-d.ts +++ b/test/types/awssigv4signer.test-d.ts @@ -16,7 +16,7 @@ const mockCreds = { accessKeyId: uuidv4(), secretAccessKey: uuidv4(), expired: false, - expiration: new Date(), + expireTime: new Date(), sessionToken: uuidv4(), }; @@ -30,5 +30,5 @@ const mockRegion = 'us-east-1'; const auth = AwsSigv4Signer(AwsSigv4SignerOptions); - expectType>(auth); + expectType(auth); } diff --git a/test/unit/awssigv4signer.test.js b/test/unit/awssigv4signer.test.js index df681c441..90e5363e3 100644 --- a/test/unit/awssigv4signer.test.js +++ b/test/unit/awssigv4signer.test.js @@ -16,7 +16,7 @@ const AwsSigv4SignerError = require('../../lib/aws/errors'); const { Connection } = require('../../index'); const { Client, buildServer } = require('../utils'); -test('Sign with SigV4', async (t) => { +test('Sign with SigV4', (t) => { t.plan(2); const mockCreds = { @@ -34,7 +34,7 @@ test('Sign with SigV4', async (t) => { region: mockRegion, }; - const auth = await AwsSigv4Signer(AwsSigv4SignerOptions); + const auth = AwsSigv4Signer(AwsSigv4SignerOptions); const connection = new Connection({ url: new URL('https://localhost:9200'), @@ -53,7 +53,7 @@ test('Sign with SigV4', async (t) => { t.hasProp(signedRequest.headers, 'Authorization'); }); -test('Sign with SigV4 failure (with empty region)', async (t) => { +test('Sign with SigV4 failure (with empty region)', (t) => { t.plan(2); const mockCreds = { @@ -69,15 +69,15 @@ test('Sign with SigV4 failure (with empty region)', async (t) => { }; try { - await AwsSigv4Signer(AwsSigv4SignerOptions); + AwsSigv4Signer(AwsSigv4SignerOptions); t.fail('Should fail'); } catch (err) { t.ok(err instanceof AwsSigv4SignerError); - t.equal(err.message, 'Region cannot be empty'); + t.same(err.message, 'Region cannot be empty'); } }); -test('Sign with SigV4 failure (without getCredentials function)', async (t) => { +test('Sign with SigV4 failure (without getCredentials function)', (t) => { t.plan(2); const mockRegion = 'us-west-2'; @@ -85,16 +85,16 @@ test('Sign with SigV4 failure (without getCredentials function)', async (t) => { const AwsSigv4SignerOptions = { region: mockRegion }; try { - await AwsSigv4Signer(AwsSigv4SignerOptions); + AwsSigv4Signer(AwsSigv4SignerOptions); t.fail('Should fail'); } catch (err) { t.ok(err instanceof AwsSigv4SignerError); - t.equal(err.message, 'getCredentials function is required'); + t.same(err.message, 'getCredentials function is required'); } }); test('Basic aws (promises)', (t) => { - t.plan(1); + t.plan(4); function handler(req, res) { res.setHeader('Content-Type', 'application/json;utf=8'); @@ -102,20 +102,21 @@ test('Basic aws (promises)', (t) => { } buildServer(handler, ({ port }, server) => { - const mockCreds = { - accessKeyId: uuidv4(), - secretAccessKey: uuidv4(), - expired: false, - }; - const mockRegion = 'us-east-1'; + let getCredentialsCalled = 0; const AwsSigv4SignerOptions = { region: mockRegion, getCredentials: () => new Promise((resolve) => { setTimeout(() => { - resolve(mockCreds); + getCredentialsCalled++; + resolve({ + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + expired: false, + expireTime: new Date(Date.now() + 1000 * 60 * 60), + }); }, 100); }), }; @@ -131,56 +132,126 @@ test('Basic aws (promises)', (t) => { }) .then(({ body }) => { t.same(body, { hello: 'world' }); - server.stop(); + t.same(getCredentialsCalled, 1); + client + .search({ + index: 'test', + q: 'foo:bar', + }) + .then(({ body }) => { + t.same(body, { hello: 'world' }); + t.same(getCredentialsCalled, 1); + + server.stop(); + }) + .catch(t.fail); }) .catch(t.fail); }); }); test('Basic with expired token (promises)', (t) => { - t.plan(1); + t.plan(4); function handler(req, res) { res.setHeader('Content-Type', 'application/json;utf=8'); res.end(JSON.stringify({ hello: 'world' })); } - buildServer(handler, async ({ port }, server) => { - const mockCredsExpired = { - accessKeyId: uuidv4(), - secretAccessKey: uuidv4(), - expiration: new Date(Date.now() - 1000), - }; + buildServer(handler, ({ port }, server) => { + const mockRegion = 'us-east-1'; - const mockCredsRenewed = { - accessKeyId: uuidv4(), - secretAccessKey: uuidv4(), - expiration: new Date(Date.now() - 1000), + let getCredentialsCalled = 0; + const getCredentials = () => + new Promise((resolve) => { + setTimeout(() => { + getCredentialsCalled++; + resolve({ + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + expired: true, + expireTime: new Date(Date.now() - 1000), + }); + }, 100); + }); + + const AwsSigv4SignerOptions = { + getCredentials: getCredentials, + region: mockRegion, }; + const auth = AwsSigv4Signer(AwsSigv4SignerOptions); + + const client = new Client({ + ...auth, + node: `http://localhost:${port}`, + }); + + client + .search({ + index: 'test', + q: 'foo:bar', + }) + .then(({ body }) => { + t.same(body, { hello: 'world' }); + t.same(getCredentialsCalled, 1); + client + .search({ + index: 'test', + q: 'foo:bar', + }) + .then(({ body }) => { + t.same(body, { hello: 'world' }); + t.same(getCredentialsCalled, 2); + + server.stop(); + }) + .catch(t.fail); + }) + .catch(t.fail); + }); +}); + +test('Basic with expired token and credentials sdk refresh (promises)', (t) => { + t.plan(6); + + function handler(req, res) { + res.setHeader('Content-Type', 'application/json;utf=8'); + res.end(JSON.stringify({ hello: 'world' })); + } + + buildServer(handler, ({ port }, server) => { const mockRegion = 'us-east-1'; - const getCredentials = () => { - let currentCreds = null; - return () => - new Promise((resolve) => { - setTimeout(() => { - if (currentCreds) { - resolve(mockCredsRenewed); - } else { - currentCreds = mockCredsExpired; - resolve(mockCredsExpired); - } - }, 100); - }); - }; + let getCredentialsCalled = 0; + let refreshPromiseCalled = 0; + const getCredentials = () => + new Promise((resolve) => { + setTimeout(() => { + getCredentialsCalled++; + resolve({ + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + needsRefresh: () => true, + refreshPromise: () => + new Promise((resolve) => { + refreshPromiseCalled++; + resolve({ + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + expired: false, + }); + }), + }); + }, 100); + }); const AwsSigv4SignerOptions = { - getCredentials: getCredentials(), + getCredentials: getCredentials, region: mockRegion, }; - const auth = await AwsSigv4Signer(AwsSigv4SignerOptions); + const auth = AwsSigv4Signer(AwsSigv4SignerOptions); const client = new Client({ ...auth, @@ -194,7 +265,21 @@ test('Basic with expired token (promises)', (t) => { }) .then(({ body }) => { t.same(body, { hello: 'world' }); - server.stop(); + t.same(getCredentialsCalled, 1); + t.same(refreshPromiseCalled, 0); + client + .search({ + index: 'test', + q: 'foo:bar', + }) + .then(({ body }) => { + t.same(body, { hello: 'world' }); + t.same(getCredentialsCalled, 1); + t.same(refreshPromiseCalled, 1); + + server.stop(); + }) + .catch(t.fail); }) .catch(t.fail); }); From 1475bf077eca449d21c4d46b342a4b6508d914f5 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Sat, 3 Sep 2022 22:27:04 +0700 Subject: [PATCH 19/25] fix types Signed-off-by: rawpixel-vincent --- lib/aws/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aws/index.d.ts b/lib/aws/index.d.ts index 52fc8f859..50ba0c4f0 100644 --- a/lib/aws/index.d.ts +++ b/lib/aws/index.d.ts @@ -23,8 +23,8 @@ interface AwsSigv4SignerOptions { } interface AwsSigv4SignerResponse { - Connection: Connection; - Transport: Transport; + Connection: typeof Connection; + Transport: typeof Transport; buildSignedRequestObject(request: any): http.ClientRequestArgs; } From 52ab9ad18a73e653e5e68ef827a246a37f970069 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Sun, 4 Sep 2022 04:33:42 +0700 Subject: [PATCH 20/25] add failure to refresh credentials test case Signed-off-by: rawpixel-vincent --- test/unit/awssigv4signer.test.js | 121 +++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/test/unit/awssigv4signer.test.js b/test/unit/awssigv4signer.test.js index 90e5363e3..b3be5c47a 100644 --- a/test/unit/awssigv4signer.test.js +++ b/test/unit/awssigv4signer.test.js @@ -284,3 +284,124 @@ test('Basic with expired token and credentials sdk refresh (promises)', (t) => { .catch(t.fail); }); }); + +test('Basic aws (callback)', (t) => { + t.plan(6); + + function handler(req, res) { + res.setHeader('Content-Type', 'application/json;utf=8'); + res.end(JSON.stringify({ hello: 'world' })); + } + + buildServer(handler, ({ port }, server) => { + const mockRegion = 'us-east-1'; + + let getCredentialsCalled = 0; + const AwsSigv4SignerOptions = { + region: mockRegion, + getCredentials: () => + new Promise((resolve) => { + setTimeout(() => { + getCredentialsCalled++; + resolve({ + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + expiration: new Date(Date.now() + 1000 * 60 * 60), + }); + }, 100); + }), + }; + const client = new Client({ + ...AwsSigv4Signer(AwsSigv4SignerOptions), + node: `http://localhost:${port}`, + }); + + client.search( + { + index: 'test', + q: 'foo:bar', + }, + (err, { body }) => { + t.error(err); + t.same(body, { hello: 'world' }); + t.same(getCredentialsCalled, 1); + client.search( + { + index: 'test', + q: 'foo:bar', + }, + (err, { body }) => { + t.error(err); + t.same(body, { hello: 'world' }); + t.same(getCredentialsCalled, 1); + server.stop(); + } + ); + } + ); + }); +}); + +test('Basic aws failure to refresh credentials', (t) => { + t.plan(4); + + function handler(req, res) { + res.setHeader('Content-Type', 'application/json;utf=8'); + res.end(JSON.stringify({ hello: 'world' })); + } + + buildServer(handler, ({ port }, server) => { + const mockRegion = 'us-east-1'; + + let getCredentialsCalled = 0; + const AwsSigv4SignerOptions = { + region: mockRegion, + getCredentials: () => + new Promise((resolve, reject) => { + setTimeout(() => { + getCredentialsCalled++; + if (getCredentialsCalled === 1) { + resolve({ + accessKeyId: uuidv4(), + secretAccessKey: uuidv4(), + expireTime: new Date(Date.now() - 1000 * 60 * 60), + }); + } else { + reject(new Error('Failed to refresh credentials')); + } + }, 100); + }), + }; + const client = new Client({ + ...AwsSigv4Signer(AwsSigv4SignerOptions), + node: `http://localhost:${port}`, + }); + + client + .search({ + index: 'test', + q: 'foo:bar', + }) + .then(({ body }) => { + t.same(body, { hello: 'world' }); + t.same(getCredentialsCalled, 1); + client + .search({ + index: 'test', + q: 'foo:bar', + }) + .then(({ body }) => { + t.same(getCredentialsCalled, 2); + t.fail('Should fail'); + }) + .catch((err) => { + t.ok(err); + t.same(getCredentialsCalled, 2); + }) + .finally(() => { + server.stop(); + }); + }) + .catch(t.fail); + }); +}); From d31eb6f00acfe749b405372e0e131c6b29f9a678 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Sun, 4 Sep 2022 05:17:03 +0700 Subject: [PATCH 21/25] cleanup and comments Signed-off-by: rawpixel-vincent --- lib/aws/AwsSigv4Signer.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/aws/AwsSigv4Signer.js b/lib/aws/AwsSigv4Signer.js index d32a97298..db5f3e176 100644 --- a/lib/aws/AwsSigv4Signer.js +++ b/lib/aws/AwsSigv4Signer.js @@ -44,26 +44,32 @@ function AwsSigv4Signer(opts) { class AwsSigv4SignerTransport extends Transport { request(params, options = {}, callback = undefined) { - // options is optional, - // so if it is omitted, options will be the callback + // options is optional so if options is a function, it's the callback. if (typeof options === 'function') { - // eslint-disable-next-line no-param-reassign callback = options; - // eslint-disable-next-line no-param-reassign options = {}; } const currentCredentials = credentialsState.credentials; let expired = false; if (!currentCredentials) { + // Credentials haven't been acquired yet. expired = true; - } else if (typeof currentCredentials.needsRefresh === 'function') { + } + // AWS SDK V2, needsRefresh should be available. + else if (typeof currentCredentials.needsRefresh === 'function') { expired = currentCredentials.needsRefresh(); - } else if (currentCredentials.expired === true) { + } + // AWS SDK V2, alternative to needsRefresh. + else if (currentCredentials.expired === true) { expired = true; - } else if (currentCredentials.expireTime && currentCredentials.expireTime < new Date()) { + } + // AWS SDK V2, alternative to needsRefresh and expired. + else if (currentCredentials.expireTime && currentCredentials.expireTime < new Date()) { expired = true; - } else if (currentCredentials.expiration && currentCredentials.expiration < new Date()) { + } + // AWS SDK V3, Credentials.expiration is a Date object + else if (currentCredentials.expiration && currentCredentials.expiration < new Date()) { expired = true; } @@ -71,11 +77,11 @@ function AwsSigv4Signer(opts) { if (typeof callback === 'undefined') { return super.request(params, options); } - super.request(params, options, callback); return; } + // In AWS SDK V2 Credentials.refreshPromise should be available. if (currentCredentials && typeof currentCredentials.refreshPromise === 'function') { if (typeof callback === 'undefined') { return currentCredentials.refreshPromise().then(() => { @@ -94,6 +100,7 @@ function AwsSigv4Signer(opts) { } } + // For AWS SDK V3 or when the client has not acquired credentials yet. if (typeof callback === 'undefined') { return opts.getCredentials().then((credentials) => { credentialsState.acquiredAt = Date.now(); From f036b303e0838382cee838d691c1e157eab89c83 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Tue, 6 Sep 2022 21:12:50 +0700 Subject: [PATCH 22/25] clarify code example in the docs Signed-off-by: rawpixel-vincent --- USER_GUIDE.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index c7e16d109..a21e16bd5 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -51,15 +51,20 @@ const client = new Client({ // Must return a Promise that resolve to an AWS.Credentials object. // This function is used to acquire the credentials when the client start and // when the credentials are expired. - // Credentials.refreshPromise is used instead to refresh the credentials - // when availabe (aws sdk v2) - - // Example with aws sdk V3: - getCredentials: defaultProvider(), + // The Client will refresh the Credentials only when they are expired. + // With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials. + + // Example with AWS SDK V3: + getCredentials: async () => { + // Any other method to acquire a new Credentials object can be used. + const credentialsProvider = defaultProvider(); + return credentialsProvider(); + }, - // Or with v2 for example: + // Example with AWS SDK V2: getCredentials: () => new Promise((resolve, reject) => { + // Any other method to acquire a new Credentials object can be used. AWS.config.getCredentials((err, credentials) => { if (err) { reject(err); @@ -69,7 +74,7 @@ const client = new Client({ }); }), }), - node: "", // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com + node: "https://search-xxx.region.es.amazonaws.com", // OpenSearch domain URL }); ``` From ef2b3c72754e933b751d924b3bb31a8fc3292a11 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Wed, 7 Sep 2022 00:11:12 +0700 Subject: [PATCH 23/25] remove explicit async from code example Signed-off-by: rawpixel-vincent --- USER_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index a21e16bd5..3c33e9705 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -55,7 +55,7 @@ const client = new Client({ // With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials. // Example with AWS SDK V3: - getCredentials: async () => { + getCredentials: () => { // Any other method to acquire a new Credentials object can be used. const credentialsProvider = defaultProvider(); return credentialsProvider(); From 13d30de628ecbc92a92cbb30f991b423a9a6b527 Mon Sep 17 00:00:00 2001 From: rawpixel-vincent Date: Wed, 7 Sep 2022 00:11:38 +0700 Subject: [PATCH 24/25] remove unused credentialsState.acquiredAt Signed-off-by: rawpixel-vincent --- lib/aws/AwsSigv4Signer.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/aws/AwsSigv4Signer.js b/lib/aws/AwsSigv4Signer.js index db5f3e176..7e0c7c614 100644 --- a/lib/aws/AwsSigv4Signer.js +++ b/lib/aws/AwsSigv4Signer.js @@ -18,7 +18,6 @@ const AwsSigv4SignerError = require('./errors'); function AwsSigv4Signer(opts) { const credentialsState = { credentials: null, - acquiredAt: 0, }; if (opts && (!opts.region || opts.region === null || opts.region === '')) { throw new AwsSigv4SignerError('Region cannot be empty'); @@ -85,14 +84,12 @@ function AwsSigv4Signer(opts) { if (currentCredentials && typeof currentCredentials.refreshPromise === 'function') { if (typeof callback === 'undefined') { return currentCredentials.refreshPromise().then(() => { - credentialsState.acquiredAt = Date.now(); return super.request(params, options); }); } else { currentCredentials .refreshPromise() .then(() => { - credentialsState.acquiredAt = Date.now(); super.request(params, options, callback); }) .catch(callback); @@ -103,7 +100,6 @@ function AwsSigv4Signer(opts) { // For AWS SDK V3 or when the client has not acquired credentials yet. if (typeof callback === 'undefined') { return opts.getCredentials().then((credentials) => { - credentialsState.acquiredAt = Date.now(); credentialsState.credentials = credentials; return super.request(params, options); }); @@ -111,7 +107,6 @@ function AwsSigv4Signer(opts) { opts .getCredentials() .then((credentials) => { - credentialsState.acquiredAt = Date.now(); credentialsState.credentials = credentials; super.request(params, options, callback); }) From b1308b9485dcd93f95f2e6c4fae707be80740659 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Wed, 7 Sep 2022 02:54:47 +0000 Subject: [PATCH 25/25] Minor doc and misc fixes Signed-off-by: Harsha Vamsi Kalluri --- USER_GUIDE.md | 58 ++++++++++++++----- .../unit/{ => lib/aws}/awssigv4signer.test.js | 8 +-- 2 files changed, 46 insertions(+), 20 deletions(-) rename test/unit/{ => lib/aws}/awssigv4signer.test.js (97%) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 3c33e9705..289c10243 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -2,7 +2,9 @@ - [User Guide](#user-guide) - [Initializing a Client](#initializing-a-client) - - [To authenticate with Amazon OpenSearch Service using AwsSigv4Signer](#to-authenticate-with-amazon-opensearch-service-using-awssigv4signer) + - [Authenticate with Amazon OpenSearch Service](#authenticate-with-amazon-opensearch-service) + - [Using AWS V2 SDK](#using-aws-v2-sdk) + - [Using AWS V3 SDK](#using-aws-v3-sdk) - [Create an Index](#create-an-index) - [Add a Document to the Index](#add-a-document-to-the-index) - [Search for the Document](#search-for-the-document) @@ -37,11 +39,12 @@ var client = new Client({ }); ``` -### To authenticate with [Amazon OpenSearch Service](https://aws.amazon.com/opensearch-service/) using AwsSigv4Signer +### Authenticate with Amazon OpenSearch Service + +#### Using AWS V2 SDK ```javascript const AWS = require('aws-sdk'); // V2 SDK. -const { defaultProvider } = require("@aws-sdk/credential-provider-node"); // V3 SDK. const { Client } = require('@opensearch-project/opensearch'); const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); @@ -54,13 +57,6 @@ const client = new Client({ // The Client will refresh the Credentials only when they are expired. // With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials. - // Example with AWS SDK V3: - getCredentials: () => { - // Any other method to acquire a new Credentials object can be used. - const credentialsProvider = defaultProvider(); - return credentialsProvider(); - }, - // Example with AWS SDK V2: getCredentials: () => new Promise((resolve, reject) => { @@ -76,12 +72,40 @@ const client = new Client({ }), node: "https://search-xxx.region.es.amazonaws.com", // OpenSearch domain URL }); +``` + +#### Using AWS V3 SDK + +```javascript +const { defaultProvider } = require("@aws-sdk/credential-provider-node"); // V3 SDK. +const { Client } = require('@opensearch-project/opensearch'); +const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); + +const client = new Client({ + ...AwsSigv4Signer({ + region: 'us-east-1', + // Must return a Promise that resolve to an AWS.Credentials object. + // This function is used to acquire the credentials when the client start and + // when the credentials are expired. + // The Client will refresh the Credentials only when they are expired. + // With AWS SDK V2, Credentials.refreshPromise is used when available to refresh the credentials. + // Example with AWS SDK V3: + getCredentials: () => { + // Any other method to acquire a new Credentials object can be used. + const credentialsProvider = defaultProvider(); + return credentialsProvider(); + }, + }), + node: "https://search-xxx.region.es.amazonaws.com", // OpenSearch domain URL +}); ``` ## Create an Index ```javascript + console.log('Creating index:'); + var index_name = 'books'; var settings = { settings: { @@ -97,13 +121,14 @@ const client = new Client({ body: settings, }); - console.log('Creating index:'); console.log(response.body); ``` ## Add a Document to the Index ```javascript + console.log('Adding document:'); + var document = { title: 'The Outsider', author: 'Stephen King', @@ -120,13 +145,14 @@ const client = new Client({ refresh: true, }); - console.log('Adding document:'); console.log(response.body); ``` ## Search for the Document ```javascript + console.log('Search results:'); + var query = { query: { match: { @@ -142,30 +168,30 @@ const client = new Client({ body: query, }); - console.log('Search results:'); console.log(response.body.hits); ``` ## Delete the document ```javascript + console.log('Deleting document:'); + var response = await client.delete({ index: index_name, id: id, }); - console.log('Deleting document:'); console.log(response.body); ``` ## Delete the index ```javascript + console.log('Deleting index:'); + var response = await client.indices.delete({ index: index_name, }); - console.log('Deleting index:'); console.log(response.body); -} ``` \ No newline at end of file diff --git a/test/unit/awssigv4signer.test.js b/test/unit/lib/aws/awssigv4signer.test.js similarity index 97% rename from test/unit/awssigv4signer.test.js rename to test/unit/lib/aws/awssigv4signer.test.js index b3be5c47a..c895c4915 100644 --- a/test/unit/awssigv4signer.test.js +++ b/test/unit/lib/aws/awssigv4signer.test.js @@ -11,10 +11,10 @@ const { test } = require('tap'); const { URL } = require('url'); const { v4: uuidv4 } = require('uuid'); -const AwsSigv4Signer = require('../../lib/aws/AwsSigv4Signer'); -const AwsSigv4SignerError = require('../../lib/aws/errors'); -const { Connection } = require('../../index'); -const { Client, buildServer } = require('../utils'); +const AwsSigv4Signer = require('../../../../lib/aws/AwsSigv4Signer'); +const AwsSigv4SignerError = require('../../../../lib/aws/errors'); +const { Connection } = require('../../../../index'); +const { Client, buildServer } = require('../../../utils'); test('Sign with SigV4', (t) => { t.plan(2);