From c7c1c45f38cd971a6935cbe92d2e4f4e3e8fa007 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Tue, 14 Oct 2014 11:31:37 +0100 Subject: [PATCH] Deal with int env vars more nicely (actually parse them and check they're valid ints) --- src/config.coffee | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/config.coffee b/src/config.coffee index 722ad663..e7fdddf4 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -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'