Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-aws-es

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-aws-es - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

17

CHANGELOG.md

@@ -0,1 +1,9 @@

### 3.1.1
* Fix DELETEs with request body e.g. `clearScroll()`. [#19][19] [#41][41]
* Reduce dependency footprint. [#40][40]
### 3.1.0
* Allow aws config to be set per instance. [#37][37]
* Add config for setting httpOptions on aws-sdk's requests. [#8][8]
### 3.0.0

@@ -5,3 +13,3 @@ * Support down to node 4.x.

### 2.0.5
* Catch aws credential errors. #35
* Catch aws credential errors. [#35][35]
* Add source maps.

@@ -15,1 +23,8 @@

* Added `credentials` option for passing in an AWS `Credentials` object.
[41]: https://github.com/TheDeveloper/http-aws-es/pull/41
[19]: https://github.com/TheDeveloper/http-aws-es/issues/19
[40]: https://github.com/TheDeveloper/http-aws-es/pull/40
[37]: https://github.com/TheDeveloper/http-aws-es/issues/37
[8]: https://github.com/TheDeveloper/http-aws-es/pull/8
[35]: https://github.com/TheDeveloper/http-aws-es/issues/35

159

connector.js

@@ -0,1 +1,3 @@

'use strict';
/**

@@ -12,6 +14,5 @@ * A connection handler for Amazon ES.

import AWS from 'aws-sdk';
import HttpConnector from 'elasticsearch/src/lib/connectors/http'
import _ from 'elasticsearch/src/lib/utils';
import zlib from 'zlib';
const AWS = require('aws-sdk');
const HttpConnector = require('elasticsearch/src/lib/connectors/http');
const zlib = require('zlib');

@@ -21,3 +22,5 @@ class HttpAmazonESConnector extends HttpConnector {

super(host, config);
const { protocol, port } = host;
const protocol = host.protocol;
const port = host.port;
const endpoint = new AWS.Endpoint(host.host);

@@ -28,102 +31,84 @@

this.AWS = AWS;
this.awsConfig = config.awsConfig || AWS.config;
this.endpoint = endpoint;
this.httpOptions = config.httpOptions || this.awsConfig.httpOptions;
this.httpClient = new AWS.NodeHttpClient();
}
async request(params, cb) {
let incoming;
let timeoutId;
let request;
request(params, cb) {
const reqParams = this.makeReqParams(params);
let req;
let status = 0;
let headers = {};
let log = this.log;
let response;
const AWS = this.AWS;
let incoming;
let cancelled;
let reqParams = this.makeReqParams(params);
const cancel = () => {
cancelled = true;
req && req.abort();
};
// general clean-up procedure to run after the request
// completes, has an error, or is aborted.
let cleanUp = _.bind(function (err) {
clearTimeout(timeoutId);
const cleanUp = (err) => {
req && req.removeAllListeners();
incoming && incoming.removeAllListeners();
if ((err instanceof Error) === false) {
err = void 0;
}
log.trace(params.method, reqParams, params.body, response, status);
if (err) {
this.log.trace(params.method, reqParams, params.body, response, status);
if (err instanceof Error) {
cb(err);
} else {
cb(err, response, status, headers);
cb(null, response, status, headers);
}
}, this);
};
request = new AWS.HttpRequest(this.endpoint);
// copy across params
for (let p in reqParams) {
request[p] = reqParams[p];
}
request.region = this.awsConfig.region;
if (params.body) request.body = params.body;
if (!request.headers) request.headers = {};
request.headers['presigned-expires'] = false;
request.headers['Host'] = this.endpoint.host;
// load creds
let CREDS;
try {
CREDS = await this.getAWSCredentials();
this.getAWSCredentials()
.catch(e => {
if (e && e.message) e.message = `AWS Credentials error: ${e.message}`;
throw e;
})
.then(creds => {
if (cancelled) {
return;
}
// Sign the request (Sigv4)
let signer = new AWS.Signers.V4(request, 'es');
signer.addAuthorization(CREDS, new Date());
} catch (e) {
if (e && e.message) e.message = `AWS Credentials error: ${e.message}`;
cleanUp(e);
return () => {};
}
const request = this.createRequest(params, reqParams);
let send = new AWS.NodeHttpClient();
req = send.handleRequest(request, this.httpOptions, function (_incoming) {
incoming = _incoming;
status = incoming.statusCode;
headers = incoming.headers;
response = '';
// Sign the request (Sigv4)
this.signRequest(request, creds);
let encoding = (headers['content-encoding'] || '').toLowerCase();
if (encoding === 'gzip' || encoding === 'deflate') {
incoming = incoming.pipe(zlib.createUnzip());
}
req = this.httpClient.handleRequest(request, this.httpOptions, function (_incoming) {
incoming = _incoming;
status = incoming.statusCode;
headers = incoming.headers;
response = '';
incoming.setEncoding('utf8');
incoming.on('data', function (d) {
response += d;
});
let encoding = (headers['content-encoding'] || '').toLowerCase();
if (encoding === 'gzip' || encoding === 'deflate') {
incoming = incoming.pipe(zlib.createUnzip());
}
incoming.on('error', cleanUp);
incoming.on('end', cleanUp);
}, cleanUp);
incoming.setEncoding('utf8');
incoming.on('data', function (d) {
response += d;
});
req.on('error', cleanUp);
incoming.on('error', cleanUp);
incoming.on('end', cleanUp);
}, cleanUp);
req.setNoDelay(true);
req.setSocketKeepAlive(true);
req.setNoDelay(true);
req.setSocketKeepAlive(true);
})
.catch(cleanUp);
return function () {
req.abort();
};
return cancel;
}
getAWSCredentials() {
const { awsConfig } = this;
return new Promise((resolve, reject) => {
awsConfig.getCredentials((err, creds) => {
this.awsConfig.getCredentials((err, creds) => {
if (err) return reject(err);

@@ -134,4 +119,32 @@ return resolve(creds);

}
createRequest(params, reqParams) {
const request = new AWS.HttpRequest(this.endpoint);
// copy across params
Object.assign(request, reqParams);
request.region = this.awsConfig.region;
if (!request.headers) request.headers = {};
let body = params.body;
if (body) {
let contentLength = Buffer.isBuffer(body)
? body.byteLength()
: body.length;
request.headers['Content-Length'] = contentLength;
request.body = body;
}
request.headers['presigned-expires'] = false;
request.headers['Host'] = this.endpoint.host;
return request;
}
signRequest(request, creds) {
const signer = new AWS.Signers.V4(request, 'es');
signer.addAuthorization(creds, new Date());
}
}
module.exports = HttpAmazonESConnector;
{
"name": "http-aws-es",
"version": "3.1.0",
"version": "3.1.1",
"description": "Use the elasticsearch-js client with Amazon ES",

@@ -19,24 +19,22 @@ "repository": "https://github.com/TheDeveloper/http-aws-es",

],
"main": "dist/connector.js",
"dependencies": {
"babel-runtime": "^6.26.0"
},
"main": "connector.js",
"peerDependencies": {
"aws-sdk": "^2.83.0",
"aws-sdk": "^2.138.0",
"elasticsearch": "^13.2.0"
},
"devDependencies": {
"aws-sdk": "^2.83.0",
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"elasticsearch": "^13.2.0",
"eslint": "^4.2.0",
"minimist": "^1.2.0"
"aws-sdk": "^2.138.0",
"chai": "^4.1.2",
"elasticsearch": "^13.3.1",
"eslint": "^4.9.0",
"minimist": "^1.2.0",
"mocha": "^4.0.1",
"nyc": "^11.2.1",
"sinon": "^4.0.0"
},
"scripts": {
"prepublish": "npm run build",
"build": "rm -rf dist; mkdir dist; babel ./connector.js -o dist/connector.js",
"test": "node test/local"
"test": "nyc --all mocha",
"integration-test": "mocha test/integration",
"posttest": "npm run lint",
"lint": "eslint ."
},

@@ -43,0 +41,0 @@ "author": "Geoff Wagstaff <geoff@gosquared.com>",

# Connection handler for Amazon ES [<img title="Version" src="https://img.shields.io/npm/v/http-aws-es.svg?style=flat-square" />](https://www.npmjs.org/package/http-aws-es)
Makes elasticsearch-js compatible with Amazon ES. It uses the aws-sdk to make signed requests to an Amazon ES endpoint.
Makes [elasticsearch-js](https://github.com/elastic/elasticsearch-js) compatible with Amazon ES. It uses the aws-sdk to make signed requests to an Amazon ES endpoint.

@@ -4,0 +4,0 @@ ## Installation

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc