1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-08-27 23:31:41 +02:00

get templates

This commit is contained in:
Kyle Spearrin 2018-05-14 16:25:14 -04:00
parent a1238ff685
commit 85770b7cbb
14 changed files with 222 additions and 6 deletions

View File

@ -9,7 +9,7 @@ export class DeleteCommand {
constructor(private cipherService: CipherService, private folderService: FolderService) { }
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
switch (object) {
switch (object.toLowerCase()) {
case 'item':
return await this.deleteCipher(id);
case 'folder':

View File

@ -12,13 +12,22 @@ import { CipherResponse } from '../models/response/cipherResponse';
import { CollectionResponse } from '../models/response/collectionResponse';
import { FolderResponse } from '../models/response/folderResponse';
import { StringResponse } from '../models/response/stringResponse';
import { TemplateResponse } from '../models/response/templateResponse';
import { CipherRequest } from '../models/request/cipherRequest';
import { LoginRequest } from '../models/request/loginRequest';
import { LoginUriRequest } from '../models/request/loginUriRequest';
import { FieldRequest } from '../models/request/fieldRequest';
import { CardRequest } from '../models/request/cardRequest';
import { IdentityRequest } from '../models/request/identityRequest';
import { SecureNoteRequest } from '../models/request/secureNoteRequest';
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): Promise<Response> {
switch (object) {
switch (object.toLowerCase()) {
case 'item':
return await this.getCipher(id);
case 'totp':
@ -27,6 +36,8 @@ export class GetCommand {
return await this.getFolder(id);
case 'collection':
return await this.getCollection(id);
case 'template':
return await this.getTemplate(id);
default:
return Response.badRequest('Unknown object.');
}
@ -88,4 +99,36 @@ export class GetCommand {
const res = new CollectionResponse(decCollection);
return Response.success(res);
}
private async getTemplate(id: string) {
let template: any = null;
switch (id.toLowerCase()) {
case 'item':
template = CipherRequest.template();
break;
case 'field':
template = FieldRequest.template();
break;
case 'login':
template = LoginRequest.template();
break;
case 'loginuri':
template = LoginUriRequest.template();
break;
case 'card':
template = CardRequest.template();
break;
case 'identity':
template = IdentityRequest.template();
break;
case 'securenote':
template = SecureNoteRequest.template();
break;
default:
return Response.badRequest('Unknown object.');
}
const res = new TemplateResponse(template);
return Response.success(res);
}
}

View File

@ -15,7 +15,7 @@ export class ListCommand {
private collectionService: CollectionService) { }
async run(object: string, cmd: program.Command): Promise<Response> {
switch (object) {
switch (object.toLowerCase()) {
case 'items':
return await this.listCiphers();
case 'folders':

View File

@ -0,0 +1,19 @@
export class CardRequest {
static template(): CardRequest {
var req = new CardRequest();
req.cardholderName = 'John Doe';
req.brand = 'visa';
req.number = '4242424242424242';
req.expMonth = '04';
req.expYear = '2023';
req.code = '123';
return req;
}
cardholderName: string;
brand: string;
number: string;
expMonth: string;
expYear: string;
code: string;
}

View File

@ -0,0 +1,36 @@
import { CipherType } from 'jslib/enums/cipherType';
import { LoginRequest } from './loginRequest';
import { SecureNoteRequest } from './secureNoteRequest';
import { CardRequest } from './cardRequest';
import { IdentityRequest } from './identityRequest';
import { FieldRequest } from './fieldRequest';
export class CipherRequest {
static template(): CipherRequest {
var req = new CipherRequest();
req.type = CipherType.Login;
req.folderId = null;
req.organizationId = null;
req.name = 'Item name';
req.notes = 'Some notes about this item.';
req.favorite = false;
req.fields = [];
req.login = null;
req.secureNote = null;
req.card = null;
req.identity = null;
return req;
}
type: CipherType;
folderId: string;
organizationId: string;
name: string;
notes: string;
favorite: boolean;
fields: FieldRequest[];
login: LoginRequest;
secureNote: SecureNoteRequest;
card: CardRequest;
identity: IdentityRequest;
}

View File

@ -0,0 +1,3 @@
export class CollectionRequest {
name: string;
}

View File

@ -0,0 +1,15 @@
import { FieldType } from 'jslib/enums/fieldType';
export class FieldRequest {
static template(): FieldRequest {
var req = new FieldRequest();
req.name = 'Field name';
req.value = 'Some value';
req.type = FieldType.Text;
return req;
}
name: string;
value: string;
type: FieldType;
}

View File

@ -0,0 +1,3 @@
export class FolderRequest {
name: string;
}

View File

@ -0,0 +1,43 @@
export class IdentityRequest {
static template(): IdentityRequest {
var req = new IdentityRequest();
req.title = 'Mr';
req.firstName = 'John';
req.middleName = 'William';
req.lastName = 'Doe';
req.address1 = '123 Any St';
req.address2 = 'Apt #123';
req.address3 = null;
req.city = 'New York';
req.state = 'NY';
req.postalCode = '10001';
req.country = 'US';
req.company = 'Acme Inc.';
req.email = 'john@company.com';
req.phone = '5555551234';
req.ssn = '000-123-4567';
req.username = 'jdoe';
req.passportNumber = 'US-123456789';
req.licenseNumber = 'D123-12-123-12333';
return req;
}
title: string;
firstName: string;
middleName: string;
lastName: string;
address1: string;
address2: string;
address3: string;
city: string;
state: string;
postalCode: string;
country: string;
company: string;
email: string;
phone: string;
ssn: string;
username: string;
passportNumber: string;
licenseNumber: string;
}

View File

@ -0,0 +1,17 @@
import { LoginUriRequest } from './loginUriRequest';
export class LoginRequest {
static template(): LoginRequest {
var req = new LoginRequest();
req.uris = [];
req.username = 'jdoe';
req.password = 'myp@ssword123';
req.totp = 'JBSWY3DPEHPK3PXP';
return req;
}
uris: LoginUriRequest[];
username: string;
password: string;
totp: string;
}

View File

@ -0,0 +1,13 @@
import { UriMatchType } from 'jslib/enums/uriMatchType';
export class LoginUriRequest {
static template(): LoginUriRequest {
var req = new LoginUriRequest();
req.uri = 'https://google.com';
req.match = null;
return req;
}
uri: string;
match: UriMatchType = null;
}

View File

@ -0,0 +1,11 @@
import { SecureNoteType } from 'jslib/enums/secureNoteType';
export class SecureNoteRequest {
static template(): SecureNoteRequest {
var req = new SecureNoteRequest();
req.type = SecureNoteType.Generic;
return req;
}
type: SecureNoteType;
}

View File

@ -0,0 +1,10 @@
import { BaseResponse } from './baseResponse';
export class TemplateResponse extends BaseResponse {
template: any;
constructor(template: any) {
super('template');
this.template = template;
}
}

View File

@ -1,16 +1,17 @@
import * as program from 'commander';
import { DeleteCommand } from './commands/delete.command';
import { GetCommand } from './commands/get.command';
import { ListCommand } from './commands/list.command';
import { LoginCommand } from './commands/login.command';
import { SyncCommand } from './commands/sync.command';
import { ListCommand } from './commands/list.command';
import { GetCommand } from './commands/get.command';
import { Main } from './main';
import { Response } from './models/response';
import { ListResponse } from './models/response/listResponse';
import { StringResponse } from './models/response/stringResponse';
import { DeleteCommand } from './commands/delete.command';
import { TemplateResponse } from './models/response/templateResponse';
export class Program {
constructor(private main: Main) { }
@ -97,6 +98,8 @@ export class Program {
console.log((response.data as StringResponse).data);
} else if (response.data.object === 'list') {
console.log(JSON.stringify((response.data as ListResponse).data));
} else if (response.data.object === 'template') {
console.log(JSON.stringify((response.data as TemplateResponse).template));
} else {
console.log(JSON.stringify(response.data));
}