Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
prompt for unlock if can interact
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Oct 21, 2019
1 parent 2688520 commit e7450d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jslib
3 changes: 2 additions & 1 deletion src/commands/export.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class ExportCommand {
constructor(private cryptoService: CryptoService, private exportService: ExportService) { }

async run(password: string, cmd: program.Command): Promise<Response> {
if (password == null || password === '') {
const canInteract = process.stdout.isTTY && process.env.BW_NOINTERACTION !== 'true';
if ((password == null || password === '') && canInteract) {
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
type: 'password',
name: 'password',
Expand Down
3 changes: 2 additions & 1 deletion src/commands/unlock.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class UnlockCommand {
private cryptoFunctionService: CryptoFunctionService) { }

async run(password: string, cmd: program.Command) {
if (password == null || password === '') {
const canInteract = process.stdout.isTTY && process.env.BW_NOINTERACTION !== 'true';
if ((password == null || password === '') && canInteract) {
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
type: 'password',
name: 'password',
Expand Down
17 changes: 16 additions & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class Program extends BaseProgram {
.option('--raw', 'Return raw output instead of a descriptive message.')
.option('--response', 'Return a JSON formatted version of response output.')
.option('--quiet', 'Don\'t return anything to stdout.')
.option('--nointeraction', 'Do not prompt for interactive user input.')
.option('--session <session>', 'Pass session key instead of reading from env.')
.version(this.main.platformUtilsService.getApplicationVersion(), '-v, --version');

Expand All @@ -64,6 +65,10 @@ export class Program extends BaseProgram {
process.env.BW_RESPONSE = 'true';
});

program.on('option:nointeraction', () => {
process.env.BW_NOINTERACTION = 'true';
});

program.on('option:session', (key) => {
process.env.BW_SESSION = key;
});
Expand Down Expand Up @@ -640,7 +645,17 @@ export class Program extends BaseProgram {
await this.exitIfNotAuthed();
const hasKey = await this.main.cryptoService.hasKey();
if (!hasKey) {
this.processResponse(Response.error('Vault is locked.'), true);
const canInteract = process.stdout.isTTY && process.env.BW_NOINTERACTION !== 'true';
if (canInteract) {
const command = new UnlockCommand(this.main.cryptoService, this.main.userService,
this.main.cryptoFunctionService);
const response = await command.run(null, null);
if (!response.success) {
this.processResponse(response, true);
}
} else {
this.processResponse(Response.error('Vault is locked.'), true);
}
}
}
}

0 comments on commit e7450d2

Please sign in to comment.