mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
allow gets by search term
This commit is contained in:
parent
df7ccaea9d
commit
0490c6ba3f
@ -9,6 +9,10 @@ export class DeleteCommand {
|
|||||||
constructor(private cipherService: CipherService, private folderService: FolderService) { }
|
constructor(private cipherService: CipherService, private folderService: FolderService) { }
|
||||||
|
|
||||||
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
|
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
|
||||||
|
if (id != null) {
|
||||||
|
id = id.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
switch (object.toLowerCase()) {
|
switch (object.toLowerCase()) {
|
||||||
case 'item':
|
case 'item':
|
||||||
return await this.deleteCipher(id);
|
return await this.deleteCipher(id);
|
||||||
|
@ -20,6 +20,10 @@ export class EditCommand {
|
|||||||
return Response.badRequest('Error parsing the encoded request data.');
|
return Response.badRequest('Error parsing the encoded request data.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id != null) {
|
||||||
|
id = id.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
switch (object.toLowerCase()) {
|
switch (object.toLowerCase()) {
|
||||||
case 'item':
|
case 'item':
|
||||||
return await this.editCipher(id, req);
|
return await this.editCipher(id, req);
|
||||||
|
@ -9,6 +9,10 @@ import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration
|
|||||||
import { SyncService } from 'jslib/abstractions/sync.service';
|
import { SyncService } from 'jslib/abstractions/sync.service';
|
||||||
import { TotpService } from 'jslib/abstractions/totp.service';
|
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||||
|
|
||||||
|
import { CipherView } from 'jslib/models/view/cipherView';
|
||||||
|
import { CollectionView } from 'jslib/models/view/collectionView';
|
||||||
|
import { FolderView } from 'jslib/models/view/folderView';
|
||||||
|
|
||||||
import { Response } from '../models/response';
|
import { Response } from '../models/response';
|
||||||
import { CipherResponse } from '../models/response/cipherResponse';
|
import { CipherResponse } from '../models/response/cipherResponse';
|
||||||
import { CollectionResponse } from '../models/response/collectionResponse';
|
import { CollectionResponse } from '../models/response/collectionResponse';
|
||||||
@ -26,6 +30,8 @@ import { Login } from '../models/login';
|
|||||||
import { LoginUri } from '../models/loginUri';
|
import { LoginUri } from '../models/loginUri';
|
||||||
import { SecureNote } from '../models/secureNote';
|
import { SecureNote } from '../models/secureNote';
|
||||||
|
|
||||||
|
import { CliUtils } from '../utils';
|
||||||
|
|
||||||
export class GetCommand {
|
export class GetCommand {
|
||||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||||
private collectionService: CollectionService, private totpService: TotpService,
|
private collectionService: CollectionService, private totpService: TotpService,
|
||||||
@ -36,6 +42,10 @@ export class GetCommand {
|
|||||||
return Response.badRequest('`id` argument is required.');
|
return Response.badRequest('`id` argument is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id != null) {
|
||||||
|
id = id.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
switch (object.toLowerCase()) {
|
switch (object.toLowerCase()) {
|
||||||
case 'item':
|
case 'item':
|
||||||
return await this.getCipher(id);
|
return await this.getCipher(id);
|
||||||
@ -57,32 +67,46 @@ export class GetCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getCipher(id: string) {
|
private async getCipher(id: string) {
|
||||||
const cipher = await this.cipherService.get(id);
|
let decCipher: CipherView = null;
|
||||||
if (cipher == null) {
|
if (this.isGuid(id)) {
|
||||||
return Response.notFound();
|
const cipher = await this.cipherService.get(id);
|
||||||
|
if (cipher != null) {
|
||||||
|
decCipher = await cipher.decrypt();
|
||||||
|
}
|
||||||
|
} else if (id.trim() !== '') {
|
||||||
|
let ciphers = await this.cipherService.getAllDecrypted();
|
||||||
|
ciphers = CliUtils.searchCiphers(ciphers, id);
|
||||||
|
if (ciphers.length > 1) {
|
||||||
|
return Response.error('More than one result was found.');
|
||||||
|
}
|
||||||
|
if (ciphers.length > 0) {
|
||||||
|
decCipher = ciphers[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const decCipher = await cipher.decrypt();
|
if (decCipher == null) {
|
||||||
|
return Response.notFound();
|
||||||
|
}
|
||||||
const res = new CipherResponse(decCipher);
|
const res = new CipherResponse(decCipher);
|
||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getTotp(id: string) {
|
private async getTotp(id: string) {
|
||||||
const cipher = await this.cipherService.get(id);
|
const cipherResponse = await this.getCipher(id);
|
||||||
if (cipher == null) {
|
if (!cipherResponse.success) {
|
||||||
return Response.notFound();
|
return cipherResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cipher = cipherResponse.data as CipherResponse;
|
||||||
if (cipher.type !== CipherType.Login) {
|
if (cipher.type !== CipherType.Login) {
|
||||||
return Response.badRequest('Not a login.');
|
return Response.badRequest('Not a login.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const decCipher = await cipher.decrypt();
|
if (cipher.login.totp == null || cipher.login.totp === '') {
|
||||||
if (decCipher.login.totp == null || decCipher.login.totp === '') {
|
|
||||||
return Response.error('No TOTP available for this login.');
|
return Response.error('No TOTP available for this login.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const totp = await this.totpService.getCode(decCipher.login.totp);
|
const totp = await this.totpService.getCode(cipher.login.totp);
|
||||||
if (totp == null) {
|
if (totp == null) {
|
||||||
return Response.error('Couldn\'t generate TOTP code.');
|
return Response.error('Couldn\'t generate TOTP code.');
|
||||||
}
|
}
|
||||||
@ -92,27 +116,59 @@ export class GetCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getFolder(id: string) {
|
private async getFolder(id: string) {
|
||||||
const folder = await this.folderService.get(id);
|
let decFolder: FolderView = null;
|
||||||
if (folder == null) {
|
if (this.isGuid(id)) {
|
||||||
return Response.notFound();
|
const folder = await this.folderService.get(id);
|
||||||
|
if (folder != null) {
|
||||||
|
decFolder = await folder.decrypt();
|
||||||
|
}
|
||||||
|
} else if (id.trim() !== '') {
|
||||||
|
let folders = await this.folderService.getAllDecrypted();
|
||||||
|
folders = CliUtils.searchFolders(folders, id);
|
||||||
|
if (folders.length > 1) {
|
||||||
|
return Response.error('More than one result was found.');
|
||||||
|
}
|
||||||
|
if (folders.length > 0) {
|
||||||
|
decFolder = folders[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const decFolder = await folder.decrypt();
|
if (decFolder == null) {
|
||||||
|
return Response.notFound();
|
||||||
|
}
|
||||||
const res = new FolderResponse(decFolder);
|
const res = new FolderResponse(decFolder);
|
||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getCollection(id: string) {
|
private async getCollection(id: string) {
|
||||||
const collection = await this.collectionService.get(id);
|
let decCollection: CollectionView = null;
|
||||||
if (collection == null) {
|
if (this.isGuid(id)) {
|
||||||
return Response.notFound();
|
const collection = await this.collectionService.get(id);
|
||||||
|
if (collection != null) {
|
||||||
|
decCollection = await collection.decrypt();
|
||||||
|
}
|
||||||
|
} else if (id.trim() !== '') {
|
||||||
|
let collections = await this.collectionService.getAllDecrypted();
|
||||||
|
collections = CliUtils.searchCollections(collections, id);
|
||||||
|
if (collections.length > 1) {
|
||||||
|
return Response.error('More than one result was found.');
|
||||||
|
}
|
||||||
|
if (collections.length > 0) {
|
||||||
|
decCollection = collections[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const decCollection = await collection.decrypt();
|
if (decCollection == null) {
|
||||||
|
return Response.notFound();
|
||||||
|
}
|
||||||
const res = new CollectionResponse(decCollection);
|
const res = new CollectionResponse(decCollection);
|
||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isGuid(id: string) {
|
||||||
|
return RegExp(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, 'i').test(id);
|
||||||
|
}
|
||||||
|
|
||||||
private async getTemplate(id: string) {
|
private async getTemplate(id: string) {
|
||||||
let template: any = null;
|
let template: any = null;
|
||||||
switch (id.toLowerCase()) {
|
switch (id.toLowerCase()) {
|
||||||
|
@ -180,7 +180,7 @@ export class Program {
|
|||||||
.command('update')
|
.command('update')
|
||||||
.description('Check for updates.')
|
.description('Check for updates.')
|
||||||
.action(async (object, id, cmd) => {
|
.action(async (object, id, cmd) => {
|
||||||
console.log('Checking...');
|
// TODO
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
|
Loading…
Reference in New Issue
Block a user