Permalink
Browse files

[PROV-1135] Only display credentials if asked for

  • Loading branch information...
1 parent e74fbef commit bf614089a629e6fc31f9b9949b40269d38de936d @mcavage mcavage committed Sep 8, 2011
Showing with 46 additions and 7 deletions.
  1. +3 −1 bin/sdc-getmachine
  2. +3 −1 bin/sdc-getmachinemetadata
  3. +3 −0 bin/sdc-listmachines
  4. +36 −4 lib/cloudapi.js
  5. +1 −1 package.json
View
@@ -13,6 +13,7 @@ var common = require('../lib/cli_common');
var Options = {
"account": String,
+ "credentials": Boolean,
"debug": Boolean,
"help": Boolean,
"identity": path,
@@ -22,6 +23,7 @@ var Options = {
var ShortOptions = {
"a": ["--account"],
+ "c": ["--credentials"],
"d": ["--debug"],
"h": ["--help"],
"?": ["--help"],
@@ -42,6 +44,6 @@ common.parseArguments(Options, ShortOptions, function(parsed) {
var client = common.newClient(parsed);
parsed.argv.remain.forEach(function(machine) {
- client.getMachine(machine, common.callback);
+ client.getMachine(machine, parsed.credentials || false, common.callback);
});
}, usageStr);
@@ -13,6 +13,7 @@ var common = require('../lib/cli_common');
var Options = {
"account": String,
+ "credentials": Boolean,
"debug": Boolean,
"help": Boolean,
"identity": path,
@@ -23,6 +24,7 @@ var Options = {
var ShortOptions = {
"a": ["--account"],
+ "c": ["--credentials"],
"d": ["--debug"],
"h": ["--help"],
"?": ["--help"],
@@ -58,6 +60,6 @@ common.parseArguments(Options, ShortOptions, function(parsed) {
var client = common.newClient(parsed);
parsed.argv.remain.forEach(function(machine) {
- client.getMachineMetadata(machine, callback);
+ client.getMachineMetadata(machine, parsed.credentials || false, callback);
});
}, usageStr);
View
@@ -13,6 +13,7 @@ var common = require('../lib/cli_common');
var Options = {
"account": String,
+ "credentials": Boolean,
"debug": Boolean,
"dataset": String,
"help": Boolean,
@@ -31,6 +32,7 @@ var Options = {
var ShortOptions = {
"a": ["--account"],
+ "c": ["--credentials"],
"b": ["--tombstone"],
"d": ["--debug"],
"e": ["--dataset"],
@@ -56,6 +58,7 @@ common.parseArguments(Options, ShortOptions, function(parsed) {
var opts = {};
var tags = {};
+ if (parsed.credentials) opts.credentials = parsed.credentials;
if (parsed.dataset) opts.dataset = parsed.dataet;
if (parsed.limit) opts.limit = parsed.limit;
if (parsed.memory) opts.memory = parsed.memory;
View
@@ -748,15 +748,28 @@ CloudAPI.prototype.ListMachines = CloudAPI.prototype.listMachines;
* @param {Function} callback of the form f(err, machine).
* @throws {TypeError} on bad input.
*/
-CloudAPI.prototype.getMachine = function(account, machine, callback, noCache) {
+CloudAPI.prototype.getMachine = function(account,
+ machine,
+ getCredentials,
+ callback,
+ noCache) {
if (typeof(machine) === 'function') {
callback = machine;
+ getCredentials = false;
+ machine = account;
+ account = this.account;
+ }
+ if (typeof(getCredentials) === 'function') {
+ callback = getCredentials;
+ getCredentials = machine;
machine = account;
account = this.account;
}
if (!machine ||
(typeof(machine) !== 'object' && typeof(machine) !== 'string'))
throw new TypeError('machine (object|string) required');
+ if (typeof(getCredentials) !== 'boolean')
+ throw new TypeError('getCredentials must be a boolean');
if (!callback || typeof(callback) !== 'function')
throw new TypeError('callback (function) required');
if (typeof(account) === 'object')
@@ -765,7 +778,10 @@ CloudAPI.prototype.getMachine = function(account, machine, callback, noCache) {
var name = (typeof(machine) === 'object' ? machine.id : machine);
var self = this;
- return this._request(sprintf(MACHINE, account, name), null, function(req) {
+ var path = sprintf(MACHINE, account, name);
+ if (getCredentials)
+ path += '?credentials=true';
+ return this._request(path, null, function(req) {
req.cacheTTL = (15 * 1000);
return self._get(req, callback, noCache);
});
@@ -1337,18 +1353,31 @@ CloudAPI.prototype.DeleteMachineTag = CloudAPI.prototype.deleteMachineTag;
* @param {String} account (optional) the login name of the account.
* @param {String} machine either the id, or can be the object returned in list
* or create.
+ * @param {Boolean} getCredentials whether or not to return passwords (default is false).
* @param {Function} callback of the form f(err).
* @throws {TypeError} on bad input.
*/
-CloudAPI.prototype.getMachineMetadata = function(account, machine, callback) {
+CloudAPI.prototype.getMachineMetadata = function(account,
+ machine,
+ getCredentials,
+ callback) {
if (typeof(machine) === 'function') {
callback = machine;
+ getCredentials = false;
+ machine = account;
+ account = this.account;
+ }
+ if (typeof(getCredentials) === 'function') {
+ callback = getCredentials;
+ getCredentials = machine;
machine = account;
account = this.account;
}
if (!machine ||
(typeof(machine) !== 'object' && typeof(machine) !== 'string'))
throw new TypeError('machine (object|string) required');
+ if (typeof(getCredentials) !== 'boolean')
+ throw new TypeError('getCredentials must be a boolean');
if (!callback || typeof(callback) !== 'function')
throw new TypeError('callback (function) required');
if (typeof(account) === 'object')
@@ -1357,7 +1386,10 @@ CloudAPI.prototype.getMachineMetadata = function(account, machine, callback) {
var m = (typeof(machine) === 'object' ? machine.id : machine);
var self = this;
- return this._request(sprintf(METADATA, account, m), null, function(req) {
+ var path = sprintf(METADATA, account, m);
+ if (getCredentials)
+ path += '?credentials=true';
+ return this._request(path, null, function(req) {
return self._get(req, callback);
});
};
View
@@ -2,7 +2,7 @@
"author": "Joyent, Inc. (http://www.joyent.com)",
"name": "smartdc",
"description": "Client SDK and CLI for the Joyent SmartDataCenter API",
- "version": "6.1.0-6",
+ "version": "6.1.0-7",
"author": "Joyent, Inc",
"homepage": "http://www.joyent.com/software/smartdatacenter",
"repository": {

0 comments on commit bf61408

Please sign in to comment.