config-validator to consider default values from schema (#139)
* config-validator to consider default values from schema * fix with relative json schema path * remove lamassuServerPath config on lamassu-migrate-options
This commit is contained in:
parent
d28c6ae691
commit
6fdb3e8834
7 changed files with 13 additions and 16 deletions
|
|
@ -78,7 +78,6 @@ cat <<EOF > $CONFIG_DIR/lamassu.json
|
|||
"hostname": "$DOMAIN",
|
||||
"logLevel": "debug",
|
||||
"lamassuCaPath": "$LAMASSU_CA_PATH",
|
||||
"lamassuServerPath": "$PWD",
|
||||
"migrateStatePath": "$MIGRATE_STATE_PATH",
|
||||
"ofacDataDir": "$OFAC_DATA_DIR",
|
||||
"ofacSources": [
|
||||
|
|
|
|||
1
install
1
install
|
|
@ -158,7 +158,6 @@ cat <<EOF > $CONFIG_DIR/lamassu.json
|
|||
"keyPath": "$SERVER_KEY_PATH",
|
||||
"hostname": "$IP",
|
||||
"logLevel": "info",
|
||||
"lamassuServerPath": "$NODE_MODULES/lamassu-server",
|
||||
"migrateStatePath": "$MIGRATE_STATE_PATH",
|
||||
"blockchainDir": "$BLOCKCHAIN_DIR",
|
||||
"ofacDataDir": "$OFAC_DATA_DIR",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
"certPath": "/etc/ssl/certs/Lamassu_OP.pem",
|
||||
"keyPath": "/etc/ssl/private/Lamassu_OP.key",
|
||||
"logLevel": "info",
|
||||
"lamassuServerPath": "/usr/local/share/.config/yarn/global/node_modules/lamassu-server",
|
||||
"migrateStatePath": "/etc/lamassu/.migrate",
|
||||
"blockchainDir": "/mnt/blockchains",
|
||||
"ofacDataDir": "/opt/lamassu-server/sanctions",
|
||||
|
|
|
|||
|
|
@ -100,8 +100,10 @@ app.post('/api/account', (req, res) => {
|
|||
.then(() => dbNotify())
|
||||
})
|
||||
|
||||
app.get('/api/config/:config', (req, res) =>
|
||||
config.fetchConfigGroup(req.params.config).then(c => res.json(c)))
|
||||
app.get('/api/config/:config', (req, res, next) =>
|
||||
config.fetchConfigGroup(req.params.config)
|
||||
.then(c => res.json(c))
|
||||
.catch(next))
|
||||
|
||||
app.post('/api/config', (req, res, next) => {
|
||||
config.saveConfigGroup(req.body)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
const pify = require('pify')
|
||||
const fs = pify(require('fs'))
|
||||
const path = require('path')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const currencies = require('../../currencies.json')
|
||||
|
|
@ -9,16 +6,13 @@ const countries = require('../../countries.json')
|
|||
const settingsLoader = require('../settings-loader')
|
||||
|
||||
const db = require('../db')
|
||||
const options = require('../options')
|
||||
const configManager = require('../config-manager')
|
||||
const configValidate = require('../config-validate')
|
||||
const machineLoader = require('../machine-loader')
|
||||
const jsonSchema = require('../../lamassu-schema.json')
|
||||
|
||||
function fetchSchema () {
|
||||
const schemaPath = path.resolve(options.lamassuServerPath, 'lamassu-schema.json')
|
||||
|
||||
return fs.readFile(schemaPath)
|
||||
.then(JSON.parse)
|
||||
return _.cloneDeep(jsonSchema)
|
||||
}
|
||||
|
||||
function fetchConfig () {
|
||||
|
|
|
|||
|
|
@ -52,8 +52,9 @@ function satisfiesRequire (config, cryptos, machineList, field, anyFields, allFi
|
|||
const isBlank = _.isNil(configManager.scopedValue(scope[0], scope[1], fieldCode, config))
|
||||
const isRequired = (_.isEmpty(anyFields) || isAnyEnabled()) &&
|
||||
(_.isEmpty(allFields) || areAllEnabled())
|
||||
const hasDefault = !_.isNil(_.get('default', field))
|
||||
|
||||
const isValid = isRequired ? !isBlank : true
|
||||
const isValid = !isRequired || !isBlank || hasDefault
|
||||
|
||||
return isValid
|
||||
})
|
||||
|
|
|
|||
|
|
@ -25,11 +25,14 @@ async function run () {
|
|||
const currentOpts = options.opts
|
||||
|
||||
// check if there are new options to add
|
||||
const result = _.mergeAll([defaultOpts, currentOpts])
|
||||
const shouldMigrate = !_.isEqual(result, currentOpts)
|
||||
let result = _.mergeAll([defaultOpts, currentOpts])
|
||||
const shouldMigrate = !_.isEqual(result, currentOpts) || _.has('lamassuServerPath', result)
|
||||
|
||||
// write the resulting lamassu.json
|
||||
if (shouldMigrate) {
|
||||
// remove old lamassuServerPath config
|
||||
result = _.omit('lamassuServerPath', result)
|
||||
|
||||
const newOpts = _.pick(_.difference(_.keys(result), _.keys(currentOpts)), result)
|
||||
console.log('Adding options', newOpts)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue