feat: decouple l-s entrypoint
This commit is contained in:
parent
2a2c1fccc8
commit
f4d6b5e454
48 changed files with 411 additions and 232 deletions
|
|
@ -4,23 +4,24 @@ const util = require('util')
|
|||
const loader = require('./loading')
|
||||
const matcher = require('./matching')
|
||||
const nameUtils = require('./name-utils')
|
||||
const options = require('../options')
|
||||
const _ = require('lodash/fp')
|
||||
const logger = require('../logger')
|
||||
|
||||
const debugLog = require('../pp')(__filename) // KOSTIS TODO: remove
|
||||
|
||||
const OFAC_DATA_DIR = process.env.OFAC_DATA_DIR
|
||||
|
||||
let structs = null
|
||||
|
||||
const readdir = util.promisify(fs.readdir)
|
||||
|
||||
function load () {
|
||||
if (!options.ofacDataDir) {
|
||||
const message = 'The ofacDataDir option has not been set in lamassu.json'
|
||||
if (!OFAC_DATA_DIR) {
|
||||
const message = 'The ofacDataDir option has not been set in the environment'
|
||||
return Promise.reject(new Error(message))
|
||||
}
|
||||
|
||||
const ofacSourcesDir = path.join(options.ofacDataDir, 'sources')
|
||||
const ofacSourcesDir = path.join(OFAC_DATA_DIR, 'sources')
|
||||
|
||||
return readdir(ofacSourcesDir)
|
||||
.then(_.flow(
|
||||
|
|
|
|||
|
|
@ -4,12 +4,23 @@ const url = require('url')
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const util = require('util')
|
||||
const options = require('../options')
|
||||
const _ = require('lodash/fp')
|
||||
const logger = require('../logger')
|
||||
|
||||
const DOWNLOAD_DIR = path.resolve('/tmp')
|
||||
|
||||
const OFAC_DATA_DIR = process.env.OFAC_DATA_DIR
|
||||
const OFAC_SOURCES_NAMES = process.env.OFAC_SOURCES_NAMES.split(',')
|
||||
const OFAC_SOURCES_URLS = process.env.OFAC_SOURCES_URLS.split(',')
|
||||
|
||||
const ofacSources = _.map(
|
||||
it => ({
|
||||
name: it[0],
|
||||
url: it[1]
|
||||
}),
|
||||
_.zip(OFAC_SOURCES_NAMES, OFAC_SOURCES_URLS)
|
||||
)
|
||||
|
||||
function mkdir (path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.mkdir(path, err => {
|
||||
|
|
@ -97,14 +108,12 @@ const moveToSourcesDir = (srcFile, ofacSourcesDir) => {
|
|||
}
|
||||
|
||||
function update () {
|
||||
const OFAC_DATA_DIR = options.ofacDataDir
|
||||
|
||||
if (!OFAC_DATA_DIR) {
|
||||
throw new Error('ofacDataDir must be defined in lamassu.json')
|
||||
throw new Error('ofacDataDir must be defined in the environment')
|
||||
}
|
||||
|
||||
if (!options.ofacSources) {
|
||||
logger.error('ofacSources must be defined in lamassu.json')
|
||||
if (!ofacSources) {
|
||||
logger.error('ofacSources must be defined in the environment')
|
||||
}
|
||||
|
||||
const OFAC_SOURCES_DIR = path.join(OFAC_DATA_DIR, 'sources')
|
||||
|
|
@ -125,7 +134,7 @@ function update () {
|
|||
return {}
|
||||
})
|
||||
|
||||
const promiseNewEtags = Promise.resolve(options.ofacSources || [])
|
||||
const promiseNewEtags = Promise.resolve(ofacSources || [])
|
||||
.then(sources => Promise.all(_.map(promiseGetEtag, sources))
|
||||
.then(etags => _.map(
|
||||
([source, etag]) => ({...source, etag}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue