Skip to content

Commit f8090ea

Browse files
committed
[mongolab][api] use the cloud from the config, required to create a database
1 parent 4eb007e commit f8090ea

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

lib/pkgcloud/mongolab/database/client/databases.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,30 @@ exports.createDatabase = function createDatabase (options, callback) {
3838
options['plan'] = 'free';
3939
}
4040

41+
// We have to setup the correct prefix for database name
42+
// for the moment we use the 'owner' field because we expect the correct prefix there.
43+
var databaseName = [options['owner'], options['name']].join('_');
44+
4145
// Setup the account name according mongolab API.
42-
var account = [this.config.username, options['owner']].join('_');
46+
// @todo We need a helper function for add the prefix if its necesary
47+
//var account = [this.config.username, options['owner']].join('_');
48+
var account = options['owner'] // at the moment we need provide the username with the prefix (partner name)
4349

4450
var createOptions = {
4551
method: 'POST',
4652
path: 'accounts/' + account + '/databases',
4753
body: {
48-
name: options['name'],
54+
name: databaseName,
4955
plan: options['plan'],
50-
username: options['owner']
56+
username: options['owner'],
57+
// In future we will have to change this for support multiples clouds and user-selected cloud.
58+
cloud: this.config.cloud
5159
}
5260
}
5361

5462
this.request(createOptions, callback, function (body, response) {
55-
// Work in progress here.
56-
// We need create the owner account before create any database.
63+
// @todo: We need to parse the response instantiating a Database class, and pass it to callback.
64+
return callback(null, body);
5765
});
5866
};
5967

test/mongolab/databases/databases-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ vows.describe('pkgcloud/mongolab/databases').addBatch({
5555
}
5656
}
5757
}
58-
})/**.addBatch({
58+
}).addBatch({
5959
"The pkgcloud MongoLab client": {
60-
"the create() method": {
60+
"the createDatabase() method": {
6161
"with correct options": {
6262
topic: function () {
6363
client.createDatabase({
6464
plan:'free',
6565
name:'testDatabase',
66-
owner:'daniel'
66+
owner: testContext.account.username
6767
}, this.callback)
6868
},
6969
"should respond correctly": function (err, database) {
@@ -97,7 +97,7 @@ vows.describe('pkgcloud/mongolab/databases').addBatch({
9797
}
9898
}
9999
}
100-
})**/.addBatch({
100+
}).addBatch({
101101
"The pkgcloud MongoLab client": {
102102
"the deleteAccount() method": {
103103
"with correct options": {

0 commit comments

Comments
 (0)