From 941d3b15afde201c104882cdc2caed789b27f648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Carranza=20V=C3=A9lez?= Date: Mon, 21 Sep 2015 21:41:36 +0000 Subject: [PATCH] Allow special env vars with a callback which don't cause an app restart --- src/application.coffee | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/application.coffee b/src/application.coffee index 8439e480..3b9b83e8 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -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' ])