fix lamassu-apply-defaults
This commit is contained in:
parent
577946ee52
commit
70c3f59628
2 changed files with 4 additions and 10 deletions
|
|
@ -4,13 +4,11 @@ const _ = require('lodash/fp')
|
||||||
|
|
||||||
// const db = require('../lib/db')
|
// const db = require('../lib/db')
|
||||||
const settingsLoader = require('../lib/settings-loader')
|
const settingsLoader = require('../lib/settings-loader')
|
||||||
const configManager = require('../lib/config-manager')
|
|
||||||
const schema = require('../lamassu-schema.json')
|
const schema = require('../lamassu-schema.json')
|
||||||
const newFields = []
|
const newFields = []
|
||||||
|
|
||||||
settingsLoader.loadLatest()
|
Promise.resolve()
|
||||||
.then(settings => {
|
.then(() => {
|
||||||
const config = settings.config
|
|
||||||
schema.groups.forEach(group => {
|
schema.groups.forEach(group => {
|
||||||
return group.fields.forEach(fieldCode => {
|
return group.fields.forEach(fieldCode => {
|
||||||
const field = schema.fields.find(r => r.code === fieldCode)
|
const field = schema.fields.find(r => r.code === fieldCode)
|
||||||
|
|
@ -18,9 +16,6 @@ settingsLoader.loadLatest()
|
||||||
if (_.isNil(field.default)) return
|
if (_.isNil(field.default)) return
|
||||||
if (group.cryptoScope === 'specific' || group.machineScope === 'specific') return
|
if (group.cryptoScope === 'specific' || group.machineScope === 'specific') return
|
||||||
|
|
||||||
const existing = configManager.scopedValue('global', 'global', fieldCode, config)
|
|
||||||
if (!_.isNil(existing)) return
|
|
||||||
|
|
||||||
return newFields.push({
|
return newFields.push({
|
||||||
fieldLocator: {
|
fieldLocator: {
|
||||||
fieldScope: {
|
fieldScope: {
|
||||||
|
|
@ -39,7 +34,7 @@ settingsLoader.loadLatest()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return settingsLoader.save({config: config.concat(newFields)})
|
return settingsLoader.save(newFields)
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Success.')
|
console.log('Success.')
|
||||||
|
|
|
||||||
|
|
@ -151,8 +151,7 @@ function validate (config) {
|
||||||
.then(() => validateRequires(config))
|
.then(() => validateRequires(config))
|
||||||
.then(arr => {
|
.then(arr => {
|
||||||
if (arr.length === 0) return config
|
if (arr.length === 0) return config
|
||||||
logger.error('Invalid configuration: %j', arr)
|
throw new Error('Invalid configuration:' + arr)
|
||||||
throw new Error('Invalid configuration')
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue