Skip to content

Commit

Permalink
Merge pull request #20 from interledger/feature/dj-admin
Browse files Browse the repository at this point in the history
[FEATURE] Add admin
  • Loading branch information
emschwartz committed Jan 7, 2016
2 parents 674a18f + 7aa1415 commit e80dd9e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
6 changes: 3 additions & 3 deletions scripts/accounts.js
Expand Up @@ -7,7 +7,7 @@ const Pathfinder = require('five-bells-sender/node_modules/five-bells-pathfind')

const pathfinder = new Pathfinder({
crawler: {
initialNodes: ['http://localhost:3001', 'http://localhost:3002']
initialLedgers: ['http://localhost:3001', 'http://localhost:3002']
}
})

Expand All @@ -16,10 +16,10 @@ co(function * () {
let ledgers = yield pathfinder.getLedgers()
console.log('Ledger\tAccount\tBalance')
for (let ledger of ledgers) {
let accounts = yield request(ledger.id + '/accounts', {json: true})
let accounts = yield request(ledger.uri + '/accounts', {json: true})
for (let account of accounts.body) {
console.log(
getPort(ledger.id) + '\t' +
getPort(ledger.uri) + '\t' +
getName(account.id) + '\t' +
account.balance)
}
Expand Down
7 changes: 6 additions & 1 deletion scripts/create-account.js
Expand Up @@ -5,12 +5,16 @@ const co = require('co')
const request = require('co-request')
const ledger = process.env.LEDGER
const username = process.env.USERNAME
const adminUser = process.env.ADMIN_USER
const adminPass = process.env.ADMIN_PASS

if (!ledger || !username) {
if (!ledger || !username || !adminUser || !adminPass) {
console.error('usage: create-account.js')
console.error('required env variables:')
console.error(' LEDGER')
console.error(' USERNAME')
console.error(' ADMIN_USER')
console.error(' ADMIN_PASS')
process.exit(1)
}

Expand All @@ -34,6 +38,7 @@ function * createAccount (ledger, name) {
let putAccountRes = yield request({
method: 'put',
url: account_uri,
auth: { user: adminUser, pass: adminPass },
json: true,
body: {
name: account_uri,
Expand Down
19 changes: 15 additions & 4 deletions src/lib/demo.js
Expand Up @@ -20,6 +20,9 @@ class Demo {
constructor (opts) {
const _this = this

this.adminUser = opts.adminUser
this.adminPass = opts.adminPass

this.numLedgers = opts.numLedgers
this.numTraders = opts.numTraders
this.barabasiAlbertConnectedCore = opts.barabasiAlbertConnectedCore || 2
Expand Down Expand Up @@ -56,7 +59,9 @@ class Demo {
LEDGER_DB_URI: 'sqlite://' + dbPath,
LEDGER_DB_SYNC: true,
LEDGER_HOSTNAME: 'localhost',
LEDGER_PORT: port
LEDGER_PORT: port,
LEDGER_ADMIN_USER: this.adminUser,
LEDGER_ADMIN_PASS: this.adminPass
},
cwd: './node_modules/five-bells-ledger',
cmd: 'npm start -- --color',
Expand Down Expand Up @@ -97,7 +102,9 @@ class Demo {
TRADER_MAX_HOLD_TIME: 60,
PATH: process.env.PATH,
TRADER_HOSTNAME: 'localhost',
TRADER_PORT: port
TRADER_PORT: port,
TRADER_ADMIN_USER: this.adminUser,
TRADER_ADMIN_PASS: this.adminPass
},
cwd: './node_modules/five-bells-trader',
cmd: 'npm start -- --color',
Expand All @@ -112,7 +119,9 @@ class Demo {
CRAWLER_INITIAL_LEDGERS: ledger,
VISUALIZATION_RECRAWL_INTERVAL: 30000,
HOSTNAME: 'localhost',
PORT: port
PORT: port,
ADMIN_USER: this.adminUser,
ADMIN_PASS: this.adminPass
},
cwd: './node_modules/five-bells-visualization',
cmd: 'npm start -- --color',
Expand All @@ -125,7 +134,9 @@ class Demo {
env: {
PATH: process.env.PATH,
LEDGER: ledger,
USERNAME: name
USERNAME: name,
ADMIN_USER: this.adminUser,
ADMIN_PASS: this.adminPass
},
cwd: './',
cmd: './scripts/create-account.js',
Expand Down
4 changes: 3 additions & 1 deletion src/services/config.js
Expand Up @@ -4,7 +4,9 @@ exports.graph = {
numLedgers: 8,
numTraders: 7,
barabasiAlbertConnectedCore: 2,
barabasiAlbertConnectionsPerNewNode: 2
barabasiAlbertConnectionsPerNewNode: 2,
adminUser: process.env.ADMIN_USER || 'admin',
adminPass: process.env.ADMIN_PASS || 'admin'
}

if (process.env.DEMO_NUM_LEDGERS) {
Expand Down

0 comments on commit e80dd9e

Please sign in to comment.