unmanaged: Default to local mode in target state when unmanaged

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2018-12-17 10:49:03 +00:00
parent 151af309fb
commit c533631f70
No known key found for this signature in database
GPG Key ID: 49690ED87032539F

View File

@ -75,11 +75,16 @@ module.exports = class DeviceConfig
db('deviceConfig').update(confToUpdate)
getTarget: ({ initial = false } = {}) =>
@db.models('deviceConfig').select('targetValues')
.then ([ devConfig ]) =>
Promise.all([
@config.get('unmanaged')
@db.models('deviceConfig').select('targetValues')
])
.then ([unmanaged, [ devConfig ]]) =>
conf = JSON.parse(devConfig.targetValues)
if initial or !conf.SUPERVISOR_VPN_CONTROL?
conf.SUPERVISOR_VPN_CONTROL = 'true'
if unmanaged and !conf.SUPERVISOR_LOCAL_MODE?
conf.SUPERVISOR_LOCAL_MODE = 'true'
for own k, { envVarName, defaultValue } of @configKeys
conf[envVarName] ?= defaultValue
return conf