3 const argon2
= require('argon2');
4 const readline
= require('readline');
5 const stream
= require('stream');
6 const DB
= require('../src/db');
7 const Logger
= require('../src/logger');
8 const Config
= require('../config');
9 const config
= new Config(process
.env
.NODE_ENV
);
11 const logger
= new Logger(config
);
12 const db
= new DB(logger
, config
);
14 const identifier
= process
.argv
[2];
17 console
.log('missing user to add');
18 throw new Error('missing argument');
21 async
function readPassword(prompt
) {
22 const input
= process
.stdin
;
23 const output
= new stream
.Writable({
24 write: function (chunk
, encoding
, callback
) {
26 process
.stdout
.write(chunk
, encoding
);
31 const rl
= readline
.createInterface({ input
, output
, terminal: !!process
.stdin
.isTTY
});
36 return new Promise((resolve
) => {
37 rl
.question('', (answer
) => {
47 await db
.initialize();
48 const password
= await
readPassword('password: ');
49 const credential
= await argon2
.hash(password
, { type: argon2
.argon2id
});
50 console
.log(`\t${identifier}:${credential}`);
51 await db
.context(async (dbCtx
) => {
52 const result
= await db
.authenticationUpsert(dbCtx
, identifier
, credential
);
56 await db
._closeConnection();