diff --git a/.gitignore b/.gitignore index d8abd2df1..1f15093f3 100644 --- a/.gitignore +++ b/.gitignore @@ -56,6 +56,9 @@ opensearch* # documentation docs/ +# temporary +tmp/ + test/benchmarks/macro/fixtures/* *-junit.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fd805ebe..5b64495ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Documented Transport#request ([#335](https://github.com/opensearch-project/opensearch-js/issues/335)) - Documented all API methods ([#335](https://github.com/opensearch-project/opensearch-js/issues/335)) - Added point in time APIs ([#348](https://github.com/opensearch-project/opensearch-js/pull/348)) +- Added support for Amazon OpenSearch Serverless ([#356](https://github.com/opensearch-project/opensearch-js/issues/356)) + ### Dependencies - Bumps `xmlbuilder2` from 2.4.1 to 3.0.2 - Bumps `minimatch` from 3.0.4 to 3.1.2 @@ -49,4 +51,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fix mutability of connection headers ([#291](https://github.com/opensearch-project/opensearch-js/issues/291)) [2.1]: https://github.com/opensearch-project/opensearch-js/releases/tag/2.1.0 -[Unreleased]: https://github.com/opensearch-project/opensearch-js/compare/2.1...HEAD \ No newline at end of file +[Unreleased]: https://github.com/opensearch-project/opensearch-js/compare/2.1...HEAD diff --git a/lib/aws/AwsSigv4Signer.js b/lib/aws/AwsSigv4Signer.js index 4e1e74d43..d46ba351d 100644 --- a/lib/aws/AwsSigv4Signer.js +++ b/lib/aws/AwsSigv4Signer.js @@ -13,6 +13,7 @@ const Connection = require('../Connection'); const Transport = require('../Transport'); const aws4 = require('aws4'); const AwsSigv4SignerError = require('./errors'); +const crypto = require('crypto'); const getAwsSDKCredentialsProvider = async () => { // First try V3 @@ -77,7 +78,12 @@ function AwsSigv4Signer(opts = {}) { request.region = opts.region; request.headers = request.headers || {}; request.headers['host'] = request.hostname; - return aws4.sign(request, credentialsState.credentials); + const signed = aws4.sign(request, credentialsState.credentials); + signed.headers['x-amz-content-sha256'] = crypto + .createHash('sha256') + .update(request.body || '', 'utf8') + .digest('hex'); + return signed; } class AwsSigv4SignerConnection extends Connection { diff --git a/package.json b/package.json index 912a18efd..62cbedb14 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ } }, "homepage": "https://www.opensearch.org/", - "version": "2.1.1", + "version": "2.2.0", "versionCanary": "7.10.0-canary.6", "keywords": [ "opensearch", diff --git a/test/unit/lib/aws/awssigv4signer.test.js b/test/unit/lib/aws/awssigv4signer.test.js index b15fb51b7..7c8636fe3 100644 --- a/test/unit/lib/aws/awssigv4signer.test.js +++ b/test/unit/lib/aws/awssigv4signer.test.js @@ -16,7 +16,7 @@ const { Connection } = require('../../../../index'); const { Client, buildServer } = require('../../../utils'); test('Sign with SigV4', (t) => { - t.plan(3); + t.plan(4); const mockCreds = { accessKeyId: uuidv4(), @@ -50,6 +50,10 @@ test('Sign with SigV4', (t) => { const signedRequest = auth.buildSignedRequestObject(request); t.hasProp(signedRequest.headers, 'X-Amz-Date'); t.hasProp(signedRequest.headers, 'Authorization'); + t.same( + signedRequest.headers['x-amz-content-sha256'], + 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' + ); t.same(signedRequest.service, 'es'); });