Move config.json flag back to the database

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver
2018-12-11 13:53:10 +00:00
parent 19f8b75766
commit 91a6340563
2 changed files with 42 additions and 1 deletions

View File

@ -49,7 +49,6 @@ class Config extends EventEmitter {
supervisorOfflineMode: { source: 'config.json', default: false },
hostname: { source: 'config.json', mutable: true },
persistentLogging: { source: 'config.json', default: false, mutable: true },
localMode: { source: 'config.json', mutable: true, default: 'false' },
version: { source: 'func' },
currentApiKey: { source: 'func' },
@ -82,6 +81,7 @@ class Config extends EventEmitter {
pinDevice: { source: 'db', mutable: true, default: 'null' },
currentCommit: { source: 'db', mutable: true },
targetStateSet: { source: 'db', mutable: true, default: 'false' },
localMode: { source: 'db', mutable: true, default: 'false' },
};
public constructor({ db, configPath }: ConfigOpts) {

41
src/migrations/M00002.js Normal file
View File

@ -0,0 +1,41 @@
const fs = require('fs');
const configJsonPath = process.env.CONFIG_MOUNT_POINT;
const { checkTruthy } = require('../lib/validation');
exports.up = function (knex, Promise) {
return new Promise(resolve => {
if (!configJsonPath) {
console.log('Unable to locate config.json! Things may fail unexpectedly!');
return resolve(false);
}
fs.readFile(configJsonPath, (err, data) => {
if (err) {
console.log('Failed to read config.json! Things may fail unexpectedly!');
return resolve();
}
try {
const parsed = JSON.parse(data.toString());
if (parsed.localMode != null) {
return resolve(checkTruthy(parsed.localMode));
}
return resolve(false);
} catch (e) {
console.log('Failed to parse config.json! Things may fail unexpectedly!');
return resolve(false);
}
});
}).then(localMode => {
// We can be sure that this does not already exist in the db because of the previous
// migration
return knex('config').insert({
key: 'localMode',
value: localMode.toString(),
});
});
};
exports.down = function (knex, Promise) {
return Promise.reject(new Error('Not Implemented'));
};