list and get commands
This commit is contained in:
parent
2557f7239c
commit
3dd38cbe12
|
@ -0,0 +1,93 @@
|
||||||
|
import * as program from 'commander';
|
||||||
|
|
||||||
|
import { CipherType } from 'jslib/enums/cipherType';
|
||||||
|
|
||||||
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
|
import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||||
|
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||||
|
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||||
|
|
||||||
|
export class GetCommand {
|
||||||
|
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||||
|
private collectionService: CollectionService, private totpService: TotpService) { }
|
||||||
|
|
||||||
|
async run(object: string, id: string, cmd: program.Command) {
|
||||||
|
switch (object) {
|
||||||
|
case 'item':
|
||||||
|
await this.getCipher(id);
|
||||||
|
break;
|
||||||
|
case 'totp':
|
||||||
|
await this.getTotp(id);
|
||||||
|
break;
|
||||||
|
case 'folder':
|
||||||
|
await this.getFolder(id);
|
||||||
|
break;
|
||||||
|
case 'collection':
|
||||||
|
await this.getCollection(id);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('Unknown object: ' + object);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getCipher(id: string) {
|
||||||
|
const cipher = await this.cipherService.get(id);
|
||||||
|
if (cipher == null) {
|
||||||
|
console.log('Not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const decCipher = await cipher.decrypt();
|
||||||
|
console.log(JSON.stringify(decCipher));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getTotp(id: string) {
|
||||||
|
const cipher = await this.cipherService.get(id);
|
||||||
|
if (cipher == null) {
|
||||||
|
console.log('Not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cipher.type !== CipherType.Login) {
|
||||||
|
console.log('Not a login.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const decCipher = await cipher.decrypt();
|
||||||
|
if (decCipher.login.totp == null || decCipher.login.totp === '') {
|
||||||
|
console.log('No TOTP available.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const totp = await this.totpService.getCode(decCipher.login.totp);
|
||||||
|
if (totp == null) {
|
||||||
|
console.log('Couldn\'t generate TOTP code.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(JSON.stringify(totp));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getFolder(id: string) {
|
||||||
|
const folder = await this.folderService.get(id);
|
||||||
|
if (folder == null) {
|
||||||
|
console.log('Not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const decFolder = await folder.decrypt();
|
||||||
|
console.log(JSON.stringify(decFolder));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getCollection(id: string) {
|
||||||
|
const collection = await this.collectionService.get(id);
|
||||||
|
if (collection == null) {
|
||||||
|
console.log('Not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const decCollection = await collection.decrypt();
|
||||||
|
console.log(JSON.stringify(decCollection));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
import * as program from 'commander';
|
||||||
|
|
||||||
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
|
import { CollectionService } from 'jslib/services/collection.service';
|
||||||
|
import { FolderService } from 'jslib/services/folder.service';
|
||||||
|
|
||||||
|
export class ListCommand {
|
||||||
|
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||||
|
private collectionService: CollectionService) { }
|
||||||
|
|
||||||
|
async run(object: string, cmd: program.Command) {
|
||||||
|
switch (object) {
|
||||||
|
case 'items':
|
||||||
|
await this.listCiphers();
|
||||||
|
break;
|
||||||
|
case 'folders':
|
||||||
|
await this.listFolders();
|
||||||
|
break;
|
||||||
|
case 'collections':
|
||||||
|
await this.listCollections();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('Unknown object: ' + object);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async listCiphers() {
|
||||||
|
const ciphers = await this.cipherService.getAllDecrypted();
|
||||||
|
console.log(JSON.stringify(ciphers));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async listFolders() {
|
||||||
|
const folders = await this.folderService.getAllDecrypted();
|
||||||
|
console.log(JSON.stringify(folders));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async listCollections() {
|
||||||
|
const collections = await this.collectionService.getAllDecrypted();
|
||||||
|
console.log(JSON.stringify(collections));
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,9 +3,7 @@ import * as program from 'commander';
|
||||||
import { SyncService } from 'jslib/abstractions/sync.service';
|
import { SyncService } from 'jslib/abstractions/sync.service';
|
||||||
|
|
||||||
export class SyncCommand {
|
export class SyncCommand {
|
||||||
constructor(private syncService: SyncService) {
|
constructor(private syncService: SyncService) { }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(cmd: program.Command) {
|
async run(cmd: program.Command) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -82,6 +82,8 @@ export class Main {
|
||||||
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
|
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
|
||||||
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
||||||
this.storageService, this.messagingService, (expired: boolean) => { });
|
this.storageService, this.messagingService, (expired: boolean) => { });
|
||||||
|
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
|
||||||
|
this.totpService = new TotpService(this.storageService, this.cryptoFunctionService);
|
||||||
this.authService = new AuthService(this.cryptoService, this.apiService, this.userService, this.tokenService,
|
this.authService = new AuthService(this.cryptoService, this.apiService, this.userService, this.tokenService,
|
||||||
this.appIdService, this.i18nService, this.platformUtilsService, this.messagingService, true);
|
this.appIdService, this.i18nService, this.platformUtilsService, this.messagingService, true);
|
||||||
this.program = new Program(this);
|
this.program = new Program(this);
|
||||||
|
|
|
@ -2,6 +2,8 @@ import * as program from 'commander';
|
||||||
|
|
||||||
import { LoginCommand } from './commands/login.command';
|
import { LoginCommand } from './commands/login.command';
|
||||||
import { SyncCommand } from './commands/sync.command';
|
import { SyncCommand } from './commands/sync.command';
|
||||||
|
import { ListCommand } from './commands/list.command';
|
||||||
|
import { GetCommand } from './commands/get.command';
|
||||||
|
|
||||||
import { Main } from './main';
|
import { Main } from './main';
|
||||||
|
|
||||||
|
@ -36,7 +38,6 @@ export class Program {
|
||||||
.description('Sync user\'s vault from server.')
|
.description('Sync user\'s vault from server.')
|
||||||
.option('-f, --force', 'Force a full sync.')
|
.option('-f, --force', 'Force a full sync.')
|
||||||
.action(async (cmd) => {
|
.action(async (cmd) => {
|
||||||
console.log('Syncing...');
|
|
||||||
const command = new SyncCommand(this.main.syncService);
|
const command = new SyncCommand(this.main.syncService);
|
||||||
await command.run(cmd);
|
await command.run(cmd);
|
||||||
process.exit();
|
process.exit();
|
||||||
|
@ -45,18 +46,21 @@ export class Program {
|
||||||
program
|
program
|
||||||
.command('list <object>')
|
.command('list <object>')
|
||||||
.description('List objects.')
|
.description('List objects.')
|
||||||
.action((object, cmd) => {
|
.action(async (object, cmd) => {
|
||||||
console.log('Listing...');
|
const command = new ListCommand(this.main.cipherService, this.main.folderService,
|
||||||
console.log(object);
|
this.main.collectionService);
|
||||||
|
await command.run(object, cmd);
|
||||||
|
process.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('get <object> <id>')
|
.command('get <object> <id>')
|
||||||
.description('Get an object.')
|
.description('Get an object.')
|
||||||
.action((object, id, cmd) => {
|
.action(async (object, id, cmd) => {
|
||||||
console.log('Getting...');
|
const command = new GetCommand(this.main.cipherService, this.main.folderService,
|
||||||
console.log(object);
|
this.main.collectionService, this.main.totpService);
|
||||||
console.log(id);
|
await command.run(object, id, cmd);
|
||||||
|
process.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|
Loading…
Reference in New Issue