Put sources in lamassu.json
This commit is contained in:
parent
b72f5549a5
commit
65f0e852d0
2 changed files with 56 additions and 47 deletions
|
|
@ -80,7 +80,17 @@ cat <<EOF > $CONFIG_DIR/lamassu.json
|
|||
"lamassuCaPath": "$LAMASSU_CA_PATH",
|
||||
"lamassuServerPath": "$PWD",
|
||||
"migrateStatePath": "$MIGRATE_STATE_PATH",
|
||||
"ofacDataDir": "$OFAC_DATA_DIR"
|
||||
"ofacDataDir": "$OFAC_DATA_DIR",
|
||||
"ofacSources": [
|
||||
{
|
||||
"name": "sdn_advanced",
|
||||
"url": "https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml"
|
||||
},
|
||||
{
|
||||
"name": "cons_advanced",
|
||||
"url": "https://www.treasury.gov/ofac/downloads/sanctions/1.0/cons_advanced.xml"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ const _ = require('lodash/fp')
|
|||
|
||||
const OFAC_DATA_DIR = options.ofacDataDir
|
||||
const OFAC_SOURCES_DIR = path.join(OFAC_DATA_DIR, 'sources')
|
||||
const OFAC_SOURCES_FILE = path.join(OFAC_DATA_DIR, 'sources.json')
|
||||
const OFAC_ETAGS_FILE = path.join(OFAC_DATA_DIR, 'etags.json')
|
||||
const DOWNLOAD_DIR = path.resolve('/tmp')
|
||||
|
||||
|
||||
const mkdir = util.promisify(fs.mkdir)
|
||||
const readFile = util.promisify(fs.readFile)
|
||||
const writeFile = util.promisify(fs.writeFile)
|
||||
const rename = util.promisify(fs.rename)
|
||||
|
|
@ -47,9 +47,8 @@ const promiseGetEtag = (source) => {
|
|||
|
||||
const download = _.curry((dstDir, source) => {
|
||||
console.log("download", source)
|
||||
const {url: sourceUrl} = source
|
||||
const fileName = path.basename(sourceUrl)
|
||||
const dstFile = path.join(dstDir, fileName)
|
||||
const {name, url: sourceUrl} = source
|
||||
const dstFile = path.join(dstDir, name + '.xml')
|
||||
const file = fs.createWriteStream(dstFile)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
@ -99,15 +98,15 @@ const moveToSourcesDir = srcFile => {
|
|||
}
|
||||
|
||||
|
||||
function update () {
|
||||
const update = () => mkdir(OFAC_DATA_DIR).catch(err => null)
|
||||
.then(() => mkdir(OFAC_SOURCES_DIR)).catch(err => null)
|
||||
.then(() => writeFile(OFAC_ETAGS_FILE, '{}', {encoding: 'utf-8', flag: 'wx'}))
|
||||
.catch(err => null)
|
||||
.then(() => {
|
||||
const promiseOldEtags = readFile(OFAC_ETAGS_FILE, {encoding: 'utf-8'})
|
||||
.then(json => JSON.parse(json) || {})
|
||||
|
||||
const promiseNewEtags = readFile(OFAC_SOURCES_FILE, {encoding: 'utf-8'})
|
||||
.then(json => {
|
||||
const obj = JSON.parse(json)
|
||||
return obj ? obj.sources : []
|
||||
})
|
||||
const promiseNewEtags = Promise.resolve(options.ofacSources || [])
|
||||
.then(sources => Promise.all(_.map(promiseGetEtag, sources))
|
||||
.then(etags => _.map(
|
||||
([source, etag]) => ({...source, etag}),
|
||||
|
|
@ -150,6 +149,6 @@ function update () {
|
|||
return Promise.all([updateEtags, ...moves, ...deletions])
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = {update}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue