Permalink
Browse files

user keys: add login, fix urls.

  • Loading branch information...
1 parent bed9db8 commit f04e58b2967722f9d78d0af661e549c23dc4d5b0 @chjj chjj committed Apr 10, 2012
Showing with 39 additions and 4 deletions.
  1. +39 −4 lib/jitsu/commands/keys.js
View
@@ -34,14 +34,23 @@ keys.create = function (keyName, file, callback) {
data.value = val;
+ jitsu.log.info('Uploading public key...');
return create(data);
});
}
function create(data) {
- jitsu.keys.create(user + '/' + keyName, data, function (err, response) {
+ jitsu.keys.create(user + '/keys/' + keyName, data, function (err, response) {
if (err) return callback(err);
jitsu.log.help('Key successfully created.');
+ return callback();
+ });
+ }
+
+ if (!user) {
+ jitsu.commands.users.login(function (err) {
+ if (err) return callback(err, true);
+ return keys.create(keyName, file, callback);
});
}
@@ -62,6 +71,7 @@ keys.create = function (keyName, file, callback) {
jitsu.log.info('Please enter location of public key.');
jitsu.log.info('~/.ssh/id_rsa.pub will be used by default.');
jitsu.prompt.get(['file'], function (err, result) {
+ if (err) return callback(err);
file = result.file || jitsu.config.get('root') + '/.ssh/id_rsa.pub';
return read(file);
});
@@ -91,6 +101,13 @@ keys.create.usage = [
keys.list = function (callback) {
var user = jitsu.config.get('username');
+ if (!user) {
+ jitsu.commands.users.login(function (err) {
+ if (err) return callback(err, true);
+ return keys.list(keyName, callback);
+ });
+ }
+
jitsu.keys.list(user, function (err, keys) {
if (err) return callback(err);
@@ -108,6 +125,8 @@ keys.list = function (callback) {
});
jitsu.inspect.putRows('data', rows, colors);
+
+ return callback();
});
};
@@ -129,6 +148,13 @@ keys.list.usage = [
keys.view = function (keyName, callback) {
var user = jitsu.config.get('username');
+ if (!user) {
+ jitsu.commands.users.login(function (err) {
+ if (err) return callback(err, true);
+ return keys.view(keyName, callback);
+ });
+ }
+
if (!keyName) {
jitsu.log.info('Please enter a name for your key.');
return jitsu.prompt.get(['name'], function(err, result) {
@@ -138,9 +164,10 @@ keys.view = function (keyName, callback) {
});
}
- jitsu.keys.view(user + '/' + keyName, function (err, key) {
+ jitsu.keys.view(user + '/keys/' + keyName, function (err, key) {
if (err) return callback(err);
jitsu.inspect.putObject(key);
+ return callback();
});
};
@@ -155,14 +182,21 @@ keys.view.usage = [
];
//
-// ### function delete (keyName callback)
+// ### function delete (keyName, callback)
// #### @keyName {string} Name of the key
// #### @callback {function} Continuation to pass control to when complete.
// Attempt to return a key.
//
keys.delete = function (keyName, callback) {
var user = jitsu.config.get('username');
+ if (!user) {
+ jitsu.commands.users.login(function (err) {
+ if (err) return callback(err, true);
+ return keys.delete(keyName, callback);
+ });
+ }
+
if (!keyName) {
jitsu.log.info('Please enter a name for your key.');
return jitsu.prompt.get(['name'], function(err, result) {
@@ -173,9 +207,10 @@ keys.delete = function (keyName, callback) {
}
// fix this ins nodejitsu-api
- jitsu.keys.destroy(user + '/' + keyName, function (err) {
+ jitsu.keys.destroy(user + '/keys/' + keyName, function (err) {
if (err) return callback(err);
jitsu.log.help('Key deleted successfully.');
+ return callback();
});
};

0 comments on commit f04e58b

Please sign in to comment.