Skip to content

Instantly share code, notes, and snippets.

@spalger
Last active August 29, 2015 13:57
Show Gist options
  • Save spalger/8cf4977d6ac871a5f1e2 to your computer and use it in GitHub Desktop.
Save spalger/8cf4977d6ac871a5f1e2 to your computer and use it in GitHub Desktop.
Augment elasticsearch-js's HttpConnector class to implement special Agent config
var elasticsearch = require('elasticsearch');
var CustomHttpConnector = require('./custom_http_connector');
module.exports = new elasticsearch.Client({
connectionClass: CustomHttpConnector
});
module.exports = CustomHttpConnector;
var EsHttpConnector = require('elasticsearch/src/lib/connectors/http');
var inherits = require('util').inherits;
var security = require('./security');
function CustomHttpConnector(host, config) {
EsHttpConnector.call(this, host, config);
}
inherits(CustomHttpConnector, EsHttpConnector);
// override the makeAgentParams method to modify the values used from config.
CustomHttpConnector.prototype.makeAgentConfig = function (config) {
return {
// standard params
maxSockets: config.maxSockets,
minSockets: config.minSockets
// custom params
pfx: security.pfx.elasticsearch
};
}
@brettwsnare
Copy link

My ES instance is sitting behind a proxy which requires me to present my server cert. Can I use this same technique to set the following:

key: Private key to use for SSL.
passphrase: A string of passphrase for the private key or pfx.
cert: Public x509 certificate to use.
ca: An authority certificate or array of authority certificates to check the remote host against.

UPDATE: Yes, I was able to send all of my Node.js HTTPS config options using this technique(https://gist.github.com/spenceralger/8cf4977d6ac871a5f1e2/e200e07a8e55c3068b98a138c0ad8deaff12c529). Thank you for posting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment