From 2fc927d7b409ad7e3fef19c13aa73ab358ab14e3 Mon Sep 17 00:00:00 2001 From: Rajit Singh Date: Tue, 25 Nov 2014 14:31:12 +0100 Subject: [PATCH 1/3] If POST, then use curl's -d for params --- lib/cloudcontrol.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/cloudcontrol.js b/lib/cloudcontrol.js index 64f03d5..2c628c9 100644 --- a/lib/cloudcontrol.js +++ b/lib/cloudcontrol.js @@ -150,12 +150,18 @@ Cloudcontrol.prototype.curl = function curl(options, cb) { }) url = self.protocol + '://' + self.host + options.path - if (options.params) url += '?' - if (typeof options.params === 'string') url += options.params - if (typeof options.params === 'object') Object.keys(options.params).forEach(function(key) { - url += key + '=' + escape(options.params[key]) - }) + if (options.params && options.method === 'POST') { + var curlified = Object.keys(options.params).map(function (key) { return '-d ' + key + '=' + options.params[key]; }); + cmd += ' ' + curlified; + } else if (options.params) { + if (options.params) url += '?' + + if (typeof options.params === 'string') url += options.params + if (typeof options.params === 'object') Object.keys(options.params).forEach(function(key) { + url += key + '=' + escape(options.params[key]) + }) + } cmd += ' "' + url + '"' exec(cmd, function(err, result) { cb(err, result) From 2fb537432b4532a7e60bc17145a77f99a4cf634e Mon Sep 17 00:00:00 2001 From: Rajit Singh Date: Wed, 26 Nov 2014 09:06:41 +0100 Subject: [PATCH 2/3] Join params once processed into curl args --- lib/cloudcontrol.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cloudcontrol.js b/lib/cloudcontrol.js index 2c628c9..18c1daf 100644 --- a/lib/cloudcontrol.js +++ b/lib/cloudcontrol.js @@ -153,7 +153,7 @@ Cloudcontrol.prototype.curl = function curl(options, cb) { if (options.params && options.method === 'POST') { var curlified = Object.keys(options.params).map(function (key) { return '-d ' + key + '=' + options.params[key]; }); - cmd += ' ' + curlified; + cmd += ' ' + curlified.join(' '); } else if (options.params) { if (options.params) url += '?' From 313b137089c004142508e4a2e2a9642877fe1358 Mon Sep 17 00:00:00 2001 From: Markus Horn Date: Fri, 27 Feb 2015 12:54:49 +0100 Subject: [PATCH 3/3] PROD-539: node-cloudcontrol fork does not handle outdated tokens - try reauthentication if cloud control responses with "Unauthorized" --- lib/cloudcontrol.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cloudcontrol.js b/lib/cloudcontrol.js index 18c1daf..6016f06 100644 --- a/lib/cloudcontrol.js +++ b/lib/cloudcontrol.js @@ -192,7 +192,7 @@ Cloudcontrol.prototype.request = function request(options, cb) { try { result = JSON.parse(result) } catch(e) { - if (result === "Authorization Required") { + if (result === "Authorization Required" || result === "Unauthorized") { self.retries++ if (self.retries < 3) { // try to reauthenticate