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,24 +14,44 @@ import { PasswordVerificationRequest } from 'jslib-common/models/request/passwor
|
|||||||
import { Utils } from 'jslib-common/misc/utils';
|
import { Utils } from 'jslib-common/misc/utils';
|
||||||
|
|
||||||
import { HashPurpose } from 'jslib-common/enums/hashPurpose';
|
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 {
|
export class UnlockCommand {
|
||||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
private logService: ConsoleLogService;
|
||||||
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) { }
|
|
||||||
|
|
||||||
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';
|
const canInteract = process.env.BW_NOINTERACTION !== 'true';
|
||||||
if ((password == null || password === '') && canInteract) {
|
if (password == null || password === '') {
|
||||||
|
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 })({
|
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
|
||||||
type: 'password',
|
type: 'password',
|
||||||
name: 'password',
|
name: 'password',
|
||||||
message: 'Master password:',
|
message: 'Master password:',
|
||||||
});
|
});
|
||||||
|
|
||||||
password = answer.password;
|
password = answer.password;
|
||||||
}
|
} else {
|
||||||
if (password == null || password === '') {
|
|
||||||
return Response.badRequest('Master password is required.');
|
return Response.badRequest('Master password is required.');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.setNewSessionKey();
|
this.setNewSessionKey();
|
||||||
const email = await this.userService.getEmail();
|
const email = await this.userService.getEmail();
|
||||||
|
@ -202,6 +202,8 @@ export class Program extends BaseProgram {
|
|||||||
}
|
}
|
||||||
this.processResponse(Response.error('Vault is locked.'), true);
|
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) => {
|
.action(async (password, cmd) => {
|
||||||
if (!cmd.check) {
|
if (!cmd.check) {
|
||||||
await this.exitIfNotAuthed();
|
await this.exitIfNotAuthed();
|
||||||
|
Loading…
Reference in New Issue
Block a user