Fix unlock env and passwordfile (#352)
* Handle null options * Pass in ConsoleLogService dependency
This commit is contained in:
parent
f0c1f1b16b
commit
230e00e423
|
@ -18,19 +18,17 @@ import { NodeUtils } from 'jslib-common/misc/nodeUtils';
|
|||
import { ConsoleLogService } from 'jslib-common/services/consoleLog.service';
|
||||
|
||||
export class UnlockCommand {
|
||||
private logService: ConsoleLogService;
|
||||
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) {
|
||||
this.logService = new ConsoleLogService(false);
|
||||
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService,
|
||||
private logService: ConsoleLogService) {
|
||||
}
|
||||
|
||||
async run(password: string, options: program.OptionValues) {
|
||||
const canInteract = process.env.BW_NOINTERACTION !== 'true';
|
||||
if (password == null || password === '') {
|
||||
if (options.passwordfile) {
|
||||
if (options?.passwordfile) {
|
||||
password = await NodeUtils.readFirstLine(options.passwordfile);
|
||||
} else if (options.passwordenv) {
|
||||
} else if (options?.passwordenv) {
|
||||
if (process.env[options.passwordenv]) {
|
||||
password = process.env[options.passwordenv];
|
||||
} else {
|
||||
|
|
|
@ -208,7 +208,7 @@ export class Program extends BaseProgram {
|
|||
if (!cmd.check) {
|
||||
await this.exitIfNotAuthed();
|
||||
const command = new UnlockCommand(this.main.cryptoService, this.main.userService,
|
||||
this.main.cryptoFunctionService, this.main.apiService);
|
||||
this.main.cryptoFunctionService, this.main.apiService, this.main.logService);
|
||||
const response = await command.run(password, cmd);
|
||||
this.processResponse(response);
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ export class Program extends BaseProgram {
|
|||
const canInteract = process.env.BW_NOINTERACTION !== 'true';
|
||||
if (canInteract) {
|
||||
const command = new UnlockCommand(this.main.cryptoService, this.main.userService,
|
||||
this.main.cryptoFunctionService, this.main.apiService);
|
||||
this.main.cryptoFunctionService, this.main.apiService, this.main.logService);
|
||||
const response = await command.run(null, null);
|
||||
if (!response.success) {
|
||||
this.processResponse(response, true);
|
||||
|
|
Loading…
Reference in New Issue