Skip to content

Commit

Permalink
Fix serverless signing with body
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
  • Loading branch information
harshavamsi committed Jan 20, 2023
1 parent 72c0f1a commit 06ecee3
Show file tree
Hide file tree
Showing 4 changed files with 1,218 additions and 992 deletions.
13 changes: 12 additions & 1 deletion lib/aws/AwsSigv4Signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
const Connection = require('../Connection');
const Transport = require('../Transport');
const aws4 = require('aws4');
const crypto = require('crypto');
const AwsSigv4SignerError = require('./errors');

const getAwsSDKCredentialsProvider = async () => {
Expand Down Expand Up @@ -77,13 +78,23 @@ function AwsSigv4Signer(opts = {}) {
request.region = opts.region;
request.headers = request.headers || {};
request.headers['host'] = request.hostname;
request.headers['X-Amz-Content-Sha256'] = hash(request.body || '', 'hex');
request.extraHeadersToIgnore = {
'content-length': true,
};
return aws4.sign(request, credentialsState.credentials);
}

function hash(string, encoding) {
return crypto.createHash('sha256').update(string, 'utf8').digest(encoding);
}

class AwsSigv4SignerConnection extends Connection {
buildRequestObject(params) {
const request = super.buildRequestObject(params);
return buildSignedRequestObject(request);
let req = buildSignedRequestObject(request);
console.log(req);
return req;
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/aws/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { OpenSearchClientError } from '../errors';
interface AwsSigv4SignerOptions {
getCredentials?: () => Promise<Credentials>;
region: string;
service: string;
}

interface AwsSigv4SignerResponse {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"xmlbuilder2": "^3.0.2"
},
"dependencies": {
"aws4": "^1.11.0",
"aws4": "^1.12.0",
"debug": "^4.3.1",
"hpagent": "^0.1.1",
"ms": "^2.1.3",
Expand Down
Loading

0 comments on commit 06ecee3

Please sign in to comment.