Skip to content

Commit

Permalink
Added Support for AOSS (#366)
Browse files Browse the repository at this point in the history
* Added Support for AOSS

Signed-off-by: Theo Truong <theotr@amazon.com>
  • Loading branch information
nhtruong authored Jan 23, 2023
1 parent 8ff2fd4 commit 52010ba
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ opensearch*
# documentation
docs/

# temporary
tmp/

test/benchmarks/macro/fixtures/*

*-junit.xml
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
[Unreleased]: https://github.com/opensearch-project/opensearch-js/compare/2.1...HEAD
8 changes: 7 additions & 1 deletion lib/aws/AwsSigv4Signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion test/unit/lib/aws/awssigv4signer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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');
});

Expand Down

0 comments on commit 52010ba

Please sign in to comment.