mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-06 00:48:08 +02:00
Enable alternative ways for settings passwords (#101)
* Enable alternative ways for settings passwords: * the environment variable BW_PASSWORD * prefix the command line argument with "file:" and the password will read from the first line of that file * prefix the command line argument with "env:" and the password will be read from that environment variable * Appveyor fixes * Switch to using command options for password file and password env * Lowercase options
This commit is contained in:
parent
0092aac275
commit
fb7335b927
@ -14,6 +14,8 @@ import { Response } from '../models/response';
|
|||||||
|
|
||||||
import { MessageResponse } from '../models/response/messageResponse';
|
import { MessageResponse } from '../models/response/messageResponse';
|
||||||
|
|
||||||
|
import { NodeUtils } from '../../misc/nodeUtils';
|
||||||
|
|
||||||
export class LoginCommand {
|
export class LoginCommand {
|
||||||
protected validatedParams: () => Promise<any>;
|
protected validatedParams: () => Promise<any>;
|
||||||
protected success: () => Promise<MessageResponse>;
|
protected success: () => Promise<MessageResponse>;
|
||||||
@ -38,7 +40,12 @@ export class LoginCommand {
|
|||||||
return Response.badRequest('Email address is invalid.');
|
return Response.badRequest('Email address is invalid.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((password == null || password === '') && canInteract) {
|
if (password == null || password === '') {
|
||||||
|
if (cmd.passwordfile) {
|
||||||
|
password = await NodeUtils.readFirstLine(cmd.passwordfile);
|
||||||
|
} else if (cmd.passwordenv && process.env[cmd.passwordenv]) {
|
||||||
|
password = process.env[cmd.passwordenv];
|
||||||
|
} else if (canInteract) {
|
||||||
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
|
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
|
||||||
type: 'password',
|
type: 'password',
|
||||||
name: 'password',
|
name: 'password',
|
||||||
@ -46,6 +53,8 @@ export class LoginCommand {
|
|||||||
});
|
});
|
||||||
password = answer.password;
|
password = answer.password;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (password == null || password === '') {
|
if (password == null || password === '') {
|
||||||
return Response.badRequest('Master password is required.');
|
return Response.badRequest('Master password is required.');
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as readline from 'readline';
|
||||||
|
|
||||||
export class NodeUtils {
|
export class NodeUtils {
|
||||||
static mkdirpSync(targetDir: string, mode = '700', relative = false, relativeDir: string = null) {
|
static mkdirpSync(targetDir: string, mode = '700', relative = false, relativeDir: string = null) {
|
||||||
@ -13,4 +14,16 @@ export class NodeUtils {
|
|||||||
return dir;
|
return dir;
|
||||||
}, initialDir);
|
}, initialDir);
|
||||||
}
|
}
|
||||||
|
static readFirstLine(fileName: string) {
|
||||||
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
const readStream = fs.createReadStream(fileName, {encoding: 'utf8'});
|
||||||
|
const readInterface = readline.createInterface(readStream);
|
||||||
|
readInterface
|
||||||
|
.on('line', (line) => {
|
||||||
|
readStream.close();
|
||||||
|
resolve(line);
|
||||||
|
})
|
||||||
|
.on('error', (err) => reject(err));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user