Comparing version 0.1.1 to 0.1.2
@@ -6,6 +6,6 @@ var http = require('http'); | ||
function request(method, host, port, isSecure, path, params, token, callback) { | ||
function request(method, host, port, isSecure, path, params, options, callback) { | ||
var payload; | ||
var headers = {}; | ||
if (method !== 'DELETE') { | ||
if (method !== 'DELETE') { | ||
headers["accept"] = "application/json"; | ||
@@ -15,9 +15,13 @@ headers["content-type"] = "application/json"; | ||
// Odd - CloudController delete seems to require that content lenght be set.. | ||
headers["content-length"] = 0; | ||
headers["content-length"] = 0; | ||
} | ||
if(token != undefined) { | ||
headers['AUTHORIZATION'] = token; | ||
if(options.token != undefined) { | ||
headers['AUTHORIZATION'] = options.token; | ||
} | ||
if(options.proxyUser != undefined){ | ||
headers['PROXY-USER'] = options.proxyUser; | ||
} | ||
if (params != undefined){ | ||
@@ -28,3 +32,3 @@ payload = JSON.stringify(params); | ||
var options = { | ||
options = { | ||
host: host, | ||
@@ -45,3 +49,3 @@ port: port, | ||
res.on('end', function() { | ||
res.on('end', function() { | ||
// TODO - improve error handling here.. | ||
@@ -54,3 +58,3 @@ var error = { | ||
path: path, | ||
params: params, | ||
params: params, | ||
headers: headers | ||
@@ -62,3 +66,3 @@ }; | ||
return callback(undefined, data); | ||
}); | ||
}); | ||
}); | ||
@@ -78,3 +82,3 @@ | ||
// Uploads zipfile to CF | ||
function upload(host, port, isSecure, token, file, path, resources, callback) { | ||
function upload(host, port, isSecure, options, file, path, resources, callback) { | ||
@@ -96,3 +100,3 @@ var boundary = Math.random(); | ||
post_data.push(new Buffer("\r\n--" + boundary + "--"), 'ascii'); | ||
doUpload(host, port, isSecure, token, path, post_data, boundary, callback); | ||
doUpload(host, port, isSecure, options, path, post_data, boundary, callback); | ||
}); | ||
@@ -115,3 +119,3 @@ }; | ||
function doUpload(host, port, isSecure, token, path, post_data, boundary, callback) { | ||
function doUpload(host, port, isSecure, options, path, post_data, boundary, callback) { | ||
var length = 0; | ||
@@ -123,3 +127,18 @@ | ||
var options = { | ||
var headers = { | ||
'Content-Type' : 'multipart/form-data; boundary=' + boundary, | ||
'Content-Length' : length, | ||
'Accept-Encoding' : 'gzip, deflate', | ||
'Accept' : '*/*; q=0.5, application/xml' | ||
}; | ||
if(options.token != undefined) { | ||
headers['AUTHORIZATION'] = options.token; | ||
} | ||
if(options.proxyUser != undefined){ | ||
headers['PROXY-USER'] = options.proxyUser; | ||
} | ||
options = { | ||
host: host, | ||
@@ -129,9 +148,3 @@ port: port, | ||
method: 'POST', | ||
headers : { | ||
'Content-Type' : 'multipart/form-data; boundary=' + boundary, | ||
'Content-Length' : length, | ||
'AUTHORIZATION' : token, | ||
'Accept-Encoding' : 'gzip, deflate', | ||
'Accept' : '*/*; q=0.5, application/xml' | ||
} | ||
headers: headers | ||
}; | ||
@@ -141,4 +154,4 @@ | ||
var req = protocol.request(options, function(res){ | ||
// TODO - not sure what POST /apps/<app>/application returns here exactly (some binary..) | ||
// but seems safe to ignore if the call is successful.. | ||
// TODO - not sure what POST /apps/<app>/application returns here exactly (some binary..) | ||
// but seems safe to ignore if the call is successful.. | ||
res.setEncoding('utf8'); | ||
@@ -151,3 +164,3 @@ var data = ''; | ||
res.on('end', function(){ | ||
return callback(); | ||
return callback(); | ||
}); | ||
@@ -154,0 +167,0 @@ |
@@ -57,3 +57,3 @@ var util = require('util'); | ||
self.start(name, callback); | ||
}); | ||
}); | ||
}; | ||
@@ -74,3 +74,3 @@ | ||
var self = this; | ||
this.systemServices(function(err, services){ | ||
this.systemServices(function(err, services){ | ||
var vendorService = vmcutils.vendorService(services, vendor); | ||
@@ -86,12 +86,12 @@ if (vendorService == undefined) return callback(new Error('System Service not found: ' + vendor)); | ||
var self = this; | ||
this.provisionedServices(function(err, services){ | ||
this.provisionedServices(function(err, services){ | ||
var serviceNames = []; | ||
for (var i=0; i<services.length; i++) { | ||
var serv = services[i]; | ||
var serv = services[i]; | ||
serviceNames.push(serv.name); | ||
} | ||
} | ||
if(serviceNames.indexOf(service) == -1) return callback(new Error('Service not found: ' + service)); | ||
self.del('/services/' + service, callback); | ||
self.del('/services/' + service, callback); | ||
}); | ||
@@ -133,3 +133,3 @@ }; | ||
}, | ||
uris:[name + self.rootTarget] | ||
uris:[name + self.rootTarget] | ||
}; | ||
@@ -155,3 +155,3 @@ | ||
self.restart(name, callback); | ||
}); | ||
}); | ||
}); | ||
@@ -175,3 +175,3 @@ }; | ||
var path = '/apps/' + name; | ||
self.del(path, callback); | ||
self.del(path, callback); | ||
}); | ||
@@ -195,3 +195,3 @@ }); | ||
var env = variable + "=" + value; | ||
app.env.push(env); | ||
app.env.push(env); | ||
@@ -220,3 +220,3 @@ self.updateApp(name, app, function(err, data){ | ||
var nv = nvp.split('='); | ||
if(nv[0] !== variable) newEnv.push(nvp); | ||
if(nv[0] !== variable) newEnv.push(nvp); | ||
} | ||
@@ -233,3 +233,3 @@ | ||
}); | ||
}); | ||
}); | ||
}; | ||
@@ -239,3 +239,3 @@ | ||
VMC.prototype.login = function(callback) { | ||
var self = this; | ||
var self = this; | ||
this.token = undefined; | ||
@@ -263,3 +263,3 @@ var path = '/users/' + this.user + '/tokens'; | ||
this.isSecure = uri.protocol === 'https'; | ||
if (uri.port == undefined) { | ||
@@ -276,19 +276,20 @@ this.port = uri.protocol === 'https' ? 443 : 80; | ||
this.pwd = pwd; | ||
this.token = undefined; | ||
this.token = undefined; | ||
this.proxyUser = undefined; | ||
this.get = function(path, callback) { | ||
return comms.request('GET', this.host, this.port, this.isSecure, path, undefined, this.token, callback); | ||
return comms.request('GET', this.host, this.port, this.isSecure, path, undefined, { token: this.token, proxyUser: this.proxyUser }, callback); | ||
}; | ||
this.post = function(path, params, callback) { | ||
return comms.request('POST', this.host, this.port, this.isSecure, path, params, this.token, callback); | ||
return comms.request('POST', this.host, this.port, this.isSecure, path, params, { token: this.token, proxyUser: this.proxyUser }, callback); | ||
}; | ||
this.put = function(path, params, callback) { | ||
return comms.request('PUT', this.host, this.port, this.isSecure, path, params, this.token, callback); | ||
return comms.request('PUT', this.host, this.port, this.isSecure, path, params, { token: this.token, proxyUser: this.proxyUser }, callback); | ||
}; | ||
this.del = function(path, callback) { | ||
return comms.request('DELETE', this.host, this.port, this.isSecure, path, undefined, this.token, callback); | ||
return comms.request('DELETE', this.host, this.port, this.isSecure, path, undefined, { token: this.token, proxyUser: this.proxyUser }, callback); | ||
}; | ||
this.uploadZip = function(zipFile, path, resources, callback) { | ||
return comms.upload(this.host, this.port, this.isSecure, this.token, zipFile, path, resources, callback); | ||
return comms.upload(this.host, this.port, this.isSecure, { token: this.token, proxyUser: this.proxyUser }, zipFile, path, resources, callback); | ||
}; | ||
@@ -295,0 +296,0 @@ |
{ | ||
"name": "vmcjs", | ||
"description": "Node.js VMC library", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Damian Beresford <Damian.Beresford@feedhenry.com>", | ||
@@ -6,0 +6,0 @@ "repository" : { "type" : "git", |
15076
435