TRITON-524 'triton inst get' should support '--credentials'

Reviewed by: Marsell Kukuljevic <marsell@joyent.com>
Approved by: Marsell Kukuljevic <marsell@joyent.com>
This commit is contained in:
Trent Mick 2018-06-19 14:42:10 -07:00
parent 5734123e75
commit f100c4dbb5
4 changed files with 35 additions and 10 deletions

View File

@ -6,6 +6,9 @@ Known issues:
## not yet released ## not yet released
- [TRITON-524] Add `triton inst get --credentials ...` option to match
`triton inst list --credentials ...` for including generated credentials
in instance metadata.
- [joyent/node-triton#245] `triton profile` now generates fresh new keys during - [joyent/node-triton#245] `triton profile` now generates fresh new keys during
Docker setup and signs them with an account key, rather than copying (and Docker setup and signs them with an account key, rather than copying (and
decrypting) the account key itself. This makes using Docker simpler with keys decrypting) the account key itself. This makes using Docker simpler with keys

View File

@ -872,13 +872,12 @@ CloudApi.prototype.getPackage = function getPackage(opts, cb) {
/** /**
* Get a machine by id. * Get a machine by id.
* *
* XXX add getCredentials equivalent
* XXX cloudapi docs don't doc the credentials=true option
*
* For backwards compat, calling with `getMachine(id, cb)` is allowed. * For backwards compat, calling with `getMachine(id, cb)` is allowed.
* *
* @param {Object} opts * @param {Object} opts
* - id {UUID} Required. The machine id. * - {UUID} id - Required. The machine id.
* - {Boolean} credentials - Optional. Set to true to include generated
* credentials for this machine in `machine.metadata.credentials`.
* @param {Function} cb of the form `function (err, machine, res)` * @param {Function} cb of the form `function (err, machine, res)`
*/ */
CloudApi.prototype.getMachine = function getMachine(opts, cb) { CloudApi.prototype.getMachine = function getMachine(opts, cb) {
@ -887,9 +886,14 @@ CloudApi.prototype.getMachine = function getMachine(opts, cb) {
} }
assert.object(opts, 'opts'); assert.object(opts, 'opts');
assert.uuid(opts.id, 'opts.id'); assert.uuid(opts.id, 'opts.id');
assert.optionalBool(opts.credentials, 'opts.credentials');
var endpoint = format('/%s/machines/%s', this.account, opts.id); var query = {};
this._request(endpoint, function (err, req, res, body) { if (opts.credentials) {
query.credentials = 'true';
}
var p = this._path(format('/%s/machines/%s', this.account, opts.id), query);
this._request(p, function (err, req, res, body) {
cb(err, body, res); cb(err, body, res);
}); });
}; };

View File

@ -25,7 +25,10 @@ function do_get(subcmd, opts, args, cb) {
cb(setupErr); cb(setupErr);
return; return;
} }
tritonapi.getInstance(args[0], function (err, inst) { tritonapi.getInstance({
id: args[0],
credentials: opts.credentials
}, function onInst(err, inst) {
if (inst) { if (inst) {
if (opts.json) { if (opts.json) {
console.log(JSON.stringify(inst)); console.log(JSON.stringify(inst));
@ -44,6 +47,13 @@ do_get.options = [
type: 'bool', type: 'bool',
help: 'Show this help.' help: 'Show this help.'
}, },
{
names: ['credentials'],
type: 'bool',
help: 'Include generated credentials, in the "metadata.credentials" ' +
'field, if any. Typically used with "-j", though one can show ' +
'values with "-o metadata.credentials".'
},
{ {
names: ['json', 'j'], names: ['json', 'j'],
type: 'bool', type: 'bool',
@ -58,7 +68,6 @@ do_get.help = [
'{{usage}}', '{{usage}}',
'', '',
'{{options}}', '{{options}}',
'',
'Where "INST" is an instance name, id, or short id.', 'Where "INST" is an instance name, id, or short id.',
'', '',
'A *deleted* instance may still respond with the instance object. In that', 'A *deleted* instance may still respond with the instance object. In that',

View File

@ -1123,6 +1123,8 @@ TritonApi.prototype.updateNetworkIp = function updateNetworkIp(opts, cb) {
* - {Array} fields: Optional. An array of instance field names that are * - {Array} fields: Optional. An array of instance field names that are
* wanted by the caller. This *can* allow the implementation to avoid * wanted by the caller. This *can* allow the implementation to avoid
* extra API calls. E.g. `['id', 'name']`. * extra API calls. E.g. `['id', 'name']`.
* - {Boolean} credentials: Optional. Set to true to include generated
* credentials for this instance in `inst.metadata.credentials`.
* @param {Function} cb `function (err, inst, res)` * @param {Function} cb `function (err, inst, res)`
* Note that deleted instances will result in `err` being a * Note that deleted instances will result in `err` being a
* `InstanceDeletedError` and `inst` being defined. On success, `res` is * `InstanceDeletedError` and `inst` being defined. On success, `res` is
@ -1137,6 +1139,7 @@ TritonApi.prototype.getInstance = function getInstance(opts, cb) {
assert.object(opts, 'opts'); assert.object(opts, 'opts');
assert.string(opts.id, 'opts.id'); assert.string(opts.id, 'opts.id');
assert.optionalArrayOfString(opts.fields, 'opts.fields'); assert.optionalArrayOfString(opts.fields, 'opts.fields');
assert.optionalBool(opts.credentials, 'opts.credentials');
assert.func(cb, 'cb'); assert.func(cb, 'cb');
/* /*
@ -1176,7 +1179,10 @@ TritonApi.prototype.getInstance = function getInstance(opts, cb) {
return next(); return next();
} }
} }
self.cloudapi.getMachine(uuid, function (err, inst_, res_) { self.cloudapi.getMachine({
id: uuid,
credentials: opts.credentials
}, function onMachine(err, inst_, res_) {
res = res_; res = res_;
inst = inst_; inst = inst_;
err = errFromGetMachineErr(err); err = errFromGetMachineErr(err);
@ -1264,7 +1270,10 @@ TritonApi.prototype.getInstance = function getInstance(opts, cb) {
} }
var uuid = instFromList.id; var uuid = instFromList.id;
self.cloudapi.getMachine(uuid, function (err, inst_, res_) { self.cloudapi.getMachine({
id: uuid,
credentials: opts.credentials
}, function onMachine(err, inst_, res_) {
res = res_; res = res_;
inst = inst_; inst = inst_;
err = errFromGetMachineErr(err); err = errFromGetMachineErr(err);