-
-
Save spalger/8cf4977d6ac871a5f1e2 to your computer and use it in GitHub Desktop.
Augment elasticsearch-js's HttpConnector class to implement special Agent config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var elasticsearch = require('elasticsearch'); | |
var CustomHttpConnector = require('./custom_http_connector'); | |
module.exports = new elasticsearch.Client({ | |
connectionClass: CustomHttpConnector | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!