Adding test user
This commit is contained in:
24
server/ops
Executable file
24
server/ops
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
script_dir=$(dirname $0)
|
||||
script="${script_dir}/src/bin/$1"
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
echo "usage: $(basename $0) <command>"
|
||||
echo ""
|
||||
echo "Available scripts are"
|
||||
ls -1 ${script_dir}/src/bin
|
||||
exit -1
|
||||
fi
|
||||
|
||||
|
||||
# For scripts that need config access
|
||||
export NODE_CONFIG_DIR="${script_dir}/config"
|
||||
|
||||
if [[ ! -e "${script}" ]]; then
|
||||
echo error: Script ${script} does not exist
|
||||
exit -1
|
||||
fi
|
||||
|
||||
shift
|
||||
# See https://stackoverflow.com/questions/448407/bash-script-to-receive-and-repass-quoted-parameters
|
||||
babel-node -- "${script}" "$@"
|
||||
5
server/package-lock.json
generated
5
server/package-lock.json
generated
@@ -5434,6 +5434,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"readline-sync": {
|
||||
"version": "1.4.9",
|
||||
"resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.9.tgz",
|
||||
"integrity": "sha1-PtqOZfI80qF+YTAbHwADOWr17No="
|
||||
},
|
||||
"redis": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz",
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
"passport-http-bearer": "^1.0.1",
|
||||
"pino": "^4.10.1",
|
||||
"pino-pretty-express": "^1.0.4",
|
||||
"readline-sync": "^1.4.9",
|
||||
"redis": "^2.7.1",
|
||||
"redis-rstream": "^0.1.3",
|
||||
"regexp-pattern": "^1.0.4",
|
||||
|
||||
@@ -3,7 +3,7 @@ import path from 'path'
|
||||
import timers from 'timers'
|
||||
import autoBind from 'auto-bind2'
|
||||
|
||||
export class DARServer {
|
||||
export class ServerTool {
|
||||
constructor(toolName, log) {
|
||||
autoBind(this)
|
||||
this.toolName = toolName
|
||||
37
server/src/bin/addUser.js
Normal file
37
server/src/bin/addUser.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import path from 'path'
|
||||
import config from 'config'
|
||||
import mongoose from 'mongoose'
|
||||
import { DB } from '../database'
|
||||
import credential from 'credential'
|
||||
import readlineSync from 'readline-sync'
|
||||
import crypto from 'crypto'
|
||||
import urlSafeBase64 from 'urlsafe-base64'
|
||||
import util from 'util'
|
||||
|
||||
const mongoUri = config.get('uri.mongo')
|
||||
|
||||
new DB().connect(mongoUri).then((db) => {
|
||||
console.log(`Connected to MongoDB at ${mongoUri}`)
|
||||
|
||||
const User = db.User
|
||||
let user = new User({
|
||||
role: "administrator"
|
||||
})
|
||||
user.firstName = readlineSync.question('First name? ')
|
||||
user.lastName = readlineSync.question('Last name? ')
|
||||
user.email = readlineSync.question('Email? ')
|
||||
let password = readlineSync.question('Password? ', {hideEchoBack: true})
|
||||
let cr = credential()
|
||||
|
||||
util.promisify(cr.hash)(password).then((json) => {
|
||||
user.passwordHash = JSON.parse(json)
|
||||
|
||||
return user.save()
|
||||
}).then((savedUser) => {
|
||||
console.log(`User is ${user}`)
|
||||
process.exit(0)
|
||||
}).catch((error) => {
|
||||
console.log(`error: ${error.message}`)
|
||||
process.exit(-1)
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
import { DARServer } from './DARServer'
|
||||
import { ServerTool } from './ServerTool'
|
||||
import pino from 'pino'
|
||||
import * as pinoExpress from 'pino-pretty-express'
|
||||
import path from 'path'
|
||||
@@ -18,7 +18,7 @@ if (isProduction) {
|
||||
log = pino({ name: serviceName }, pretty)
|
||||
}
|
||||
|
||||
const tool = new DARServer(path.basename(process.argv[1], '.js'), log)
|
||||
const tool = new ServerTool(path.basename(process.argv[1], '.js'), log)
|
||||
|
||||
tool.run(process.argv.slice(2)).then((exitCode) => {
|
||||
process.exitCode = exitCode
|
||||
Reference in New Issue
Block a user