mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-30 08:10:34 +01:00
--passwordenv
doesn't work for for unlock (#347)
* - Add passwordenv parameter to unlock command - Add passwordfile parameter to unlock command - Adapt help message * Remove newline * Add warning if passwordenv var not found * Appease the linter * Refactor * Undo last commit
This commit is contained in:
parent
4656b6e383
commit
47308ef240
@ -14,23 +14,43 @@ import { PasswordVerificationRequest } from 'jslib-common/models/request/passwor
|
||||
import { Utils } from 'jslib-common/misc/utils';
|
||||
|
||||
import { HashPurpose } from 'jslib-common/enums/hashPurpose';
|
||||
import { NodeUtils } from 'jslib-common/misc/nodeUtils';
|
||||
import { ConsoleLogService } from 'jslib-common/services/consoleLog.service';
|
||||
|
||||
export class UnlockCommand {
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) { }
|
||||
private logService: ConsoleLogService;
|
||||
|
||||
async run(password: string, cmd: program.Command) {
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) {
|
||||
this.logService = new ConsoleLogService(false);
|
||||
}
|
||||
|
||||
async run(password: string, options: program.OptionValues) {
|
||||
const canInteract = process.env.BW_NOINTERACTION !== 'true';
|
||||
if ((password == null || password === '') && canInteract) {
|
||||
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
|
||||
type: 'password',
|
||||
name: 'password',
|
||||
message: 'Master password:',
|
||||
});
|
||||
password = answer.password;
|
||||
}
|
||||
if (password == null || password === '') {
|
||||
return Response.badRequest('Master password is required.');
|
||||
if (options.passwordfile) {
|
||||
password = await NodeUtils.readFirstLine(options.passwordfile);
|
||||
} else if (options.passwordenv) {
|
||||
if (process.env[options.passwordenv]) {
|
||||
password = process.env[options.passwordenv];
|
||||
} else {
|
||||
this.logService.warning(`Warning: Provided passwordenv ${options.passwordenv} is not set`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (password == null || password === '') {
|
||||
if (canInteract) {
|
||||
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
|
||||
type: 'password',
|
||||
name: 'password',
|
||||
message: 'Master password:',
|
||||
});
|
||||
|
||||
password = answer.password;
|
||||
} else {
|
||||
return Response.badRequest('Master password is required.');
|
||||
}
|
||||
}
|
||||
|
||||
this.setNewSessionKey();
|
||||
|
@ -202,6 +202,8 @@ export class Program extends BaseProgram {
|
||||
}
|
||||
this.processResponse(Response.error('Vault is locked.'), true);
|
||||
})
|
||||
.option('--passwordenv <passwordenv>', 'Environment variable storing your password')
|
||||
.option('--passwordfile <passwordfile>', 'Path to a file containing your password as its first line')
|
||||
.action(async (password, cmd) => {
|
||||
if (!cmd.check) {
|
||||
await this.exitIfNotAuthed();
|
||||
|
Loading…
Reference in New Issue
Block a user