Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add user keys

  • Loading branch information...
commit fba2770e8bddd152d3e869e8b6d59f7c1ffb6727 1 parent 25256b2
@chjj chjj authored
Showing with 167 additions and 13 deletions.
  1. +14 −13 lib/jitsu.js
  2. +153 −0 lib/jitsu/commands/keys.js
View
27 lib/jitsu.js
@@ -34,7 +34,7 @@ jitsu.use(flatiron.plugins.cli, {
string: true
},
jitsuconf: {
- alias: 'j',
+ alias: 'j',
description: 'specify file to load configuration from',
string: true
},
@@ -69,7 +69,7 @@ jitsu.options.log = {
// Setup config, users, command aliases and prompt settings
//
jitsu.prompt.properties = flatiron.common.mixin(
- jitsu.prompt.properties,
+ jitsu.prompt.properties,
require('./jitsu/properties')
);
jitsu.prompt.override = jitsu.argv;
@@ -95,6 +95,7 @@ jitsu.api.Databases = require('nodejitsu-api').Databases;
jitsu.api.Logs = require('nodejitsu-api').Logs;
jitsu.api.Snapshots = require('nodejitsu-api').Snapshots;
jitsu.api.Users = require('nodejitsu-api').Users;
+// jitsu.api.Keys = require('nodejitsu-api').Keys;
//
// ### function welcome ()
@@ -111,7 +112,7 @@ jitsu.welcome = function () {
// #### @callback {function} Continuation to pass control to when complete.
// Starts the jitsu CLI and runs the specified command.
//
-jitsu.start = function (callback) {
+jitsu.start = function (callback) {
//
// Check for --no-colors/--colors option, without hitting the config file
// yet
@@ -124,7 +125,7 @@ jitsu.start = function (callback) {
if (err) {
return callback();
}
-
+
jitsu.init(function (err) {
if (err) {
jitsu.welcome();
@@ -217,7 +218,7 @@ jitsu.exec = function (command, callback) {
// Sets up the instances of the Resource clients for jitsu.
// there is no io here, yet this function is ASYNC.
//
-jitsu.setup = function (callback) {
+jitsu.setup = function (callback) {
if (jitsu.started === true) {
return callback();
}
@@ -258,12 +259,12 @@ jitsu.showError = function (command, err, shallow, skip) {
if (username) {
jitsu.log.error('Unable to authenticate as: ' + username.magenta);
}
-
- jitsu.log.error('403 ' + err.result.error);
+
+ jitsu.log.error('403 ' + err.result.error);
}
else if (!skip) {
jitsu.log.error('Error running command ' + command.magenta);
-
+
if (!jitsu.config.get('nolog')) {
jitsu.logFile.log(err);
}
@@ -287,7 +288,7 @@ jitsu.showError = function (command, err, shallow, skip) {
jitsu.log.error('');
jitsu.log.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
}
-
+
jitsu.log.error('Error output from your application:');
jitsu.log.error('');
if (err.result.result.error.stdout) {
@@ -295,7 +296,7 @@ jitsu.showError = function (command, err, shallow, skip) {
jitsu.log.error(line);
});
}
-
+
if (err.result.result.error.stderr) {
err.result.result.error.stderr.split('\n').forEach(function (line) {
jitsu.log.error(line);
@@ -306,13 +307,13 @@ jitsu.showError = function (command, err, shallow, skip) {
jitsu.log.error('There was an error while attempting to deploy your application.');
jitsu.log.error('');
jitsu.log.error(err.result.result.error.message);
-
+
if (err.result.result.error.blame) {
jitsu.log.error(err.result.result.error.blame.message);
jitsu.log.error('');
jitsu.log.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
- }
-
+ }
+
jitsu.log.error('Error output from Haibu:');
jitsu.log.error('');
stack = err.result.result.error.result || err.result.result.error.stack;
View
153 lib/jitsu/commands/keys.js
@@ -0,0 +1,153 @@
+/*
+ * keys.js: Commands related to user keys
+ *
+ * (C) 2010, Nodejitsu Inc.
+ *
+ */
+
+var jitsu = require('../../jitsu');
+
+var keys = exports;
+
+//
+// ### function create (username, keyName callback)
+// #### @username {string} Username
+// #### @data {string} Key data
+// #### @callback {function} Continuation to pass control to when complete.
+// Attempt to create a key on the user's behalf.
+//
+keys.create = function (username, data, callback) {
+ var user = {
+ username: username,
+ password: jitsu.config.get('password')
+ };
+
+ if (data.path) {
+ fs.readFile(data.path, 'utf8', function(err, val) {
+ if (err) return callback(err);
+ data.value = val.split(/\s+/)[1];
+ delete data.path;
+ return next();
+ });
+ } else {
+ return next();
+ }
+
+ function next() {
+ jitsu.users.createKey(user, data.name, function (err, response) {
+ if (err) return callback(err);
+ jitsu.log.help('Key successfully created.');
+ });
+ }
+};
+
+//
+// Usage for `jitsu keys create`.
+//
+keys.create.usage = [
+ 'Confirms the Nodejitsu user account for the specified username.',
+ 'You will be prompted to supply a valid invite code for the account.',
+ '',
+ 'jitsu keys confirm <username> <invitecode>'
+];
+
+//
+// ### function list (username, callback)
+// #### @username {string} Username
+// #### @callback {function} Continuation to pass control to when complete.
+// Attempt to list all keys bound to the user.
+//
+keys.list = function (username, callback) {
+ var user = {
+ username: username,
+ password: jitsu.config.get('password')
+ };
+
+ jitsu.users.listKeys(user, function (err, keys) {
+ if (err) return callback(err);
+
+ var rows = [['name', 'state', 'subdomain', 'start', 'latest']],
+ colors = ['underline', 'underline', 'underline', 'underline', 'underline'];
+
+ Object.keys(keys).forEach(function (k) {
+ var key = keys[k];
+ rows.push([
+ k,
+ key.type,
+ key.value,
+ key.ttl,
+ ]);
+ });
+
+ jitsu.inspect.putRows('data', rows, colors);
+ });
+};
+
+//
+// Usage for `jitsu keys list`.
+//
+keys.list.usage = [
+ 'Confirms the Nodejitsu user account for the specified username.',
+ 'You will be prompted to supply a valid invite code for the account.',
+ '',
+ 'jitsu keys confirm <username> <invitecode>'
+];
+
+//
+// ### function view (username, keyName callback)
+// #### @username {string} Username
+// #### @keyName {string} Name of the key
+// #### @callback {function} Continuation to pass control to when complete.
+// Attempt to return a key.
+//
+keys.view = function (username, keyName, callback) {
+ var user = {
+ username: username,
+ password: jitsu.config.get('password')
+ };
+
+ jitsu.users.getKey(user, keyName, function (err, key) {
+ if (err) return callback(err);
+ jitsu.inspect.putObject(key);
+ });
+};
+
+//
+// Usage for `jitsu keys view`.
+//
+keys.view.usage = [
+ 'Confirms the Nodejitsu user account for the specified username.',
+ 'You will be prompted to supply a valid invite code for the account.',
+ '',
+ 'jitsu keys confirm <username> <invitecode>'
+];
+
+//
+// ### function delete (username, keyName callback)
+// #### @username {string} Username
+// #### @keyName {string} Name of the key
+// #### @callback {function} Continuation to pass control to when complete.
+// Attempt to return a key.
+//
+keys.delete = function (username, keyName, callback) {
+ var user = {
+ username: username,
+ password: jitsu.config.get('password')
+ };
+
+ jitsu.users.deleteKey(user, keyName, function (err) {
+ if (err) return callback(err);
+ jitsu.log.help('Key deleted successfully.');
+ });
+};
+
+//
+// Usage for `jitsu keys delete`.
+//
+keys.delete.usage = [
+ 'Confirms the Nodejitsu user account for the specified username.',
+ 'You will be prompted to supply a valid invite code for the account.',
+ '',
+ 'jitsu keys confirm <username> <invitecode>'
+];
+
Please sign in to comment.
Something went wrong with that request. Please try again.