From f7bbe5fcff004f15123675469f4c08ce7733c26f Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 14 Dec 2016 11:01:18 -0800 Subject: [PATCH] joyent/node-triton#154 #108 changes broke `triton cloudapi ...` --- CHANGES.md | 2 ++ lib/do_cloudapi.js | 49 +++++++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3aa6258..7003df8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ Known issues: ## not yet released +- [joyent/node-triton#154] Fix `triton cloudapi ...` after #108 changes. + - **BREAKING CHANGE for module usage of node-triton.** To implement joyent/node-triton#108, the way a TritonApi client is setup for use has changed from being (unrealistically) sync to async. diff --git a/lib/do_cloudapi.js b/lib/do_cloudapi.js index e0ed906..201f3fd 100644 --- a/lib/do_cloudapi.js +++ b/lib/do_cloudapi.js @@ -11,7 +11,9 @@ */ var http = require('http'); +var vasync = require('vasync'); +var common = require('./common'); 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) { - if (err) { - 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(); - } + vasync.pipeline({arg: {cli: this}, funcs: [ + common.cliSetupTritonApi, - if (reqOpts.method !== 'head') - console.log(JSON.stringify(body, null, 4)); - callback(); - }); + function callCloudapi(ctx, next) { + var cloudapi = ctx.cli.tritonapi.cloudapi; + 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 = [