From 02886c6be9ec9853fb2eddb2ee2534913e55fb5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Jan=C5=BEi=C4=87?= Date: Tue, 5 May 2015 20:03:01 +0200 Subject: [PATCH 1/6] add protocol option (enables https support) --- index.js | 7 +++++-- lib/InfluxRequest.js | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5de52fdc..befca7c0 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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); }); } diff --git a/lib/InfluxRequest.js b/lib/InfluxRequest.js index 5b2a1c97..18b9104a 100644 --- a/lib/InfluxRequest.js +++ b/lib/InfluxRequest.js @@ -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 }); @@ -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; From d6c82daf26db8f86afe5018f7d8ac77ae6df9240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Jan=C5=BEi=C4=87?= Date: Tue, 5 May 2015 20:09:21 +0200 Subject: [PATCH 2/6] updated README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d0b76fe9..68a328e8 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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 | From b98116e3b1bf7e94b69a9f2d2dace9f3e91a7d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Jan=C5=BEi=C4=87?= Date: Tue, 5 May 2015 21:15:01 +0200 Subject: [PATCH 3/6] added https connection test --- test.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test.js b/test.js index d5272542..956978fc 100644 --- a/test.js +++ b/test.js @@ -430,4 +430,38 @@ describe('Helpers', function () { {time: 1383934015205, sequence_number: 23168, value: 232} ]); }); -}); \ No newline at end of file +}); + +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(); + }); + }); + + }); +}); From fd35765f71e5022b22e101e4e1a9d0d3fe7af189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Jan=C5=BEi=C4=87?= Date: Wed, 6 May 2015 18:32:50 +0200 Subject: [PATCH 4/6] updated travis.yml to enable ssl on port 8084 --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index b72df920..cc667da7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" + - 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 + - sed -i -r -e 's/^# ssl-cert/ssl-cert = "\/server.pem" #/g' /opt/influxdb/shared/config.toml + - 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 From 41343ee3fe8a611211dc994008f791ca02978193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Jan=C5=BEi=C4=87?= Date: Wed, 6 May 2015 19:07:07 +0200 Subject: [PATCH 5/6] use sudo for cert and config generation --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index cc667da7..4311d035 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,9 @@ env: before_script: - wget "http://s3.amazonaws.com/influxdb/influxdb_$(echo $INFLUX)_amd64.deb" - sudo dpkg -i "influxdb_$(echo $INFLUX)_amd64.deb" - - 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 - - sed -i -r -e 's/^# ssl-cert/ssl-cert = "\/server.pem" #/g' /opt/influxdb/shared/config.toml - - sed -i -r -e 's/^# ssl-port/ssl-port = 8084 #/g' /opt/influxdb/shared/config.toml + - 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 From 7baf93a68738a1c031f944b7161ee58bb600c539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Jan=C5=BEi=C4=87?= Date: Wed, 6 May 2015 21:25:05 +0200 Subject: [PATCH 6/6] fixed yml parsing ' #' as comment --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4311d035..374e8235 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,8 @@ 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 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