Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: nodejitsu/jitsu
...
head fork: nodejitsu/jitsu
  • 7 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 57 additions and 22 deletions.
  1. +50 −17 lib/jitsu/commands/databases.js
  2. +7 −5 test/commands/databases-test.js
67 lib/jitsu/commands/databases.js
View
@@ -21,7 +21,7 @@ databases.usage = [
'Valid database types are: ' + 'couch'.magenta + ', ' + 'redis'.magenta + ', or ' + 'mongo'.magenta
];
-databases.available = ['couch', 'redis', 'mongo'];
+databases.available = ['couch', 'redis', 'mongo', 'mongohq', 'redistogo'];
//
// Micro aliasing for databases command
@@ -35,7 +35,9 @@ databases.available = ['couch', 'redis', 'mongo'];
databases.aliases = {
couch : ['c', 'couchdb'],
redis : ['r'],
- mongo : ['m', 'mongodb']
+ mongo : ['m', 'mongodb'],
+ mongohq: [],
+ redistogo: []
};
//
@@ -167,7 +169,9 @@ databases.create.usage = [
'',
'jitsu databases create couch <database name>',
'jitsu databases create mongo <database name>',
- 'jitsu databases create redis <database name>'
+ 'jitsu databases create redis <database name>',
+ 'jitsu databases create mongohq <database name>',
+ 'jitsu databases create redistogo <database name>',
];
databases.get = function (databaseName, callback) {
@@ -299,25 +303,38 @@ var printDatabase = function (database) {
switch (database.type) {
case 'couch':
- var subdomain = database.metadata.id.split('/')[1];
printBase(database);
-
- var connUrl = 'http://' + subdomain + '.iriscouch.com:5984',
- sslConnUrl = 'https://' + subdomain + '.iriscouch.com:6984';
+ var connUrl, sslConnUrl;
+
+ // We will need support the databases created using the old way
+ // So we check if
+ if (database.metadata.id.indexOf('/') !== -1) {
+ var subdomain = database.metadata.id.split('/')[1];
+ connUrl = 'http://' + subdomain + '.iriscouch.com:5984';
+ sslConnUrl = 'https://' + subdomain + '.iriscouch.com:6984';
+ } else {
+ connUrl = 'http://' + database.metadata.host + ':5984',
+ sslConnUrl = 'https://' + database.metadata.host + ':' + database.metadata.port;
+ }
jitsu.log.data('Connection url: ' + connUrl.grey);
jitsu.log.data('SSL connection url: ' + sslConnUrl.grey);
break;
case 'mongo':
+ case 'mongohq':
printBase(database);
- jitsu.log.data('Connection url: ' + (database.metadata.config.MONGOHQ_URL).grey);
+ if (database.metadata.config && database.metadata.config.MONGOHQ_URL) {
+ jitsu.log.data('Connection url: ' + (database.metadata.config.MONGOHQ_URL).grey);
+ } else {
+ jitsu.log.data('Connection url: ' + database.metadata.uri.grey + '/'.grey + database.metadata.dbname.grey);
+ }
break;
case 'redis':
var port = database.metadata.port,
password = database.metadata.password,
- server = database.metadata.label.split('-')[0] + '.redistogo.com';
+ server = (database.metadata.label) ? database.metadata.label.split('-')[0] + '.redistogo.com' : database.metadata.host;
printBase(database);
jitsu.log.data('Connection host: ' + server.grey);
@@ -336,10 +353,16 @@ var printDbHelp = function (database) {
switch (database.type) {
case 'couch':
- var subdomain = database.metadata.id.split('/')[1];
-
- var connUrl = 'http://' + subdomain + '.iriscouch.com:5984',
- sslConnUrl = 'https://' + subdomain + '.iriscouch.com:6984';
+ var connUrl, sslConnUrl;
+
+ if (database.metadata.id.indexOf('/') !== -1) {
+ var subdomain = database.metadata.id.split('/')[1];
+ connUrl = 'http://' + subdomain + '.iriscouch.com:5984';
+ sslConnUrl = 'https://' + subdomain + '.iriscouch.com:6984';
+ } else {
+ connUrl = 'http://' + database.metadata.host + ':5984',
+ sslConnUrl = 'https://' + database.metadata.host + ':' + database.metadata.port;
+ }
// TODO: Only write this if in some "verbose" mode.
[
@@ -361,8 +384,17 @@ var printDbHelp = function (database) {
break;
case 'mongo':
- var parsed = require('url').parse(database.metadata.config.MONGOHQ_URL),
- auth = parsed.auth.split(':');
+ case 'mongohq':
+ var parsed, auth, uri;
+ if (database.metadata.config && database.metadata.config.MONGOHQ_URL) {
+ parsed = require('url').parse(database.metadata.config.MONGOHQ_URL);
+ auth = parsed.auth.split(':');
+ uri = database.metadata.config.MONGOHQ_URL;
+ } else {
+ parsed = require('url').parse(database.metadata.uri + '/' + database.metadata.dbname);
+ auth = [database.metadata.username, database.metadata.password];
+ uri = database.metadata.uri + '/' + database.metadata.dbname;
+ }
// TODO: Only write this if in some "verbose" mode.
[
@@ -387,16 +419,17 @@ var printDbHelp = function (database) {
'Connect with the `' + 'mongoose'.magenta + '` module:',
'',
' var mongoose = require(\'mongoose\');',
- ' mongoose.connect(\'' + database.metadata.config.MONGOHQ_URL + '\');',
+ ' mongoose.connect(\'' + uri + '\');',
''
].forEach(printHelp);
break;
case 'redis':
+ case 'redistogo':
var port = database.metadata.port,
password = database.metadata.password,
- server = database.metadata.label.split('-')[0] + '.redistogo.com';
+ server = (database.metadata.label) ? database.metadata.label.split('-')[0] + '.redistogo.com' : database.metadata.host;
[
'',
12 test/commands/databases-test.js
View
@@ -141,11 +141,13 @@ vows.describe('jitsu/commands/databases').addBatch({
type: "mongo",
user: "tester",
metadata: {
- ok: true,
- created: true,
- config: {
- MONGOHQ_URL: 'mongo://nodejitsu:pass@this.is.only.a.test.mongohq.com/path'
- }
+ id: 63562,
+ port: 10039,
+ host: 'this.is.only.a.test.mongohq.com',
+ uri: 'mongo://nodejitsu:pass@this.is.only.a.test.mongohq.com:10039',
+ username: 'nodejitsu',
+ password: 'pass',
+ dbname: '/path'
},
id: "tester-test3",
resource: "Database"

No commit comments for this range

Something went wrong with that request. Please try again.