add basic server config validation

This commit is contained in:
oleg 2015-12-29 23:32:05 +03:00
parent e89211ab72
commit 73c7883904
3 changed files with 63 additions and 5 deletions

8
app.js
View File

@ -12,7 +12,8 @@ var env = process.env.NODE_ENV || 'development',
notifier = require('./lib/notifier'),
project = require('./lib/project'),
libLogger = require('./lib/logger'),
EventEmitter = require('events').EventEmitter;
EventEmitter = require('events').EventEmitter,
validateConfig = require('./lib/validateConfig');
var app = new EventEmitter(),
logger = libLogger('app'),
@ -181,6 +182,11 @@ Steppy(
reader.load(app.config.paths.data, 'config', this.slot());
},
function(err, mkdirResult, config) {
this.pass(mkdirResult);
validateConfig(config, this.slot());
},
function(err, mkdirResult, config) {
_(app.config).defaults(config);
_(app.config).defaults(configDefaults);

View File

@ -1,7 +1,7 @@
plugins:
# - nci-mail-notification
# - nci-jabber-notification
# plugins:
# - nci-mail-notification
# - nci-jabber-notification
nodes:
- type: local
@ -14,7 +14,6 @@ http:
storage:
backend: memdown
# backend: leveldown
notify:
mail:

53
lib/validateConfig.js Normal file
View File

@ -0,0 +1,53 @@
'use strict';
var Steppy = require('twostep').Steppy,
validateParams = require('./validateParams');
module.exports = function(config, callback) {
Steppy(
function() {
validateParams(config, {
type: 'object',
properties: {
plugins: {
type: 'array',
items: {type: 'string'}
},
nodes: {
type: 'array',
required: true,
items: {
type: 'object',
properties: {
type: {type: 'string', enum: ['local']},
maxExecutorsCount: {type: 'integer'}
}
},
minItems: 1
},
storage: {
type: 'object',
required: true,
properties: {
backend: {type: 'string', required: true}
}
},
notify: {
type: 'object'
}
},
additionalProperties: true
});
this.pass(null);
},
function(err) {
if (err) {
err.message = (
'Error during validation server config: "' + err.message
);
}
callback(err, config);
}
);
};