Allow special env vars with a callback which don't cause an app restart

This commit is contained in:
Pablo Carranza Vélez 2015-09-21 21:41:36 +00:00
parent 66a4bf4ab3
commit 941d3b15af

View File

@ -292,6 +292,16 @@ joinErrorMessages = (failures) ->
err.message or err
"#{failures.length} error#{s}: #{messages.join(' - ')}"
# Example callback function to enable/disable vpn
# enableVpn = (val) ->
# if val == '1' then console.log('Enabling VPN') else console.log('Disabling VPN')
specialActionEnvVars = {
'RESIN_OVERRIDE_LOCK': null
# @Praneeth: maybe add your vars here with a callback as value? e.g:
# 'RESIN_ENABLE_VPN': enableVpn
}
UPDATE_IDLE = 0
UPDATE_UPDATING = 1
UPDATE_REQUIRED = 2
@ -351,6 +361,8 @@ application.update = update = (force) ->
if app.environment_variable?
_.extend(env, app.environment_variable)
remoteAppEnvs[app.id] = env
env = _.pick env, (val, key) ->
!_.includes(key, _.keys(specialActionEnvVars))
return {
appId: '' + app.id
commit: app.commit
@ -361,6 +373,13 @@ application.update = update = (force) ->
remoteApps = _.indexBy(remoteApps, 'appId')
remoteAppIds = _.keys(remoteApps)
# @Praneeth: looks like this might be a good place to run the special functions,
# like turning vpn on/off if remoteAppEnvs has the corresponding variable.
_.map specialActionEnvVars, (specialActionCallback, key) ->
_.map remoteAppIds, (appId) ->
if remoteAppEnvs[appId][key]? && specialActionCallback?
specialActionCallback(remoteAppEnvs[appId][key])
apps = _.indexBy(apps, 'appId')
localApps = _.mapValues apps, (app) ->
_.pick(app, [ 'appId', 'commit', 'imageId', 'env' ])