Skip to content

Commit

Permalink
Merge pull request #25 from nodejitsu/fix-databases-superuser
Browse files Browse the repository at this point in the history
Fix databases for superusers
  • Loading branch information
mmalecki committed Jul 29, 2013
2 parents fcbc2a8 + 01e4ea1 commit 93c2cc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions node.js/lib/client/databases.js
Expand Up @@ -8,6 +8,7 @@
*/ */


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


// //
Expand All @@ -31,7 +32,8 @@ util.inherits(Databases, Client);
// Provisions a database for the user // Provisions a database for the user
// //
Databases.prototype.create = function (databaseType, databaseName, callback) { 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) { this.request({ method: 'POST', uri: argv, body: { type: databaseType }}, function (err, result, res) {
if (err) return callback(err); if (err) return callback(err);
Expand All @@ -47,7 +49,8 @@ Databases.prototype.create = function (databaseType, databaseName, callback) {
// Gets the metadata for the specified database // Gets the metadata for the specified database
// //
Databases.prototype.get = function (databaseName, callback) { 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) { this.request({ uri: argv }, function (err, result) {
if (err) return callback(err); if (err) return callback(err);
Expand Down Expand Up @@ -82,7 +85,8 @@ Databases.prototype.list = function (username, callback) {
// Deprovisions specified database // Deprovisions specified database
// //
Databases.prototype.destroy = function (databaseName, callback) { 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); this.request({ method: 'DELETE', uri: argv }, callback);
}; };
10 changes: 5 additions & 5 deletions node.js/lib/client/helpers.js
Expand Up @@ -2,17 +2,17 @@


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


return appName; return data;
}; };


// //
Expand Down

0 comments on commit 93c2cc5

Please sign in to comment.