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:
parent
5734123e75
commit
f100c4dbb5
@ -6,6 +6,9 @@ Known issues:
|
||||
|
||||
## 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
|
||||
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
|
||||
|
@ -872,13 +872,12 @@ CloudApi.prototype.getPackage = function getPackage(opts, cb) {
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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)`
|
||||
*/
|
||||
CloudApi.prototype.getMachine = function getMachine(opts, cb) {
|
||||
@ -887,9 +886,14 @@ CloudApi.prototype.getMachine = function getMachine(opts, cb) {
|
||||
}
|
||||
assert.object(opts, 'opts');
|
||||
assert.uuid(opts.id, 'opts.id');
|
||||
assert.optionalBool(opts.credentials, 'opts.credentials');
|
||||
|
||||
var endpoint = format('/%s/machines/%s', this.account, opts.id);
|
||||
this._request(endpoint, function (err, req, res, body) {
|
||||
var query = {};
|
||||
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);
|
||||
});
|
||||
};
|
||||
|
@ -25,7 +25,10 @@ function do_get(subcmd, opts, args, cb) {
|
||||
cb(setupErr);
|
||||
return;
|
||||
}
|
||||
tritonapi.getInstance(args[0], function (err, inst) {
|
||||
tritonapi.getInstance({
|
||||
id: args[0],
|
||||
credentials: opts.credentials
|
||||
}, function onInst(err, inst) {
|
||||
if (inst) {
|
||||
if (opts.json) {
|
||||
console.log(JSON.stringify(inst));
|
||||
@ -44,6 +47,13 @@ do_get.options = [
|
||||
type: 'bool',
|
||||
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'],
|
||||
type: 'bool',
|
||||
@ -58,7 +68,6 @@ do_get.help = [
|
||||
'{{usage}}',
|
||||
'',
|
||||
'{{options}}',
|
||||
'',
|
||||
'Where "INST" is an instance name, id, or short id.',
|
||||
'',
|
||||
'A *deleted* instance may still respond with the instance object. In that',
|
||||
|
@ -1123,6 +1123,8 @@ TritonApi.prototype.updateNetworkIp = function updateNetworkIp(opts, cb) {
|
||||
* - {Array} fields: Optional. An array of instance field names that are
|
||||
* wanted by the caller. This *can* allow the implementation to avoid
|
||||
* 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)`
|
||||
* Note that deleted instances will result in `err` being a
|
||||
* `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.string(opts.id, 'opts.id');
|
||||
assert.optionalArrayOfString(opts.fields, 'opts.fields');
|
||||
assert.optionalBool(opts.credentials, 'opts.credentials');
|
||||
assert.func(cb, 'cb');
|
||||
|
||||
/*
|
||||
@ -1176,7 +1179,10 @@ TritonApi.prototype.getInstance = function getInstance(opts, cb) {
|
||||
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_;
|
||||
inst = inst_;
|
||||
err = errFromGetMachineErr(err);
|
||||
@ -1264,7 +1270,10 @@ TritonApi.prototype.getInstance = function getInstance(opts, cb) {
|
||||
}
|
||||
|
||||
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_;
|
||||
inst = inst_;
|
||||
err = errFromGetMachineErr(err);
|
||||
|
Reference in New Issue
Block a user