feat: decouple l-s entrypoint
This commit is contained in:
parent
2a2c1fccc8
commit
f4d6b5e454
48 changed files with 411 additions and 232 deletions
|
|
@ -1,9 +1,13 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var pgp = require('pg-promise')()
|
||||
var psqlUrl = require('../lib/options').postgresql
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
var db = pgp(psqlUrl)
|
||||
var pgp = require('pg-promise')()
|
||||
|
||||
const { PSQL_URL } = require('../lib/constants')
|
||||
|
||||
var db = pgp(PSQL_URL)
|
||||
|
||||
db.manyOrNone(`select * from transactions where incoming=false
|
||||
and stage='final_request' and authority='machine'`)
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const options = require('../lib/options-loader')()
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
if (!options.opts.frontCameraDir) {
|
||||
options.opts.frontCameraDir = '/opt/lamassu-server/frontcamera'
|
||||
const setEnvVariable = require('../tools/set-env-var')
|
||||
|
||||
fs.writeFileSync(options.path, JSON.stringify(options.opts, null, '\t'), 'utf8')
|
||||
if (!process.env.FRONT_CAMERA_DIR) {
|
||||
setEnvVariable('FRONT_CAMERA_DIR', '/opt/lamassu-server/frontcamera')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
const hdkey = require('ethereumjs-wallet/hdkey')
|
||||
const hkdf = require('futoin-hkdf')
|
||||
const db = require('../lib/db')
|
||||
|
|
@ -9,14 +11,14 @@ const mnemonicHelpers = require('../lib/mnemonic-helpers')
|
|||
const pify = require('pify')
|
||||
const fs = pify(require('fs'))
|
||||
|
||||
const options = require('../lib/options')
|
||||
const MNEMONIC_PATH = process.env.MNEMONIC_PATH
|
||||
|
||||
const defaultPrefixPath = "m/44'/60'/1'/0'"
|
||||
const paymentPrefixPath = "m/44'/60'/0'/0'"
|
||||
|
||||
const address = process.argv[2]
|
||||
|
||||
if (!options || !options.mnemonicPath) {
|
||||
if (!MNEMONIC_PATH) {
|
||||
console.error(`Unable to fetch mnemonic from your account!`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
|
@ -47,7 +49,7 @@ function searchForHdIndex (address) {
|
|||
}
|
||||
|
||||
function fetchMnemonic () {
|
||||
return fs.readFile(options.mnemonicPath, 'utf8')
|
||||
return fs.readFile(MNEMONIC_PATH, 'utf8')
|
||||
.then(mnemonic => computeSeed(mnemonic))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
#!/usr/bin/env node
|
||||
const FileStore = require('migrate/lib/file-store')
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
const db = require('../lib/db')
|
||||
const migrate = require('../lib/migrate')
|
||||
const options = require('../lib/options')
|
||||
const { asyncLocalStorage, defaultStore } = require('../lib/async-storage')
|
||||
|
||||
const MIGRATE_STATE_PATH = process.env.MIGRATE_STATE_PATH
|
||||
|
||||
const createMigration = `CREATE TABLE IF NOT EXISTS migrations (
|
||||
id serial PRIMARY KEY,
|
||||
data json NOT NULL
|
||||
|
|
@ -14,7 +20,7 @@ const select = 'select * from migrations limit 1'
|
|||
|
||||
const getMigrateFile = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
new FileStore(options.migrateStatePath).load((err, store) => {
|
||||
new FileStore(MIGRATE_STATE_PATH).load((err, store) => {
|
||||
if (err) return reject(err)
|
||||
return resolve(store)
|
||||
})
|
||||
|
|
@ -26,7 +32,7 @@ asyncLocalStorage.run(store, () => {
|
|||
db.none(createMigration)
|
||||
.then(() => Promise.all([db.oneOrNone(select), getMigrateFile()]))
|
||||
.then(([qResult, migrateFile]) => {
|
||||
process.env.SKIP_SERVER_LOGS = !(qResult && qResult.data.migrations.find(({ title }) => title === '1572524820075-server-support-logs.js'))
|
||||
process.env.SKIP_SERVER_LOGS = !(qResult && _.find(({ title }) => title === '1572524820075-server-support-logs.js', qResult.data.migrations ?? []))
|
||||
if (!qResult && migrateFile) {
|
||||
return db.none('insert into migrations (id, data) values (1, $1)', [migrateFile])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
const options = require('../lib/options')
|
||||
const MNEMONIC_PATH = process.env.MNEMONIC_PATH
|
||||
|
||||
const mnemonic = fs.readFileSync(options.mnemonicPath, 'utf8').trim()
|
||||
const mnemonic = fs.readFileSync(MNEMONIC_PATH, 'utf8').trim()
|
||||
console.log(mnemonic)
|
||||
|
|
|
|||
|
|
@ -2,22 +2,12 @@
|
|||
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const setEnvVariable = require('../tools/set-env-var')
|
||||
|
||||
const 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'
|
||||
}
|
||||
]
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
const options = require('../lib/options-loader')()
|
||||
|
||||
if (!options.opts.ofacSources) {
|
||||
options.opts.ofacSources = ofacSources
|
||||
fs.writeFileSync(options.path, JSON.stringify(options.opts, null, ' '), 'utf8')
|
||||
if (!process.env.OFAC_SOURCES_NAMES && !process.env.OFAC_SOURCES_URLS) {
|
||||
setEnvVariable('OFAC_SOURCES_NAMES', 'sdn_advanced,cons_advanced')
|
||||
setEnvVariable('OFAC_SOURCES_URLS', 'https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml,https://www.treasury.gov/ofac/downloads/sanctions/1.0/cons_advanced.xml')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,14 @@
|
|||
const fs = require('fs')
|
||||
const hkdf = require('futoin-hkdf')
|
||||
|
||||
const options = require('../lib/options')
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
const mnemonicHelpers = require('../lib/mnemonic-helpers')
|
||||
|
||||
const mnemonic = fs.readFileSync(options.mnemonicPath, 'utf8').trim()
|
||||
const MNEMONIC_PATH = process.env.MNEMONIC_PATH
|
||||
|
||||
const mnemonic = fs.readFileSync(MNEMONIC_PATH, 'utf8').trim()
|
||||
const masterSeed = mnemonicHelpers.toEntropyBuffer(mnemonic)
|
||||
|
||||
console.log(hkdf(masterSeed, 16, { salt: 'lamassu-server-salt', info: 'operator-id' }).toString('hex'))
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
const { asyncLocalStorage, defaultStore } = require('../lib/async-storage')
|
||||
const userManagement = require('../lib/new-admin/graphql/modules/userManagement')
|
||||
const authErrors = require('../lib/new-admin/graphql/errors/authentication')
|
||||
const options = require('../lib/options')
|
||||
|
||||
const name = process.argv[2]
|
||||
const role = process.argv[3]
|
||||
const domain = options.hostname
|
||||
const domain = process.env.HOSTNAME
|
||||
|
||||
if (!domain) {
|
||||
console.error('No hostname configured in lamassu.json')
|
||||
console.error('No hostname configured in the environment')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,25 +6,26 @@ const fs = require('fs')
|
|||
const path = require('path')
|
||||
const os = require('os')
|
||||
const mnemonicHelpers = require('../lib/mnemonic-helpers')
|
||||
const options = require('../lib/options-loader')()
|
||||
const setEnvVariable = require('../tools/set-env-var')
|
||||
|
||||
if (!options.opts.mnemonicPath && options.opts.seedPath) {
|
||||
const seed = fs.readFileSync(options.opts.seedPath, 'utf8').trim()
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
if (!process.env.MNEMONIC_PATH && process.env.SEED_PATH) {
|
||||
const seed = fs.readFileSync(process.env.SEED_PATH, 'utf8').trim()
|
||||
const mnemonic = mnemonicHelpers.fromSeed(seed)
|
||||
|
||||
if (process.argv[2] === '--prod') {
|
||||
options.opts.mnemonicPath = path.resolve('/etc', 'lamassu', 'mnemonics', 'mnemonic.txt')
|
||||
setEnvVariable('MNEMONIC_PATH', path.resolve('/etc', 'lamassu', 'mnemonics', 'mnemonic.txt'))
|
||||
} else {
|
||||
options.opts.mnemonicPath = path.resolve(os.homedir(), '.lamassu', 'mnemonics', 'mnemonic.txt')
|
||||
setEnvVariable('MNEMONIC_PATH', path.resolve(os.homedir(), '.lamassu', 'mnemonics', 'mnemonic.txt'))
|
||||
}
|
||||
|
||||
if (!fs.existsSync(path.dirname(options.opts.mnemonicPath))) {
|
||||
fs.mkdirSync(path.dirname(options.opts.mnemonicPath))
|
||||
if (!fs.existsSync(path.dirname(process.env.MNEMONIC_PATH))) {
|
||||
fs.mkdirSync(path.dirname(process.env.MNEMONIC_PATH))
|
||||
}
|
||||
|
||||
if (!fs.existsSync(options.opts.mnemonicPath)) {
|
||||
fs.writeFileSync(options.opts.mnemonicPath, mnemonic, 'utf8')
|
||||
if (!fs.existsSync(process.env.MNEMONIC_PATH)) {
|
||||
fs.writeFileSync(process.env.MNEMONIC_PATH, mnemonic, 'utf8')
|
||||
}
|
||||
|
||||
fs.writeFileSync(options.path, JSON.stringify(options.opts, null, '\t'), 'utf8')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,13 @@
|
|||
'use strict'
|
||||
|
||||
const pgp = require('pg-promise')()
|
||||
const psqlUrl = require('../lib/options').postgresql
|
||||
|
||||
const db = pgp(psqlUrl)
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
const { PSQL_URL } = require('../lib/constants')
|
||||
|
||||
const db = pgp(PSQL_URL)
|
||||
|
||||
db.many('select data from user_config', 'exchanges')
|
||||
.then(rows => {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path')
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') })
|
||||
|
||||
const login = require('../lib/admin/login')
|
||||
const options = require('../lib/options')
|
||||
|
||||
const name = process.argv[2]
|
||||
const domain = options.hostname
|
||||
const domain = process.env.HOSTNAME
|
||||
|
||||
if (!domain) {
|
||||
console.error('No hostname configured in lamassu.json')
|
||||
console.error('No hostname configured in the environment')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue