Deal with int env vars more nicely (actually parse them and check they're valid ints)

This commit is contained in:
Pagan Gazzard 2014-10-14 11:31:37 +01:00 committed by Pablo Carranza Vélez
parent 10012a48cf
commit c7c1c45f38

View File

@ -1,3 +1,12 @@
checkInt = (s) ->
# Make sure `s` exists and is not an empty string.
if !s
return
i = parseInt(s, 10)
if isNaN(i)
return
return i
module.exports = config =
apiEndpoint: process.env.API_ENDPOINT ? 'https://api.resin.io'
registryEndpoint: process.env.REGISTRY_ENDPOINT ? 'registry.resin.io'
@ -9,8 +18,8 @@ module.exports = config =
localImage: process.env.SUPERVISOR_IMAGE ? 'resin/rpi-supervisor'
configMountPoint: process.env.CONFIG_MOUNT_POINT ? '/mnt/mmcblk0p1/config.json'
ledFile: process.env.LED_FILE ? '/sys/class/leds/led0/brightness'
bootstrapRetryDelay: process.env.BOOTSTRAP_RETRY_DELAY_MS ? 30000
restartSuccessTimeout: process.env.RESTART_SUCCESS_TIMEOUT ? 60000
bootstrapRetryDelay: checkInt(process.env.BOOTSTRAP_RETRY_DELAY_MS) ? 30000
restartSuccessTimeout: checkInt(process.env.RESTART_SUCCESS_TIMEOUT) ? 60000
successMessage: 'SUPERVISOR OK'
config.heartbeatEndpoint = config.apiEndpoint + '/ping'