migrate-options unit test added
This commit is contained in:
parent
dc1ed52357
commit
cdfc84a96a
2 changed files with 65 additions and 27 deletions
|
|
@ -13,7 +13,7 @@ const paths = _.wrap(_.split, path.sep)
|
|||
// /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => 3
|
||||
const indexOfLs = _.flow(paths, _.wrap(_.indexOf, 'lamassu-server'))
|
||||
|
||||
module.exports = {run, mapKeyValuesDeep}
|
||||
module.exports = {run, mapKeyValuesDeep, updateOptionBasepath}
|
||||
|
||||
function mapKeyValuesDeep (cb, obj, key) {
|
||||
if (_.isArray(obj)) {
|
||||
|
|
@ -25,6 +25,32 @@ function mapKeyValuesDeep (cb, obj, key) {
|
|||
}
|
||||
}
|
||||
|
||||
function updateOptionBasepath (result, optionName) {
|
||||
const currentPath = _.get(optionName, result)
|
||||
|
||||
// process only keys that contains
|
||||
// lamassu-server dir in its path
|
||||
const i = indexOfLs(currentPath)
|
||||
if (i === -1) {
|
||||
return
|
||||
}
|
||||
|
||||
// workout the relative path
|
||||
// /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => certs/Lamassu_OP.pem
|
||||
const rPath = _.drop(i + 1, paths(currentPath))
|
||||
|
||||
// prepend the current lamassu-server path
|
||||
// certs/Lamassu_OP.pem => /usr/local/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem
|
||||
const newPath = _.join(path.sep, _.concat([currentBasePath], rPath))
|
||||
|
||||
// update this option
|
||||
// if the value has changed
|
||||
if (!_.isEqual(currentPath, newPath)) {
|
||||
console.log(`Migrating option ${optionName} to new path ${newPath}`)
|
||||
result[optionName] = newPath
|
||||
}
|
||||
}
|
||||
|
||||
async function run () {
|
||||
// load defaults
|
||||
const defaultOpts = require('../lamassu-default')
|
||||
|
|
@ -39,31 +65,14 @@ async function run () {
|
|||
// get all the options
|
||||
// that ends with "Path" suffix
|
||||
console.log(`Detected lamassu-server basepath: ${currentBasePath}`)
|
||||
_.map(optionName => {
|
||||
const currentPath = _.get(optionName, result)
|
||||
|
||||
// process only keys that contains
|
||||
// lamassu-server dir in its path
|
||||
const i = indexOfLs(currentPath)
|
||||
if (i === -1) {
|
||||
return
|
||||
}
|
||||
|
||||
// workout the relative path
|
||||
// /usr/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem => certs/Lamassu_OP.pem
|
||||
const rPath = _.drop(i + 1, paths(currentPath))
|
||||
|
||||
// prepend the current lamassu-server path
|
||||
// certs/Lamassu_OP.pem => /usr/local/lib/node_modules/lamassu-server/certs/Lamassu_OP.pem
|
||||
const newPath = _.join(path.sep, _.concat([currentBasePath], rPath))
|
||||
|
||||
// update this option
|
||||
// if the value has changed
|
||||
if (!_.isEqual(currentPath, newPath)) {
|
||||
console.log(`Migrating option ${optionName} to new path ${newPath}`)
|
||||
result[optionName] = newPath
|
||||
}
|
||||
}, ['seedPath', 'caPath', 'certPath', 'keyPath', 'lamassuCaPath'])
|
||||
_.each(_.wrap(updateOptionBasepath, result),
|
||||
[
|
||||
'seedPath',
|
||||
'caPath',
|
||||
'certPath',
|
||||
'keyPath',
|
||||
'lamassuCaPath'
|
||||
])
|
||||
|
||||
const shouldMigrate = !_.isEqual(result, currentOpts) || _.has('lamassuServerPath', result)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue