config validation
This commit is contained in:
parent
2769a83035
commit
48bb11c3f7
|
@ -18,6 +18,19 @@ defaults =
|
||||||
# Making NSA (err taxpayer) work for it.
|
# Making NSA (err taxpayer) work for it.
|
||||||
'protocol': 'https'
|
'protocol': 'https'
|
||||||
|
|
||||||
|
# Validators of config fields.
|
||||||
|
validators =
|
||||||
|
'host': (value) ->
|
||||||
|
_.isString value
|
||||||
|
'protocol': (value) ->
|
||||||
|
_.isString(value) and value.match /^http(s?)$/
|
||||||
|
'token': (value) ->
|
||||||
|
_.isString value
|
||||||
|
'off_days': (value) ->
|
||||||
|
return no unless _.isArray value
|
||||||
|
( return no for day in value when day not in [ 1..7 ] )
|
||||||
|
yes
|
||||||
|
|
||||||
# Get (& cache) configuration from the server.
|
# Get (& cache) configuration from the server.
|
||||||
module.exports = (cb) ->
|
module.exports = (cb) ->
|
||||||
# Have config?
|
# Have config?
|
||||||
|
@ -42,6 +55,11 @@ module.exports = (cb) ->
|
||||||
else
|
else
|
||||||
config.size_label = regex.size_label
|
config.size_label = regex.size_label
|
||||||
|
|
||||||
|
# Validate it.
|
||||||
|
for field, validator of validators when config[field]
|
||||||
|
unless validator config[field]
|
||||||
|
return cb "Config field `#{field}` misconfigured"
|
||||||
|
|
||||||
# Call back for each enqueued.
|
# Call back for each enqueued.
|
||||||
_.each queue, (cb) ->
|
_.each queue, (cb) ->
|
||||||
cb null, config
|
cb null, config
|
Loading…
Reference in New Issue