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';
|
import { ConsoleLogService } from 'jslib-common/services/consoleLog.service';
|
||||||
|
|
||||||
export class UnlockCommand {
|
export class UnlockCommand {
|
||||||
private logService: ConsoleLogService;
|
|
||||||
|
|
||||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||||
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) {
|
private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService,
|
||||||
this.logService = new ConsoleLogService(false);
|
private logService: ConsoleLogService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(password: string, options: program.OptionValues) {
|
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 === '') {
|
if (password == null || password === '') {
|
||||||
if (options.passwordfile) {
|
if (options?.passwordfile) {
|
||||||
password = await NodeUtils.readFirstLine(options.passwordfile);
|
password = await NodeUtils.readFirstLine(options.passwordfile);
|
||||||
} else if (options.passwordenv) {
|
} else if (options?.passwordenv) {
|
||||||
if (process.env[options.passwordenv]) {
|
if (process.env[options.passwordenv]) {
|
||||||
password = process.env[options.passwordenv];
|
password = process.env[options.passwordenv];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -208,7 +208,7 @@ export class Program extends BaseProgram {
|
||||||
if (!cmd.check) {
|
if (!cmd.check) {
|
||||||
await this.exitIfNotAuthed();
|
await this.exitIfNotAuthed();
|
||||||
const command = new UnlockCommand(this.main.cryptoService, this.main.userService,
|
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);
|
const response = await command.run(password, cmd);
|
||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ export class Program extends BaseProgram {
|
||||||
const canInteract = process.env.BW_NOINTERACTION !== 'true';
|
const canInteract = process.env.BW_NOINTERACTION !== 'true';
|
||||||
if (canInteract) {
|
if (canInteract) {
|
||||||
const command = new UnlockCommand(this.main.cryptoService, this.main.userService,
|
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);
|
const response = await command.run(null, null);
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
this.processResponse(response, true);
|
this.processResponse(response, true);
|
||||||
|
|
Loading…
Reference in New Issue