Server deployment stuff

This commit is contained in:
John Lyon-Smith
2018-03-19 15:04:10 -07:00
parent 59c11d791d
commit faf99108e9
12 changed files with 164 additions and 33 deletions

View File

@@ -10,7 +10,7 @@ import util from 'util'
import autoBind from 'auto-bind2'
class SendMessageTool {
class AddUserTool {
constructor(toolName, log) {
autoBind(this)
this.toolName = toolName
@@ -20,7 +20,9 @@ class SendMessageTool {
async run() {
const mongoUri = config.get('uri.mongo')
new DB().connect(mongoUri).then((db) => {
try {
const db = await new DB().connect(mongoUri)
console.log(`Connected to MongoDB at ${mongoUri}`)
const User = db.User
@@ -33,18 +35,16 @@ class SendMessageTool {
let password = readlineSync.question('Password? ', {hideEchoBack: true})
let cr = credential()
util.promisify(cr.hash)(password).then((json) => {
user.passwordHash = JSON.parse(json)
const json = await util.promisify(cr.hash)(password)
return user.save()
}).then((savedUser) => {
console.log(`User is ${user}`)
process.exit(0)
}).catch((error) => {
console.log(`error: ${error.message}`)
process.exit(-1)
})
})
user.passwordHash = JSON.parse(json)
const savedUser = await user.save()
console.log(`User is ${user}`)
} catch(error) {
console.log(`error: ${error.message}`)
}
}
}
@@ -54,7 +54,7 @@ const log = {
warning: function() { console.error(chalk.yellow('warning:', [...arguments].join(' ')))}
}
const tool = new AddUserTool('add-user', log)
const tool = new AddUserTool('addUser', log)
tool.run(process.argv.slice(2)).then((exitCode) => {
process.exit(exitCode)