Skip to content

Commit

Permalink
Add support for HTTP auth
Browse files Browse the repository at this point in the history
  • Loading branch information
myoung34 committed Sep 26, 2017
1 parent 729f9ba commit 2dddfe0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/coverage
/node_modules
/package-lock.json
4 changes: 4 additions & 0 deletions handlers/shipElasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
28 changes: 28 additions & 0 deletions test/shipElasticsearch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,41 @@ 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;
var passVal2 = false;
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') {
Expand Down

0 comments on commit 2dddfe0

Please sign in to comment.