joyent/node-triton#154 #108 changes broke triton cloudapi ...

This commit is contained in:
Trent Mick 2016-12-14 11:01:18 -08:00
parent ad7d608011
commit f7bbe5fcff
2 changed files with 31 additions and 20 deletions

View File

@ -7,6 +7,8 @@ Known issues:
## not yet released ## not yet released
- [joyent/node-triton#154] Fix `triton cloudapi ...` after #108 changes.
- **BREAKING CHANGE for module usage of node-triton.** - **BREAKING CHANGE for module usage of node-triton.**
To implement joyent/node-triton#108, the way a TritonApi client is To implement joyent/node-triton#108, the way a TritonApi client is
setup for use has changed from being (unrealistically) sync to async. setup for use has changed from being (unrealistically) sync to async.

View File

@ -11,7 +11,9 @@
*/ */
var http = require('http'); var http = require('http');
var vasync = require('vasync');
var common = require('./common');
var errors = require('./errors'); var errors = require('./errors');
@ -62,27 +64,34 @@ function do_cloudapi(subcmd, opts, args, callback) {
} }
} }
this.tritonapi.cloudapi._request(reqOpts, function (err, req, res, body) { vasync.pipeline({arg: {cli: this}, funcs: [
if (err) { common.cliSetupTritonApi,
callback(err);
return;
}
if (opts.headers || reqOpts.method === 'head') {
console.error('%s/%s %d %s',
req.connection.encrypted ? 'HTTPS' : 'HTTP',
res.httpVersion,
res.statusCode,
http.STATUS_CODES[res.statusCode]);
Object.keys(res.headers).forEach(function (key) {
console.error('%s: %s', key, res.headers[key]);
});
console.error();
}
if (reqOpts.method !== 'head') function callCloudapi(ctx, next) {
console.log(JSON.stringify(body, null, 4)); var cloudapi = ctx.cli.tritonapi.cloudapi;
callback(); cloudapi._request(reqOpts, function (err, req, res, body) {
}); if (err) {
next(err);
return;
}
if (opts.headers || reqOpts.method === 'head') {
console.error('%s/%s %d %s',
req.connection.encrypted ? 'HTTPS' : 'HTTP',
res.httpVersion,
res.statusCode,
http.STATUS_CODES[res.statusCode]);
Object.keys(res.headers).forEach(function (key) {
console.error('%s: %s', key, res.headers[key]);
});
console.error();
}
if (reqOpts.method !== 'head')
console.log(JSON.stringify(body, null, 4));
next();
});
}
]}, callback);
} }
do_cloudapi.options = [ do_cloudapi.options = [