Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for http auth #17

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ exports.handler = function(config, event, context, callback) {
return callback(null, 'Event did not match any mappings.');
}

console.log('Running ' + taskNames.length + ' handlers with config:', config);

_config = JSON.parse(JSON.stringify(config)) // Deep clone object to prevent modifying the real config.httpAuth key
if (_config.elasticsearch.httpAuth) {
_config.elasticsearch.httpAuth = "*****"
}
console.log('Running ' + taskNames.length + ' handlers with _config:', _config);
var tasks = [];
var processor;
_.some(taskNames, function(taskName) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"aws-sdk": "^2.3.18",
"csv-parse": "^1.1.1",
"elasticsearch": "^11.0.1",
"elasticsearch": "^13.3.1",
"http-aws-es": "tphummel/http-aws-es",
"lodash": "^4.13.1"
},
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