deployd/deployd — pull request #54 by aaronfay (2012-09-19 06:21:01+00:00)
Title: Fixes #52 - authenticate with remote mongo server

Hello,

Please review this pull request, I've made some changes primarily to 2 files to allow the option of remote authentication as opposed to starting a local mongodb instance. The main features of note are in the `dpd` script, several new command line options:

```
Options:

-h, --help output usage information
-V, --version output the version number
-m, --mongod [path] path to mongod executable (defaults to `mongod`)
-p, --port [port] port to host server (defaults to 2403)
-w, --wait wait for input before exiting
-d, --dashboard start the dashboard immediately
-o, --open open in a browser
-e, --environment [env] defaults to development
-h, --host [host] specify host for mongo server
-P, --mongoPort [mongoPort] mongodb port to connect to
-n, --dbname [dbname] name of the mongo database
-a, --auth prompts for mongo server credentials

```

The new options are `-h --host`, `-P --mongoPort`, `-n --dbname`, and `-a --auth`. If `auth` is selected, the user will be prompted for a username and password on startup. The `auth` flag also requires `host` to be provided also.

As for the `db.js` changes, the most notable feature is the ability to create a database with authentication:

```
var options = {
host: "remote.db.com",
port: 27017,
name: "my-db",
credentials: {
username: "foo_user",
password: "top secret"
}
}

db = db.create(options);

```
The code is modified to always use the `host` parameter which defaults to loopback address when not provided. If credentials are set, the mongo `authenticate` method is called with the credentials directly after opening the connection to the database.

I have also included a couple tests to prove the authentication feature, but was unable to run the regular test suite because there is no local mongo instance in my dev environment (koding.com), and I also had some trouble with the `expect` statements, if someone could provide insight regarding how to make those `expect` statements happy, I would be appreciative.

Regards,
Aaron