From 8b985ec67b085eef9bebd978252db1ea47e65890 Mon Sep 17 00:00:00 2001 From: Nick Martin Date: Thu, 8 Dec 2011 23:10:45 -0800 Subject: [PATCH] Factor duplicated validation code to one place. --- app/skybreak/deploy.js | 17 +++++++++++++++++ app/skybreak/skybreak.js | 31 +++---------------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/app/skybreak/deploy.js b/app/skybreak/deploy.js index ae4a21f17b..92d5cddeff 100644 --- a/app/skybreak/deploy.js +++ b/app/skybreak/deploy.js @@ -24,6 +24,23 @@ exports.parse_url = function (url) { return parsed; }; +exports.validate_url = function (url) { + if (!url.hostname) { + process.stdout.write( +"Please specify a domain to connect to, such as www.example.com or\n" + +"http://www.example.com/\n"); + process.exit(1); + } + + if (url.pathname != '/' || url.hash || url.query) { + process.stdout.write( +"Sorry, Skybreak does not yet support specific path URLs, such as\n" + +"http://www.example.com/blog . Please specify the root of a domain.\n"); + process.exit(1); + } +} + + // hash the password so we never send plaintext over the wire. Doesn't // actually make us more secure, but it means we won't leak a user's // password, which they might use on other sites too. diff --git a/app/skybreak/skybreak.js b/app/skybreak/skybreak.js index dd3355fd21..21c21483d3 100644 --- a/app/skybreak/skybreak.js +++ b/app/skybreak/skybreak.js @@ -430,20 +430,7 @@ Commands.push({ // remote mode var deploy = require('./deploy'); var url = deploy.parse_url(new_argv._[1]); - - if (!url.hostname) { - process.stdout.write( -"Please specify a domain to connect to, such as www.example.com or\n" + -"http://www.example.com/\n"); - process.exit(1); - } - - if (url.pathname != '/' || url.hash || url.query) { - process.stdout.write( -"Sorry, Skybreak does not yet support specific path URLs, such as\n" + -"http://www.example.com/blog . Please specify the root of a domain.\n"); - process.exit(1); - } + deploy.validate_url(url); deploy.maybe_password(url.hostname, function (password) { @@ -524,20 +511,7 @@ Commands.push({ var deploy = require('./deploy'); var url = deploy.parse_url(new_argv._[1]); - - if (!url.hostname) { - process.stdout.write( -"Please specify a domain to deploy to, such as www.example.com or\n" + -"http://www.example.com/\n"); - process.exit(1); - } - - if (url.pathname != '/' || url.hash || url.query) { - process.stdout.write( -"Sorry, Skybreak does not yet support deploying to a specific path URL, such as\n" + -"http://www.example.com/blog . Please specify the root of a domain.\n"); - process.exit(1); - } + deploy.validate_url(url); var app_dir = path.resolve(require_project("bundle")); var build_dir = path.join(app_dir, '.skybreak/local/build_tar'); @@ -640,6 +614,7 @@ Commands.push({ var deploy = require('./deploy'); var url = deploy.parse_url(argv._[0]); + deploy.validate_url(url); deploy.maybe_password(url.hostname, function (password) { var http = require('http');