RegionCreate: validate max number of regions per stage.

This commit is contained in:
Eslam A. Hefnawy 2015-12-10 22:05:15 +02:00
parent c413ee5113
commit a0b4e64773
3 changed files with 10 additions and 2 deletions

View File

@ -271,17 +271,24 @@ class ServerlessPlugin {
// if stage is provided, limit region list
if (stage){
// Make sure stage exists in project
if (!_this.S._projectJson.stages[stage]) {
return BbPromise.reject(new SError('Stage ' + stage + ' does not exist in your project', SError.errorCodes.UNKNOWN));
}
if (addAllRegions) {
// list only regions in stage
regionChoices = [];
_this.S._projectJson.stages[stage].forEach(function(regionInStage){
regionChoices.push(regionInStage.region)
});
} else {
// make sure there are regions left in stage
if (!_this.S._projectJson.stages[stage].length === 4) {
return BbPromise.reject(new SError('Stage ' + stage + ' already have all possible regions.', SError.errorCodes.UNKNOWN));
}
// list only regions NOT in stage
_this.S._projectJson.stages[stage].forEach(function(regionInStage){
let index = regionChoices.indexOf(regionInStage.region);

View File

@ -157,6 +157,7 @@ usage: serverless region create`,
return BbPromise.reject(new SError('Stage ' + _this.evt.stage + ' does not exist in your project', SError.errorCodes.UNKNOWN));
}
// validate region: make sure Lambda is supported in that region
if (awsMisc.validLambdaRegions.indexOf(_this.evt.region) == -1) {
return BbPromise.reject(new SError('Invalid region. Lambda not supported in ' + _this.evt.region, SError.errorCodes.UNKNOWN));

View File

@ -19,9 +19,9 @@ describe('All Tests', function() {
//require('./tests/actions/ModuleInstall');
//require('./tests/actions/ModuleCreate');
//require('./tests/actions/FunctionCreate');
//require('./tests/actions/EnvList');
require('./tests/actions/EnvList');
//require('./tests/actions/EnvGet');
require('./tests/actions/EnvSetUnset');
//require('./tests/actions/EnvSetUnset');
//require('./tests/actions/ResourcesDeploy');
//require('./tests/actions/FunctionRun');
//require('./tests/actions/FunctionDeploy');