Switch to local mode in unmanaged mode

Change-type: major
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2018-12-11 14:46:03 +00:00
parent 91a6340563
commit 5bb3820d6a
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
3 changed files with 22 additions and 3 deletions

View File

@ -149,5 +149,12 @@ export function createProviderFunctions(
]);
},
},
unmanaged: {
get: () => {
return config.get('apiEndpoint').then(apiEndpoint => {
return !apiEndpoint;
});
},
},
};
}

View File

@ -60,6 +60,7 @@ class Config extends EventEmitter {
mixpanelHost: { source: 'func' },
extendedEnvOptions: { source: 'func' },
fetchOptions: { source: 'func' },
unmanaged: { source: 'func' },
// NOTE: all 'db' values are stored and loaded as *strings*,
apiSecret: { source: 'db', mutable: true },

View File

@ -40,9 +40,20 @@ export class LocalModeManager {
}
});
const localMode = checkTruthy(
(await this.config.get('localMode')) || false,
);
// On startup, check if we're in unmanaged mode,
// as local mode needs to be set
let unmanagedLocalMode = false;
if (checkTruthy((await this.config.get('unmanaged')) || false)) {
console.log('Starting up in unmanaged mode, activating local mode');
await this.config.set({ localMode: true });
unmanagedLocalMode = true;
}
const localMode =
// short circuit the next get if we know we're in local mode
unmanagedLocalMode ||
checkTruthy((await this.config.get('localMode')) || false);
if (!localMode) {
// Remove any leftovers if necessary
await this.removeLocalModeArtifacts();