1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 06:43:35 +00:00

Add status command (#145)

* Show vault status.

The status is shown as 'unauthenticated', 'locked', or 'unlocked'.

* Add more status command fields.

Added `serverUrl`, `lastSync`, `userEmail`, and `userId`.

* Add status help text.
This commit is contained in:
Jarimatti Valkonen
2020-06-17 01:43:30 +01:00
committed by GitHub
parent c0c368cbfe
commit 62c7c30cb4
2 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
import * as program from 'commander';
import { EnvironmentService, SyncService, UserService, VaultTimeoutService } from 'jslib/abstractions';
import { Response } from 'jslib/cli/models/response';
import { TemplateResponse } from '../models/response/templateResponse';
export class StatusCommand {
constructor(
private envService: EnvironmentService,
private syncService: SyncService,
private userService: UserService,
private vaultTimeoutService: VaultTimeoutService) {
}
async run(cmd: program.Command): Promise<Response> {
try {
const baseUrl = this.baseUrl();
const status = await this.status();
const lastSync = await this.syncService.getLastSync();
const userId = await this.userService.getUserId();
const email = await this.userService.getEmail();
return Response.success(new TemplateResponse({
serverUrl: baseUrl,
lastSync: lastSync,
userEmail: email,
userId: userId,
status: status,
}));
} catch (e) {
return Response.error(e);
}
}
private baseUrl(): string {
let url = this.envService.baseUrl;
if (url == null) {
url = 'https://bitwarden.com';
}
return url;
}
private async status(): Promise<string> {
const isAuthed = await this.userService.isAuthenticated();
if (!isAuthed) {
return 'unauthenticated';
}
const isLocked = await this.vaultTimeoutService.isLocked();
if (isLocked) {
return 'locked';
} else {
return 'unlocked';
}
}
}