Factor duplicated validation code to one place.

This commit is contained in:
Nick Martin
2011-12-08 23:10:45 -08:00
parent 5293001ff5
commit 8b985ec67b
2 changed files with 20 additions and 28 deletions

View File

@@ -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.

View File

@@ -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');