From 2dddfe0a4b6624cc8921b04bac91948de2b0b2ec Mon Sep 17 00:00:00 2001 From: Marcus Young Date: Tue, 26 Sep 2017 11:38:57 -0500 Subject: [PATCH] Add support for HTTP auth --- .gitignore | 1 + handlers/shipElasticsearch.js | 4 ++++ test/shipElasticsearch.spec.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/.gitignore b/.gitignore index ccc2930..014c77d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /coverage /node_modules +/package-lock.json diff --git a/handlers/shipElasticsearch.js b/handlers/shipElasticsearch.js index 0365907..eaf4e77 100644 --- a/handlers/shipElasticsearch.js +++ b/handlers/shipElasticsearch.js @@ -7,6 +7,10 @@ exports.process = function(config) { host: config.elasticsearch.host }; + if (config.elasticsearch.httpAuth) { + esConfig.httpAuth = config.elasticsearch.httpAuth; + } + if (config.elasticsearch.useAWS) { esConfig.connectionClass = require('http-aws-es'); esConfig.amazonES = { diff --git a/test/shipElasticsearch.spec.js b/test/shipElasticsearch.spec.js index e7c47fe..ec9da61 100644 --- a/test/shipElasticsearch.spec.js +++ b/test/shipElasticsearch.spec.js @@ -12,6 +12,33 @@ describe('handler/shipElasticsearch.js', function() { handler = require('../handlers/shipElasticsearch'); }); + it('should allow http auth', + function(done) { + var config = { + elasticsearch: { + httpAuth: 'asdf:wut', + index: 'index', + type: 'type' + }, + data: [ + { + value: '1' + }, + { + value: '2' + } + ], + test: 'test' + }; + var es = require('elasticsearch'); + es.Client = function(config) { + assert.strictEqual(config.httpAuth, 'asdf:wut', + 'httpAuth param provided'); + done(); + }; + handler.process(config); + }); + it('should split data by the maxChunkSize', function(done) { var passVal1 = false; @@ -19,6 +46,7 @@ describe('handler/shipElasticsearch.js', function() { var es = require('elasticsearch'); es.Client = function(config) { assert.strictEqual(config.host, 'http://mock', 'host param provided'); + assert.strictEqual(config.httpAuth, undefined, 'httpAuth param not provided'); return { bulk: function(params, callback) { if (params.body[1].value === '1') {