Permalink
Browse files

Merge pull request #25 from nodejitsu/fix-databases-superuser

Fix databases for superusers
  • Loading branch information...
mmalecki committed Jul 29, 2013
2 parents fcbc2a8 + 01e4ea1 commit 93c2cc53bce120ca87012339bf6a4d6afb762b33
Showing with 12 additions and 8 deletions.
  1. +7 −3 node.js/lib/client/databases.js
  2. +5 −5 node.js/lib/client/helpers.js
@@ -8,6 +8,7 @@
*/

var util = require('util'),
defaultUser = require('./helpers').defaultUser,
Client = require('./client').Client;

//
@@ -31,7 +32,8 @@ util.inherits(Databases, Client);
// Provisions a database for the user
//
Databases.prototype.create = function (databaseType, databaseName, callback) {
var argv = ['databases', this.options.get('username'), databaseName];
databaseName = defaultUser.call(this, databaseName);
var argv = [ 'databases' ].concat(databaseName.split('/'));

this.request({ method: 'POST', uri: argv, body: { type: databaseType }}, function (err, result, res) {
if (err) return callback(err);
@@ -47,7 +49,8 @@ Databases.prototype.create = function (databaseType, databaseName, callback) {
// Gets the metadata for the specified database
//
Databases.prototype.get = function (databaseName, callback) {
var argv = ['databases', this.options.get('username'), databaseName];
databaseName = defaultUser.call(this, databaseName);
var argv = [ 'databases' ].concat(databaseName.split('/'));

this.request({ uri: argv }, function (err, result) {
if (err) return callback(err);
@@ -82,7 +85,8 @@ Databases.prototype.list = function (username, callback) {
// Deprovisions specified database
//
Databases.prototype.destroy = function (databaseName, callback) {
var argv = ['databases', this.options.get('username'), databaseName];
databaseName = defaultUser.call(this, databaseName);
var argv = [ 'databases' ].concat(databaseName.split('/'));

this.request({ method: 'DELETE', uri: argv }, callback);
};
@@ -2,17 +2,17 @@

//
// ### function defaultUser (appName)
// #### @appName {String} App name
// #### @data {String} App name, user/app, or user/database.
//
// A helper to prepend a default username.
// needs 'this' to be able to options.get('username').
//
exports.defaultUser = function (appName) {
if (appName.search('/') === -1) {
appName = this.options.get('username') + '/' + appName;
exports.defaultUser = function (data) {
if (!~data.indexOf('/')) {
data = this.options.get('username') + '/' + data;
}

return appName;
return data;
};

//

0 comments on commit 93c2cc5

Please sign in to comment.