From d2df96bbb249d1bd476960c5565ef726c6689666 Mon Sep 17 00:00:00 2001 From: Marcus Young Date: Mon, 25 Sep 2017 14:56:17 -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..2ca3b11 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); return { bulk: function(params, callback) { if (params.body[1].value === '1') {