Skip to content

Commit

Permalink
Merge pull request #63 from janza/master
Browse files Browse the repository at this point in the history
added protocol option
  • Loading branch information
bencevans committed May 7, 2015
2 parents b559924 + 7baf93a commit 1bae6a8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ env:
before_script:
- wget "http://s3.amazonaws.com/influxdb/influxdb_$(echo $INFLUX)_amd64.deb"
- sudo dpkg -i "influxdb_$(echo $INFLUX)_amd64.deb"
- sudo openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj '/C=US/ST=NewYork/L=NYC/O=Influx/CN=*' -keyout /server.pem -out /server.pem >/dev/null 2>&1
- sudo sed -i -r -e "s/^# ssl-cert.*/ssl-cert = \"\/server.pem\"/g" /opt/influxdb/shared/config.toml
- sudo sed -i -r -e 's/^# ssl-port.*/ssl-port = 8084/g' /opt/influxdb/shared/config.toml
- sudo service influxdb start
- sleep 5
script: npm run travis-test
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ var client = influx({
hosts : [
{
host : 'localhost',
port : 8060 //optional. default 8086
port : 8060, //optional. default 8086
protocol : 'http' //optional. default 'http'
}
],
// or single-host configuration
host : 'localhost',
port : 8086, // optional, default 8086
protocol : 'http', // optional, default 'http'
username : 'dbuser',
password : 'f4ncyp4ass',
database : 'my_database'
Expand All @@ -58,6 +60,7 @@ host and disables the failed host for 60 seconds (timeout value is configurable)
| database | database name |
| host | hostname, e.g. 'localhost' |
| port [optional] | influxdb port, default: 8086 |
| protocol [optional] | protocol, default: http |
| hosts [optional] | Array of hosts for cluster configuration, e.g. [ {host: 'localhost', port : 8086},...] Port is optional |
| depreciatedLogging [optional] | logging function for depreciated warnings, defaults to console.log |
| failoverTimeout [optional] | number of ms node-influx will take a host out of the balancing after a request failed, default: 60000 |
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var defaultOptions = {
username : 'root',
password : 'root',
port : 8086,
protocol : 'http',
depreciatedLogging : (process.env.NODE_ENV === undefined || 'development') ? console.log : false,
failoverTimeout : 60000,
requestTimeout : null,
Expand All @@ -28,13 +29,15 @@ var InfluxDB = function(options) {

if ( (!_.isArray(this.options.hosts) || 0 === this.options.hosts.length ) && 'string' === typeof this.options.host)
{
this.request.addHost(this.options.host,this.options.port);
this.request.addHost(this.options.host, this.options.port, this.options.protocol);
}
if (_.isArray(this.options.hosts) && 0 < this.options.hosts.length)
{
var self = this;
_.each(this.options.hosts,function(host){
self.request.addHost(host.host, host.port || self.options.port);
var port = host.port || self.options.port;
var protocol = host.protocol || self.options.protocol;
self.request.addHost(host.host, port, protocol);
});
}

Expand Down
5 changes: 3 additions & 2 deletions lib/InfluxRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ InfluxRequest.prototype.getHostsDisabled = function () {
return this.hostsDisabled;
};

InfluxRequest.prototype.addHost = function (hostname, port) {
InfluxRequest.prototype.addHost = function (hostname, port, protocol) {
this.hostsAvailable.push({
name: hostname,
port: port,
protocol: protocol,
available: true,
timeout: 0
});
Expand Down Expand Up @@ -88,7 +89,7 @@ InfluxRequest.prototype.disableHost = function (host) {

InfluxRequest.prototype.url = function (host, path) {
return url.format({
protocol: 'http:',
protocol: host.protocol,
hostname: host.name,
port: host.port
}) + '/' + path;
Expand Down
36 changes: 35 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,38 @@ describe('Helpers', function () {
{time: 1383934015205, sequence_number: 23168, value: 232}
]);
});
});
});

describe('HTTPS connection', function() {
var client;

var dbName = 'https_db';

describe('connect and create test DB', function () {

before(function() {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; // allow self-signed cert

client = influx({
host: 'localhost',
port: 8084,
protocol: 'https',
username: 'root',
password: 'root',
timePrecision: 'ms'
});
});

it('should create a new database without error', function (done) {
client.createDatabase(dbName, done);
});

it('should throw an error if db already exists', function (done) {
client.createDatabase(dbName, function (err) {
assert(err instanceof Error);
done();
});
});

});
});

0 comments on commit 1bae6a8

Please sign in to comment.