Check for valid strings or ints in all config values

This commit is contained in:
Pablo Carranza Velez 2016-02-12 10:33:18 -03:00
parent a151e95036
commit b088612ddd
2 changed files with 21 additions and 19 deletions

View File

@ -1,3 +1,4 @@
* Check for valid strings or ints in all config values [Pablo]
* Remove quotes in OS version [Pablo] * Remove quotes in OS version [Pablo]
# v1.5.0 # v1.5.0

View File

@ -7,38 +7,39 @@ checkInt = (s) ->
return return
return i return i
checkValidKey = (s) -> checkString = (s) ->
# Make sure `s` exists and is not an empty string, or 'null'. # Make sure `s` exists and is not an empty string, or 'null' or 'undefined'.
if !s? or s == 'null' or s == '' # This might happen if the parsing of config.json on the host using jq is wrong (it is buggy in some versions).
if !s? or s == 'null' or s == 'undefined' or s == ''
return return
return s return s
dockerRoot = process.env.DOCKER_ROOT ? '/mnt/root/var/lib/rce' dockerRoot = checkString(process.env.DOCKER_ROOT) ? '/mnt/root/var/lib/rce'
# Defaults needed for both gosuper and node supervisor are declared in entry.sh # Defaults needed for both gosuper and node supervisor are declared in entry.sh
module.exports = config = module.exports = config =
apiEndpoint: process.env.API_ENDPOINT ? 'https://api.resin.io' apiEndpoint: checkString(process.env.API_ENDPOINT) ? 'https://api.resin.io'
listenPort: process.env.LISTEN_PORT ? 80 listenPort: checkInt(process.env.LISTEN_PORT) ? 80
gosuperAddress: "http://unix:#{process.env.GOSUPER_SOCKET}:" gosuperAddress: "http://unix:#{process.env.GOSUPER_SOCKET}:"
deltaHost: process.env.DELTA_ENDPOINT ? 'https://delta.resin.io' deltaHost: checkString(process.env.DELTA_ENDPOINT) ? 'https://delta.resin.io'
registryEndpoint: process.env.REGISTRY_ENDPOINT ? 'registry.resin.io' registryEndpoint: checkString(process.env.REGISTRY_ENDPOINT) ? 'registry.resin.io'
pubnub: pubnub:
subscribe_key: checkValidKey(process.env.PUBNUB_SUBSCRIBE_KEY) ? process.env.DEFAULT_PUBNUB_SUBSCRIBE_KEY subscribe_key: checkString(process.env.PUBNUB_SUBSCRIBE_KEY) ? process.env.DEFAULT_PUBNUB_SUBSCRIBE_KEY
publish_key: checkValidKey(process.env.PUBNUB_PUBLISH_KEY) ? process.env.DEFAULT_PUBNUB_PUBLISH_KEY publish_key: checkString(process.env.PUBNUB_PUBLISH_KEY) ? process.env.DEFAULT_PUBNUB_PUBLISH_KEY
mixpanelToken: checkValidKey(process.env.MIXPANEL_TOKEN) ? process.env.DEFAULT_MIXPANEL_TOKEN mixpanelToken: checkString(process.env.MIXPANEL_TOKEN) ? process.env.DEFAULT_MIXPANEL_TOKEN
dockerSocket: process.env.DOCKER_SOCKET dockerSocket: process.env.DOCKER_SOCKET
supervisorImage: process.env.SUPERVISOR_IMAGE ? 'resin/rpi-supervisor' supervisorImage: checkString(process.env.SUPERVISOR_IMAGE) ? 'resin/rpi-supervisor'
configMountPoint: process.env.CONFIG_MOUNT_POINT ? '/mnt/mmcblk0p1/config.json' configMountPoint: checkString(process.env.CONFIG_MOUNT_POINT) ? '/mnt/mmcblk0p1/config.json'
ledFile: process.env.LED_FILE ? '/sys/class/leds/led0/brightness' ledFile: checkString(process.env.LED_FILE) ? '/sys/class/leds/led0/brightness'
bootstrapRetryDelay: checkInt(process.env.BOOTSTRAP_RETRY_DELAY_MS) ? 30000 bootstrapRetryDelay: checkInt(process.env.BOOTSTRAP_RETRY_DELAY_MS) ? 30000
restartSuccessTimeout: checkInt(process.env.RESTART_SUCCESS_TIMEOUT) ? 60000 restartSuccessTimeout: checkInt(process.env.RESTART_SUCCESS_TIMEOUT) ? 60000
appUpdatePollInterval: checkInt(process.env.APPLICATION_UPDATE_POLL_INTERVAL) ? 60000 appUpdatePollInterval: checkInt(process.env.APPLICATION_UPDATE_POLL_INTERVAL) ? 60000
successMessage: 'SUPERVISOR OK' successMessage: 'SUPERVISOR OK'
forceSecret: forceSecret:
api: process.env.RESIN_SUPERVISOR_SECRET ? null api: checkString(process.env.RESIN_SUPERVISOR_SECRET) ? null
logsChannel: process.env.RESIN_SUPERVISOR_LOGS_CHANNEL ? null logsChannel: checkString(process.env.RESIN_SUPERVISOR_LOGS_CHANNEL) ? null
vpnStatusPath: process.env.VPN_STATUS_PATH ? '/mnt/root/run/openvpn/vpn_status' vpnStatusPath: checkString(process.env.VPN_STATUS_PATH) ? '/mnt/root/run/openvpn/vpn_status'
checkInt: checkInt checkInt: checkInt
hostOsVersionPath: process.env.HOST_OS_VERSION_PATH ? '/mnt/root/etc/os-release' hostOsVersionPath: checkString(process.env.HOST_OS_VERSION_PATH) ? '/mnt/root/etc/os-release'
dockerRoot: dockerRoot dockerRoot: dockerRoot
btrfsRoot: process.env.BTRFS_ROOT ? "#{dockerRoot}/btrfs/subvolumes" btrfsRoot: checkString(process.env.BTRFS_ROOT) ? "#{dockerRoot}/btrfs/subvolumes"