From 879e1a892668ccda38ff8a27d3d2358a23643f8e Mon Sep 17 00:00:00 2001 From: PV Date: Sat, 15 Jul 2017 18:47:18 -0700 Subject: [PATCH 01/14] Add files via upload --- lib/cli/start.js | 215 ++++++++++++++++++++++++++--------------------- 1 file changed, 117 insertions(+), 98 deletions(-) diff --git a/lib/cli/start.js b/lib/cli/start.js index 426b4d0..e1784a1 100644 --- a/lib/cli/start.js +++ b/lib/cli/start.js @@ -2,35 +2,36 @@ * External dependencies */ var http = require('http'), - program = require('commander'), - fs = require('fs'), - semver = require('semver'), - Step = require('step'), - shelljs = require('shelljs/global'), - path = require('path'); + program = require('commander'), + fs = require('fs'), + semver = require('semver'), + Step = require('step'), + shelljs = require('shelljs/global'), + path = require('path'); /** - * Local modules + * Local modules */ var stop = require('./stop'), - mongod = require('../util/mongod'), - repl = require('../client/repl'), - packageInfo = require('../../package'), - latestversionFile = path.join(__dirname, '../../.latestversion'), - createServer = require('./createserver'); + mongod = require('../util/mongod'), + repl = require('../client/repl'), + packageInfo = require('../../package'), + latestversionFile = path.join(__dirname, '../../.latestversion'), + createServer = require('./createserver'); /** * Start the server */ -var start = function(file) { +var start = function (file) { var port = program.port, - host = program.host || '127.0.0.1', - dbname = program.dbname || '-deployd', - mongoPort = generatePort(), - env = program.environment || process.env.DPD_ENV || 'development', - retries = 0, - credentials; + host = program.host || '127.0.0.1', + dbname = program.dbname || '-deployd', + mongoPort = generatePort(), + env = program.environment || process.env.DPD_ENV || 'development', + retries = 0, + credentials = {}; + if (!port) { port = 2403; @@ -38,7 +39,7 @@ var start = function(file) { } if (program.mongoPort) { - mongoPort = Number(program.mongoPort); + mongoPort = Number(program.mongoPort); } if (file) { @@ -62,45 +63,62 @@ var start = function(file) { if (!test('-d', './data')) mkdir('-p', './data'); if (program.auth && program.host === undefined) { - console.error("Authentication requires the '-h' host flag... exiting."); - process.exit(); + console.error("Authentication requires the '-h' host flag... exiting."); + process.exit(); } - if (program.host) { - if (program.auth) { - Step(function () { - var next = this; - credentials = {}; - program.prompt('username: ', function(username){ - if (username && username !== '') { - credentials.username = username; - next(); - } else { - console.error('Username cannot be blank.'); - process.exit(); - } - }); - }, - function () { - var next = this; - program.password('Password: ', function(pass){ - if (pass && pass !== '') { - credentials.password = pass; - next(); - } else { - console.error('Password cannot be blank.'); - process.exit(); - } - }); - }, - startup - ); + + + // Added by PV + + function setCredentials(username, password) { + Step(function () { + var next = this; + if (username && username !== '') { + credentials.username = username; + next(); } else { - startup(); + console.error('Username cannot be blank.'); + process.exit(); } - } else { - mongod.restart(program.mongod || 'mongod', env, mongoPort, startup); + }, + function () { + var next = this; + if (password && password !== '') { + credentials.password = password; + next(); + } else { + console.error('Password cannot be blank.'); + process.exit(); + } + }, + startup + ); + } + + + + if (program.host) { + if (program.auth) { + var auth = program.auth.split(":"); + username = auth[0]; + password = auth[1]; + setCredentials(username, password); + } else if (program.username || program.password) { + console.log(' program.password', program.password) + setCredentials(program.username, program.password); + } + else { + startup(); + } } + else { + mongod.restart(program.mongod || 'mongod', env, mongoPort, startup); + } + + + //-- Added by PV + } else { console.log("This directory does not contain a Deployd app!"); @@ -109,68 +127,69 @@ var start = function(file) { stop(1); } - function startup (err) { - if (err) { - console.log("Failed to start MongoDB (Make sure 'mongod' are in your $PATH or use dpd --mongod option. Ref: http://docs.deployd.com/docs/basics/cli.html)"); - return stop(1); - } + function startup(err) { + if (err) { + console.log("Failed to start MongoDB (Make sure 'mongod' are in your $PATH or use dpd --mongod option. Ref: http://docs.deployd.com/docs/basics/cli.html)"); + return stop(1); + } - var options = {port: port, env: 'development', db: {host: host, port: mongoPort, name: dbname}}; - - options.env = program.environment || process.env.DPD_ENV || options.env; - if(options.env !== 'development') console.log('starting in %s mode', options.env); - - if(credentials !== undefined) options.db.credentials = credentials; - var dpd = createServer(options); - dpd.on('listening', onListening); - dpd.on('error', onError); - dpd.listen(); - dpd.deploydPath = program.deploydPath; - - function onListening () { - console.info('listening on port', options.port); - var commands = repl(dpd); - if (program.dashboard) { - commands.dashboard(); - } else if (program.open) { - commands.open(); - } + var options = { port: port, env: 'development', db: { host: host, port: mongoPort, name: dbname } }; + + options.env = program.environment || process.env.DPD_ENV || options.env; + if (options.env !== 'development') console.log('starting in %s mode', options.env); + + if (credentials !== undefined) options.db.credentials = credentials; + + var dpd = createServer(options); + dpd.on('listening', onListening); + dpd.on('error', onError); + dpd.listen(); + dpd.deploydPath = program.deploydPath; + + function onListening() { + console.info('listening on port', options.port); + var commands = repl(dpd); + if (program.dashboard) { + commands.dashboard(); + } else if (program.open) { + commands.open(); } + } - function onError (err) { - if (err.code === "EADDRINUSE") { - console.error(); - console.error("ERROR: port " + options.port + " is already in use"); - if (retries > 0) { - options.port++; - console.log("Trying again on port " + options.port + "..."); - console.log(); - retries--; - dpd = createServer(options); - dpd.on('listening', onListening); - dpd.on('error', onError); - dpd.listen(); - } else { - process.exit(); - } + function onError(err) { + if (err.code === "EADDRINUSE") { + console.error(); + console.error("ERROR: port " + options.port + " is already in use"); + if (retries > 0) { + options.port++; + console.log("Trying again on port " + options.port + "..."); + console.log(); + retries--; + dpd = createServer(options); + dpd.on('listening', onListening); + dpd.on('error', onError); + dpd.listen(); } else { - console.error(err); process.exit(); } + } else { + console.error(err); + process.exit(); } } + } } /** * Port generation */ function generatePort() { - var portRange = [ 3000, 9000 ]; + var portRange = [3000, 9000]; return Math.floor(Math.random() * (portRange[1] - portRange[0])) + portRange[0]; } function checkForUpdates() { - http.get('http://registry.npmjs.org/deployd-cli', function(err, res, body) { + http.get('http://registry.npmjs.org/deployd-cli', function (err, res, body) { if (!err) { var json; try { From be81d19ca484a79655a3db2aabd2df9aa9f83703 Mon Sep 17 00:00:00 2001 From: PV Date: Sat, 15 Jul 2017 18:48:08 -0700 Subject: [PATCH 02/14] Add files via upload --- bin/dpd | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/dpd b/bin/dpd index 55e3ba7..8d35149 100755 --- a/bin/dpd +++ b/bin/dpd @@ -18,9 +18,14 @@ cli.program .option('-H, --host [host]', 'specify host for mongo server') .option('-P, --mongoPort [mongoPort]', 'mongodb port to connect to') .option('-n, --dbname [dbname]', 'name of the mongo database') - .option('-a, --auth', 'prompts for mongo server credentials') + .option('-a, --auth ', ' usesrname:password mongo server credentials') + .option('-u, --username ', 'The user to authenticate as') + .option('-s, --password ', 'The user\'s password') + .option('-c, --dbconn ', 'The MongoDB Connection String') .option(' --deploydPath [deploydPath]', 'allow overriding the path to deployd main script'); + + cli.program .command('create [project-name]') .description('\tcreate a project in a new directory\n\teg. `dpd create my-app`') @@ -52,4 +57,5 @@ cli.program cli.program.parse(process.argv); -if (cli.program.args.length === 0) cli.start(); \ No newline at end of file +if (cli.program.args.length === 0) cli.start(); + \ No newline at end of file From 4fb74587e02d31450fc93781af9a9515fcfcc3e5 Mon Sep 17 00:00:00 2001 From: PV Date: Sat, 15 Jul 2017 18:48:26 -0700 Subject: [PATCH 03/14] Add files via upload --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dd1d1d8..c787d10 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,55 @@ Deployd requires a running MongoDB to start sucessfully. Check the [Deployd Requ ```bash $ dpd create hello $ cd hello -$ dpd -d +$ dpd +``` +To start dpd with Database authentication: + +``` +dpd --host "127.0.0.1" -P '27017' -n "mymongodb" -u "myusername" -s "mypassword" + +or + +dpd --host "127.0.0.1" -P '27017' -n "mymongodb" -a "myusername:mypassword" + +``` + +## dpd Command Options + +``` + Usage: dpd [options] [command] + + + Options: + + -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 usesrname:password mongo server credentials + -u, --username The user to authenticate as + -s, --password The user's password + -c, --dbconn The MongoDB Connection String + --deploydPath [deploydPath] allow overriding the path to deployd main script + -h, --help output usage information + + + Commands: + + create [project-name] create a project in a new directory + eg. `dpd create my-app` + keygen generate a key for remote access (./.dpd/keys.json) + showkey shows current key for connecting to remote dashboard (./.dpd/keys.json) + * [default] start the server in the current project in development mode + with an interactive shell/repl for interacting with the running server + e.g. dpd (starts server in current directory), + dpd my-app/app.dpd (starts app from file) ``` ## License From 61e969a67b2d136344835f43f43805d9114741f8 Mon Sep 17 00:00:00 2001 From: PV Date: Sat, 15 Jul 2017 19:08:16 -0700 Subject: [PATCH 04/14] Add files via upload --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d612525..dd977fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deployd-cli", - "version": "2.0.0", + "version": "0.0.2", "license": "MIT", "description": "The deployd command line interface", "repository": { From 1cf7ad4827d3e8354173afb066305e20dfdc9da1 Mon Sep 17 00:00:00 2001 From: PV Date: Sat, 15 Jul 2017 20:18:23 -0700 Subject: [PATCH 05/14] Add files via upload --- lib/cli/stop.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/cli/stop.js b/lib/cli/stop.js index 8110110..4cc0410 100644 --- a/lib/cli/stop.js +++ b/lib/cli/stop.js @@ -1,6 +1,9 @@ /** * Start the server */ +var program = require('commander'); + + var stop = function(code) { var fn = function() { exit(code); From c91cfcd4a2192da7bab211e2bbce968b266f22af Mon Sep 17 00:00:00 2001 From: PV Date: Sun, 16 Jul 2017 12:14:47 -0700 Subject: [PATCH 06/14] Add files via upload --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd977fb..d612525 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deployd-cli", - "version": "0.0.2", + "version": "2.0.0", "license": "MIT", "description": "The deployd command line interface", "repository": { From 6a2d27f846e2d45e98b0f9308c56066cd4f8c84f Mon Sep 17 00:00:00 2001 From: PV Date: Sun, 16 Jul 2017 12:15:13 -0700 Subject: [PATCH 07/14] Add files via upload --- lib/cli/start.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/cli/start.js b/lib/cli/start.js index e1784a1..942538d 100644 --- a/lib/cli/start.js +++ b/lib/cli/start.js @@ -69,7 +69,7 @@ var start = function (file) { - // Added by PV + function setCredentials(username, password) { Step(function () { @@ -105,7 +105,7 @@ var start = function (file) { password = auth[1]; setCredentials(username, password); } else if (program.username || program.password) { - console.log(' program.password', program.password) + setCredentials(program.username, program.password); } else { @@ -116,8 +116,7 @@ var start = function (file) { mongod.restart(program.mongod || 'mongod', env, mongoPort, startup); } - - //-- Added by PV + } else { From 4a78d97cb5e4306bab9144330a6f942dd8226ef3 Mon Sep 17 00:00:00 2001 From: PV Date: Sun, 16 Jul 2017 15:52:20 -0700 Subject: [PATCH 08/14] Add files via upload added dpd.config to set dpd configurations to comply naming convention , that will replace app.dpd --- lib/createtemplate/dpd.config | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/createtemplate/dpd.config diff --git a/lib/createtemplate/dpd.config b/lib/createtemplate/dpd.config new file mode 100644 index 0000000..c3bcf4c --- /dev/null +++ b/lib/createtemplate/dpd.config @@ -0,0 +1,15 @@ +{ + "dpd": { + "port": 2403, + "env": "development" + }, + "db": { + "mongod": "", + "port": "", + "host": "", + "dbname": "", + "username": "", + "password": "", + "connectionString": "" + } +} \ No newline at end of file From 6962cca7da49baf9e70b9da12b8dbab1ec8844b1 Mon Sep 17 00:00:00 2001 From: PV Date: Mon, 17 Jul 2017 17:57:36 -0700 Subject: [PATCH 09/14] Create .travis.yml --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e651f17 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js + sudo: false + dist: trusty From 05440208d877c59faf2c99ab617331650fd0ac62 Mon Sep 17 00:00:00 2001 From: PV Date: Tue, 18 Jul 2017 23:53:21 -0700 Subject: [PATCH 10/14] Update .travis.yml --- .travis.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e651f17..78b519e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,12 @@ -language: node_js - sudo: false - dist: trusty +language: node_js +cache: + directories: + - node_modules +sudo: false +services: mongodb +node_js: + - "7" + - "6" + - "5" + - "4" +- "0.12" From 382765ef639f3a4df68a8fc22d198831d9d93c17 Mon Sep 17 00:00:00 2001 From: PV Date: Wed, 19 Jul 2017 00:06:56 -0700 Subject: [PATCH 11/14] Add files via upload --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 78b519e..022ef45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ node_js: - "6" - "5" - "4" -- "0.12" + - "0.12" From a20c4593a81f85f0a4862e22bf2475c3f98b138f Mon Sep 17 00:00:00 2001 From: PV Date: Wed, 19 Jul 2017 01:32:43 -0700 Subject: [PATCH 12/14] Delete .travis.yml --- .travis.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 022ef45..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: node_js -cache: - directories: - - node_modules -sudo: false -services: mongodb -node_js: - - "7" - - "6" - - "5" - - "4" - - "0.12" From 81233c53c9405096dcf7e162ee59b82fb8052a21 Mon Sep 17 00:00:00 2001 From: PV Date: Wed, 19 Jul 2017 01:37:51 -0700 Subject: [PATCH 13/14] Add files via upload --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..022ef45 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: node_js +cache: + directories: + - node_modules +sudo: false +services: mongodb +node_js: + - "7" + - "6" + - "5" + - "4" + - "0.12" From b8f6bb766744048e97f5bb4c597636fc5e47844a Mon Sep 17 00:00:00 2001 From: PV Date: Wed, 19 Jul 2017 01:38:11 -0700 Subject: [PATCH 14/14] Delete dpd.config --- lib/createtemplate/dpd.config | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 lib/createtemplate/dpd.config diff --git a/lib/createtemplate/dpd.config b/lib/createtemplate/dpd.config deleted file mode 100644 index c3bcf4c..0000000 --- a/lib/createtemplate/dpd.config +++ /dev/null @@ -1,15 +0,0 @@ -{ - "dpd": { - "port": 2403, - "env": "development" - }, - "db": { - "mongod": "", - "port": "", - "host": "", - "dbname": "", - "username": "", - "password": "", - "connectionString": "" - } -} \ No newline at end of file