add wrapper around multiple rest sessions

This commit is contained in:
Bruno Windels 2018-09-11 16:18:27 +02:00
parent 48d95c228a
commit 827e6365bb
4 changed files with 111 additions and 35 deletions

View file

@ -18,6 +18,7 @@ const util = require('util');
const exec = util.promisify(require('child_process').exec);
const request = require('request-promise-native');
const RestSession = require('./session');
const RestMultiSession = require('./multi');
module.exports = class RestSessionCreator {
constructor(synapseSubdir, hsUrl, cwd) {
@ -26,6 +27,12 @@ module.exports = class RestSessionCreator {
this.cwd = cwd;
}
async createSessionRange(usernames, password) {
const sessionPromises = usernames.map((username) => this.createSession(username, password));
const sessions = await Promise.all(sessionPromises);
return new RestMultiSession(sessions);
}
async createSession(username, password) {
await this._register(username, password);
const authResult = await this._authenticate(username, password);