fullscale / elastic.js

A JavaScript implementation of the elasticsearch Query DSL
http://docs.fullscale.co/elasticjs/
MIT License
654 stars 163 forks source link

Add support for basic authentication #18

Closed pulkitsinghal closed 11 years ago

pulkitsinghal commented 11 years ago

1) A lot of Elasticsearch as a service providers now use es-jetty or nginx to provide basic authN ... so it would be pretty cool if we could control specify username password for basic authN in the node.js for elastic.js client. http://stackoverflow.com/questions/16137919/how-to-specify-credentials-username-password-for-elasticjs-client

2) I don't see a way to specify https either, so I'm guessing that the ability to specify that will have to be exposed as well?

mattweber commented 11 years ago

Note https is supported in all clients except the node client. Https is a separate module in nodejs so there will need to be some extra work required to select between using the http and https module. I opened #19 to track this.

svperfecta commented 11 years ago

Hi guys - I thought I'd weigh in on this too, since I'm having a similar issue. Specifically, I'm deploying a node.js app to Heroku and decided to try out elastic.js. Heroku has several elasticsearch add ons, and the one we're using is Bonsai Search. They provide set an environment variable in production similar to:

http://laskdfjl:lkjlkj@apricot-544446488.us-east-1.bonsai.io

I see we're using Node's built in HTTP library, and that we're allowing two configuration options (host & port) here:

https://github.com/fullscale/elastic.js/blob/master/src/clients/elastic-node-client.js#L43

I'd like to recommend that we support a more generic configuration option in the form of a URL. We can then parse it using url.parse to get the options needed to initialize the http.request. This would mirror the Elastic.js jQuery library's api, as well as allow us to solve the HTTP / HTTPS issues as well.

mattweber commented 11 years ago

See 349f5724.

I added support for setting any request options available to the http or https request.

ejs.client = nc.NodeClient().option('auth', 'myuser:pass')

Let me know if you run into any issues.