1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-30 08:10:34 +01:00
bitwarden-browser/src/program.ts

558 lines
23 KiB
TypeScript
Raw Normal View History

2018-05-15 16:50:06 +02:00
import * as chk from 'chalk';
2018-05-14 17:15:54 +02:00
import * as program from 'commander';
2018-05-15 05:16:59 +02:00
import { Main } from './bw';
2018-05-17 06:07:44 +02:00
import { ConfigCommand } from './commands/config.command';
2018-05-15 05:40:11 +02:00
import { CreateCommand } from './commands/create.command';
2018-05-14 22:25:14 +02:00
import { DeleteCommand } from './commands/delete.command';
2018-05-15 17:30:56 +02:00
import { EditCommand } from './commands/edit.command';
2018-05-15 05:40:11 +02:00
import { EncodeCommand } from './commands/encode.command';
2018-05-17 16:58:30 +02:00
import { ExportCommand } from './commands/export.command';
import { GenerateCommand } from './commands/generate.command';
2018-05-14 22:25:14 +02:00
import { GetCommand } from './commands/get.command';
import { ListCommand } from './commands/list.command';
2018-05-16 16:25:25 +02:00
import { LockCommand } from './commands/lock.command';
2018-05-14 17:15:54 +02:00
import { LoginCommand } from './commands/login.command';
2018-05-16 05:26:36 +02:00
import { LogoutCommand } from './commands/logout.command';
2018-05-14 17:15:54 +02:00
import { SyncCommand } from './commands/sync.command';
2018-05-16 16:25:25 +02:00
import { UnlockCommand } from './commands/unlock.command';
2018-05-14 17:15:54 +02:00
2018-05-16 04:47:52 +02:00
import { Response } from './models/response';
2018-05-14 20:54:19 +02:00
import { ListResponse } from './models/response/listResponse';
2018-05-16 04:47:52 +02:00
import { MessageResponse } from './models/response/messageResponse';
2018-05-14 20:54:19 +02:00
import { StringResponse } from './models/response/stringResponse';
2018-05-14 22:25:14 +02:00
import { TemplateResponse } from './models/response/templateResponse';
2018-05-14 20:54:19 +02:00
2018-05-15 16:50:06 +02:00
const chalk = chk.default;
2018-05-16 20:47:03 +02:00
function writeLn(s: string) {
process.stdout.write(s + '\n');
}
2018-05-14 17:15:54 +02:00
export class Program {
constructor(private main: Main) { }
run() {
program
2018-05-16 04:10:24 +02:00
.option('--pretty', 'Format stdout.')
2018-05-17 05:34:58 +02:00
.option('--quiet', 'Do not return anything to stdout.')
.option('--raw', 'Return raw output instead a descriptive message.')
.option('--session <session>', 'Pass session token instead of reading from env.')
.version(this.main.platformUtilsService.getApplicationVersion(), '-v, --version');
2018-05-16 04:10:24 +02:00
2018-05-16 04:47:52 +02:00
program.on('option:pretty', () => {
process.env.BW_PRETTY = 'true';
});
program.on('option:raw', () => {
process.env.BW_RAW = 'true';
});
2018-05-16 16:29:57 +02:00
program.on('option:quiet', () => {
process.env.BW_QUIET = 'true';
});
2018-05-16 04:10:24 +02:00
program.on('option:session', (key) => {
process.env.BW_SESSION = key;
});
2018-05-14 17:15:54 +02:00
2018-05-16 20:47:03 +02:00
program.on('command:*', () => {
writeLn(chalk.redBright('Invalid command: ' + program.args.join(' ')));
process.stdout.write('See --help for a list of available commands.');
process.exit(1);
});
program.on('--help', () => {
writeLn('\n Examples:');
writeLn('');
2018-05-17 03:38:45 +02:00
writeLn(' bw login');
writeLn(' bw lock');
writeLn(' bw unlock myPassword321');
2018-05-17 05:32:14 +02:00
writeLn(' bw list --help');
2018-05-17 03:38:45 +02:00
writeLn(' bw list items --search google');
writeLn(' bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412');
writeLn(' bw get password google.com');
writeLn(' echo \'{"name":"My Folder"}\' | bw encode');
writeLn(' bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K');
writeLn(' bw edit folder c7c7b60b-9c61-40f2-8ccd-36c49595ed72 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==');
2018-05-17 04:21:29 +02:00
writeLn(' bw delete item 99ee88d2-6046-4ea7-92c2-acac464b1412');
writeLn(' bw generate -lusn --length 18');
writeLn('');
2018-05-16 20:47:03 +02:00
});
2018-05-14 17:15:54 +02:00
program
2018-05-15 23:17:47 +02:00
.command('login [email] [password]')
2018-05-16 20:47:03 +02:00
.description('Log into a user account.')
.option('--method <method>', 'Two-step login method.')
.option('--code <code>', 'Two-step login code.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Notes:');
writeLn('');
writeLn(' See docs for valid `method` enum values.');
writeLn('');
writeLn(' Pass `--raw` option to only get session token.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw login');
writeLn(' bw login john@example.com myPassword321 --raw');
writeLn(' bw login john@example.com myPassword321 --method 1 --code 249213');
writeLn('');
})
2018-05-14 17:15:54 +02:00
.action(async (email: string, password: string, cmd: program.Command) => {
2018-05-16 05:26:36 +02:00
await this.exitIfAuthed();
2018-05-16 03:11:58 +02:00
const command = new LoginCommand(this.main.authService, this.main.apiService,
2018-05-17 03:38:45 +02:00
this.main.cryptoFunctionService, this.main.syncService);
2018-05-14 20:54:19 +02:00
const response = await command.run(email, password, cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
2018-05-14 17:15:54 +02:00
});
program
.command('logout')
2018-05-16 20:47:03 +02:00
.description('Log out of the current user account.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Examples:');
writeLn('');
writeLn(' bw logout');
writeLn('');
})
2018-05-16 04:10:24 +02:00
.action(async (cmd) => {
await this.exitIfNotAuthed();
2018-05-16 05:48:50 +02:00
const command = new LogoutCommand(this.main.authService, async () => await this.main.logout());
2018-05-16 05:26:36 +02:00
const response = await command.run(cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
2018-05-14 17:15:54 +02:00
});
2018-05-15 20:21:42 +02:00
program
.command('lock')
.description('Lock the vault and destroy the current session token.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Examples:');
writeLn('');
writeLn(' bw lock');
writeLn('');
})
2018-05-16 04:47:52 +02:00
.action(async (cmd) => {
await this.exitIfNotAuthed();
2018-05-16 16:25:25 +02:00
const command = new LockCommand(this.main.lockService);
const response = await command.run(cmd);
this.processResponse(response);
2018-05-15 20:21:42 +02:00
});
program
2018-05-15 23:17:47 +02:00
.command('unlock [password]')
2018-05-15 20:21:42 +02:00
.description('Unlock the vault and obtain a new session token.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Notes:');
writeLn('');
writeLn(' After unlocking, any previous session tokens will no longer be valid.');
writeLn('');
writeLn(' Pass `--raw` option to only get session token.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw unlock');
writeLn(' bw unlock myPassword321');
writeLn(' bw unlock myPassword321 --raw');
writeLn('');
})
2018-05-16 16:25:25 +02:00
.action(async (password, cmd) => {
2018-05-16 04:47:52 +02:00
await this.exitIfNotAuthed();
2018-05-16 16:25:25 +02:00
const command = new UnlockCommand(this.main.cryptoService, this.main.userService,
this.main.cryptoFunctionService);
const response = await command.run(password, cmd);
this.processResponse(response);
2018-05-15 20:21:42 +02:00
});
2018-05-14 17:15:54 +02:00
program
.command('sync')
2018-05-16 20:47:03 +02:00
.description('Sync vault from server.')
2018-05-14 17:15:54 +02:00
.option('-f, --force', 'Force a full sync.')
.option('--last', 'Get the last sync date.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Examples:');
writeLn('');
writeLn(' bw sync');
writeLn(' bw sync -f');
writeLn(' bw sync --last');
writeLn('');
})
2018-05-14 17:15:54 +02:00
.action(async (cmd) => {
2018-05-16 04:10:24 +02:00
await this.exitIfLocked();
2018-05-14 17:15:54 +02:00
const command = new SyncCommand(this.main.syncService);
2018-05-14 20:54:19 +02:00
const response = await command.run(cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
2018-05-14 17:15:54 +02:00
});
program
.command('list <object>')
.description('List objects.')
.option('--search <search>', 'Perform a search on the listed objects.')
.option('--folderid <folderid>', 'Filter items by folder id.')
.option('--collectionid <collectionid>', 'Filter items by collection id.')
.option('--organizationid <organizationid>', 'Filter items or collections by organization id.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Objects:');
writeLn('');
writeLn(' items');
writeLn(' folders');
writeLn(' collections');
writeLn('');
writeLn(' Notes:');
writeLn('');
writeLn(' Combining multiple filters performs a logical OR operation.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw list items');
writeLn(' bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2');
writeLn(' bw list items --search google --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2');
writeLn(' bw list items --folderid null');
writeLn(' bw list items --organizationid !null');
writeLn(' bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2 --organizationid !null');
writeLn(' bw list folders --search email');
writeLn('');
})
2018-05-14 19:37:52 +02:00
.action(async (object, cmd) => {
2018-05-16 04:10:24 +02:00
await this.exitIfLocked();
2018-05-14 19:37:52 +02:00
const command = new ListCommand(this.main.cipherService, this.main.folderService,
this.main.collectionService);
2018-05-14 20:54:19 +02:00
const response = await command.run(object, cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
2018-05-14 17:15:54 +02:00
});
program
.command('get <object> <id>')
2018-05-14 17:15:54 +02:00
.description('Get an object.')
2018-05-17 19:28:22 +02:00
.option('--attachmentid <attachmentid>', 'Get an item\'s attachment.')
.option('--output <output>', 'Output directory or filename for attachment.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Objects:');
writeLn('');
writeLn(' item');
writeLn(' username');
writeLn(' password');
writeLn(' uri');
writeLn(' totp');
2018-05-17 17:07:53 +02:00
writeLn(' exposed');
2018-05-17 05:23:12 +02:00
writeLn(' folder');
writeLn(' collection');
writeLn(' template');
writeLn('');
writeLn(' Id:');
writeLn('');
writeLn(' Search term or GUID.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412');
writeLn(' bw get password https://google.com');
writeLn(' bw get totp google.com');
2018-05-17 17:07:53 +02:00
writeLn(' bw get exposed yahoo.com');
2018-05-17 19:28:22 +02:00
writeLn(' bw get item google --attachmentid b857igwl1dzrs2 --output ./photo.jpg');
writeLn(' bw get item google --attachmentid photo.jpg --raw');
2018-05-17 05:23:12 +02:00
writeLn(' bw get folder email');
writeLn(' bw get template folder');
writeLn('');
})
2018-05-14 19:37:52 +02:00
.action(async (object, id, cmd) => {
2018-05-16 04:10:24 +02:00
await this.exitIfLocked();
2018-05-14 19:37:52 +02:00
const command = new GetCommand(this.main.cipherService, this.main.folderService,
2018-05-17 19:28:22 +02:00
this.main.collectionService, this.main.totpService, this.main.auditService,
this.main.cryptoService);
2018-05-14 20:54:19 +02:00
const response = await command.run(object, id, cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
2018-05-14 17:15:54 +02:00
});
2018-05-15 03:19:49 +02:00
program
.command('create <object> [encodedJson]')
2018-05-17 21:33:36 +02:00
.option('--file <file>', 'Path to file for attachment.')
.option('--itemid <itemid>', 'Attachment\'s item id.')
2018-05-15 03:19:49 +02:00
.description('Create an object.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Objects:');
writeLn('');
writeLn(' item');
2018-05-17 21:33:36 +02:00
writeLn(' attachment');
2018-05-17 05:23:12 +02:00
writeLn(' folder');
writeLn('');
writeLn(' Notes:');
writeLn('');
writeLn(' `encodedJson` can be piped into stdin.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K');
writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyIn0K\' | bw create folder');
2018-05-17 21:33:36 +02:00
writeLn(' bw create attachment --file ./myfile.csv --itemid 16b15b89-65b3-4639-ad2a-95052a6d8f66');
2018-05-17 05:23:12 +02:00
writeLn('');
})
.action(async (object, encodedJson, cmd) => {
2018-05-16 04:10:24 +02:00
await this.exitIfLocked();
2018-05-15 03:19:49 +02:00
const command = new CreateCommand(this.main.cipherService, this.main.folderService);
const response = await command.run(object, encodedJson, cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
2018-05-15 03:19:49 +02:00
});
2018-05-14 17:15:54 +02:00
program
.command('edit <object> <id> [encodedJson]')
2018-05-14 17:15:54 +02:00
.description('Edit an object.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Objects:');
writeLn('');
writeLn(' item');
writeLn(' folder');
writeLn('');
writeLn(' Id:');
writeLn('');
writeLn(' Must be a GUID.');
writeLn('');
writeLn(' Notes:');
writeLn('');
writeLn(' `encodedJson` can be piped into stdin.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==');
writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==\' | ' +
'bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02');
writeLn('');
})
.action(async (object, id, encodedJson, cmd) => {
2018-05-16 04:10:24 +02:00
await this.exitIfLocked();
2018-05-15 17:30:56 +02:00
const command = new EditCommand(this.main.cipherService, this.main.folderService);
const response = await command.run(object, id, encodedJson, cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
2018-05-14 17:15:54 +02:00
});
program
.command('delete <object> <id>')
2018-05-17 19:43:53 +02:00
.option('--attachmentid <attachmentid>', 'Delete an item\'s attachment.')
2018-05-14 17:15:54 +02:00
.description('Delete an object.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Objects:');
writeLn('');
writeLn(' item');
writeLn(' folder');
writeLn('');
writeLn(' Id:');
writeLn('');
writeLn(' Must be a GUID.');
writeLn('');
writeLn(' Examples:');
writeLn('');
2018-05-17 19:43:53 +02:00
writeLn(' bw delete item 7063feab-4b10-472e-b64c-785e2b870b92');
2018-05-17 05:23:12 +02:00
writeLn(' bw delete folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02');
2018-05-17 19:43:53 +02:00
writeLn(' bw delete item 310d5ffd-e9a2-4451-af87-ea054dce0f78 --attachmentid b857igwl1dzrs2');
writeLn(' bw delete item 310d5ffd-e9a2-4451-af87-ea054dce0f78 --attachmentid photo.jpg');
2018-05-17 05:23:12 +02:00
writeLn('');
})
2018-05-14 21:08:48 +02:00
.action(async (object, id, cmd) => {
2018-05-16 04:10:24 +02:00
await this.exitIfLocked();
2018-05-14 21:08:48 +02:00
const command = new DeleteCommand(this.main.cipherService, this.main.folderService);
const response = await command.run(object, id, cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
2018-05-14 17:15:54 +02:00
});
2018-05-17 16:58:30 +02:00
program
.command('export [password]')
.description('Export vault data to a CSV.')
.option('--output <output>', 'Output directory or filename.')
.on('--help', () => {
writeLn('\n Examples:');
writeLn('');
writeLn(' bw export');
writeLn(' bw export myPassword321');
writeLn(' bw export --output ./exp/bw.csv');
writeLn(' bw export myPassword321 --output bw.csv');
writeLn('');
})
.action(async (password, cmd) => {
await this.exitIfLocked();
const command = new ExportCommand(this.main.cryptoService, this.main.userService,
this.main.exportService);
const response = await command.run(password, cmd);
this.processResponse(response);
});
program
.command('generate')
.description('Generate a password.')
.option('-u, --uppercase', 'Include uppercase characters.')
.option('-l, --lowercase', 'Include lowercase characters.')
.option('-n, --number', 'Include numeric characters.')
.option('-s, --special', 'Include special characters.')
.option('--length <length>', 'Length of the password.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Notes:');
writeLn('');
writeLn(' Default options are `-uln --length 14`.');
writeLn('');
writeLn(' Minimum `length` is 5.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw generate');
writeLn(' bw generate -u -l --length 18');
writeLn(' bw generate -ulns --length 25');
writeLn(' bw generate -ul');
writeLn('');
})
.action(async (cmd) => {
const command = new GenerateCommand(this.main.passwordGenerationService);
const response = await command.run(cmd);
this.processResponse(response);
});
2018-05-14 23:13:57 +02:00
program
.command('encode')
2018-05-17 05:23:12 +02:00
.description('Base 64 encode stdin.')
.on('--help', () => {
writeLn('\n Notes:');
writeLn('');
writeLn(' Use to create `encodedJson` for `create` and `edit` commands.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' echo \'{"name":"My Folder"}\' | bw encode');
writeLn('');
})
2018-05-14 23:13:57 +02:00
.action(async (object, id, cmd) => {
const command = new EncodeCommand();
const response = await command.run(cmd);
2018-05-16 16:25:25 +02:00
this.processResponse(response);
});
2018-05-17 06:07:44 +02:00
program
.command('config <setting> <value>')
.description('Configure settings.')
.on('--help', () => {
writeLn('\n Settings:');
writeLn('');
writeLn(' server - On-premise hosted installation URL.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw config server https://bw.company.com');
writeLn(' bw config server bitwarden.com');
writeLn('');
})
.action(async (setting, value, cmd) => {
const command = new ConfigCommand(this.main.environmentService);
const response = await command.run(setting, value, cmd);
this.processResponse(response);
});
2018-05-16 16:25:25 +02:00
program
.command('update')
.description('Check for updates.')
2018-05-17 05:23:12 +02:00
.on('--help', () => {
writeLn('\n Notes:');
writeLn('');
writeLn(' Returns the URL to download the newest version of this CLI tool.');
writeLn('');
writeLn(' Examples:');
writeLn('');
writeLn(' bw update');
writeLn('');
})
2018-05-16 16:25:25 +02:00
.action(async (object, id, cmd) => {
2018-05-16 17:54:59 +02:00
// TODO
2018-05-14 23:13:57 +02:00
});
2018-05-14 17:15:54 +02:00
program
.parse(process.argv);
2018-05-16 20:47:03 +02:00
if (process.argv.slice(2).length === 0) {
program.outputHelp();
}
2018-05-14 17:15:54 +02:00
}
2018-05-14 20:54:19 +02:00
2018-05-16 16:25:25 +02:00
private processResponse(response: Response) {
2018-05-15 20:21:42 +02:00
if (!response.success) {
2018-05-16 16:29:57 +02:00
if (process.env.BW_QUIET !== 'true') {
process.stdout.write(chalk.redBright(response.message));
}
2018-05-14 20:54:19 +02:00
process.exit(1);
2018-05-15 20:21:42 +02:00
return;
}
if (response.data != null) {
2018-05-16 14:37:05 +02:00
let out: string = null;
2018-05-15 20:21:42 +02:00
if (response.data.object === 'string') {
2018-05-16 03:22:39 +02:00
const data = (response.data as StringResponse).data;
if (data != null) {
2018-05-16 14:37:05 +02:00
out = data;
2018-05-16 03:22:39 +02:00
}
2018-05-15 20:21:42 +02:00
} else if (response.data.object === 'list') {
2018-05-16 16:25:25 +02:00
out = this.getJson((response.data as ListResponse).data);
2018-05-15 20:21:42 +02:00
} else if (response.data.object === 'template') {
2018-05-16 16:25:25 +02:00
out = this.getJson((response.data as TemplateResponse).template);
2018-05-16 04:47:52 +02:00
} else if (response.data.object === 'message') {
2018-05-16 14:37:05 +02:00
out = this.getMessage(response);
2018-05-15 20:21:42 +02:00
} else {
2018-05-16 16:25:25 +02:00
out = this.getJson(response.data);
2018-05-16 14:37:05 +02:00
}
2018-05-16 16:29:57 +02:00
if (out != null && process.env.BW_QUIET !== 'true') {
2018-05-16 14:37:05 +02:00
process.stdout.write(out);
2018-05-15 20:21:42 +02:00
}
2018-05-14 20:54:19 +02:00
}
2018-05-15 20:21:42 +02:00
process.exit();
2018-05-14 20:54:19 +02:00
}
2018-05-15 18:44:10 +02:00
2018-05-16 16:25:25 +02:00
private getJson(obj: any): string {
2018-05-16 04:47:52 +02:00
if (process.env.BW_PRETTY === 'true') {
2018-05-16 14:37:05 +02:00
return JSON.stringify(obj, null, ' ');
2018-05-15 18:44:10 +02:00
} else {
2018-05-16 14:37:05 +02:00
return JSON.stringify(obj);
2018-05-15 18:44:10 +02:00
}
}
2018-05-16 14:37:05 +02:00
private getMessage(response: Response) {
2018-05-16 04:47:52 +02:00
const message = (response.data as MessageResponse);
if (process.env.BW_RAW === 'true' && message.raw != null) {
2018-05-16 14:37:05 +02:00
return message.raw;
2018-05-15 18:44:10 +02:00
}
2018-05-16 14:37:05 +02:00
let out: string = '';
2018-05-16 04:47:52 +02:00
if (message.title != null) {
2018-05-16 14:37:05 +02:00
out = chalk.greenBright(message.title);
2018-05-16 04:47:52 +02:00
}
if (message.message != null) {
if (message.title != null) {
2018-05-16 14:37:05 +02:00
out += '\n';
2018-05-16 04:47:52 +02:00
}
2018-05-16 14:37:05 +02:00
out += message.message;
2018-05-15 18:44:10 +02:00
}
2018-05-16 14:37:05 +02:00
return out.trim() === '' ? null : out;
2018-05-15 18:44:10 +02:00
}
2018-05-16 04:10:24 +02:00
private async exitIfLocked() {
await this.exitIfNotAuthed();
const key = await this.main.cryptoService.getKey();
if (key == null) {
process.stdout.write(chalk.redBright('Vault is locked.'));
process.exit(1);
}
}
private async exitIfAuthed() {
const authed = await this.main.userService.isAuthenticated();
if (authed) {
const email = await this.main.userService.getEmail();
process.stdout.write(chalk.redBright('You are already logged in as ' + email + '.'));
process.exit(1);
}
}
private async exitIfNotAuthed() {
const authed = await this.main.userService.isAuthenticated();
if (!authed) {
process.stdout.write(chalk.redBright('You are not logged in.'));
process.exit(1);
}
}
2018-05-14 17:15:54 +02:00
}