From f2131d7ef54961e355791360db6f86b043c1f80e Mon Sep 17 00:00:00 2001 From: RakVhalate Date: Wed, 30 Nov 2022 20:34:46 +1000 Subject: [PATCH] Did some --- package-lock.json | 46 +++++++++++++++++++ package.json | 1 + src/app/app.module.ts | 6 ++- src/app/globals/api.ts | 3 ++ .../{ResponseData.ts => ResponseUnwrap.ts} | 6 +-- .../{ResponseToken.ts => ResponseWrap.ts} | 2 +- src/app/pages/decrypt/decrypt.component.html | 2 +- src/app/pages/decrypt/decrypt.component.ts | 21 +++++---- src/app/pages/encrypt/encrypt.component.html | 7 +-- src/app/pages/encrypt/encrypt.component.ts | 36 +++++++-------- 10 files changed, 94 insertions(+), 36 deletions(-) create mode 100644 src/app/globals/api.ts rename src/app/models/{ResponseData.ts => ResponseUnwrap.ts} (64%) rename src/app/models/{ResponseToken.ts => ResponseWrap.ts} (92%) diff --git a/package-lock.json b/package-lock.json index 555f0c8..ff9c819 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@angular/platform-browser": "^14.2.0", "@angular/platform-browser-dynamic": "^14.2.0", "@angular/router": "^14.2.0", + "ngx-clipboard": "^15.1.0", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" @@ -7916,6 +7917,34 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node_modules/ngx-clipboard": { + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/ngx-clipboard/-/ngx-clipboard-15.1.0.tgz", + "integrity": "sha512-dUJl1cNtdkCqL953oAhP7wmUPFrqW2aDg5OPhwPU9R3cLEdQgU2NbsHEUz4zaPyEopTXu8SR37onVm1Ep8qOHg==", + "dependencies": { + "ngx-window-token": ">=6.0.0", + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@angular/common": ">=13.0.0", + "@angular/core": ">=13.0.0" + } + }, + "node_modules/ngx-window-token": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/ngx-window-token/-/ngx-window-token-6.0.0.tgz", + "integrity": "sha512-IeLKO1jzfzSvZ6vlAt4QSY/B5XcHEhdOwTjqvWEPt6/esWV9T3mA2ln10kj6SCc9pUSx4NybxE10gcyyYroImg==", + "dependencies": { + "tslib": "^2.0.0" + }, + "engines": { + "node": ">=12.20.x" + }, + "peerDependencies": { + "@angular/common": ">=13.0.0", + "@angular/core": ">=13.0.0" + } + }, "node_modules/nice-napi": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nice-napi/-/nice-napi-1.0.2.tgz", @@ -17497,6 +17526,23 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "ngx-clipboard": { + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/ngx-clipboard/-/ngx-clipboard-15.1.0.tgz", + "integrity": "sha512-dUJl1cNtdkCqL953oAhP7wmUPFrqW2aDg5OPhwPU9R3cLEdQgU2NbsHEUz4zaPyEopTXu8SR37onVm1Ep8qOHg==", + "requires": { + "ngx-window-token": ">=6.0.0", + "tslib": "^2.0.0" + } + }, + "ngx-window-token": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/ngx-window-token/-/ngx-window-token-6.0.0.tgz", + "integrity": "sha512-IeLKO1jzfzSvZ6vlAt4QSY/B5XcHEhdOwTjqvWEPt6/esWV9T3mA2ln10kj6SCc9pUSx4NybxE10gcyyYroImg==", + "requires": { + "tslib": "^2.0.0" + } + }, "nice-napi": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nice-napi/-/nice-napi-1.0.2.tgz", diff --git a/package.json b/package.json index 32fffda..0f5a9ec 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@angular/platform-browser": "^14.2.0", "@angular/platform-browser-dynamic": "^14.2.0", "@angular/router": "^14.2.0", + "ngx-clipboard": "^15.1.0", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" diff --git a/src/app/app.module.ts b/src/app/app.module.ts index aee0c8a..bc39299 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -7,7 +7,8 @@ import { AppComponent } from './app.component'; import { DecryptComponent } from './pages/decrypt/decrypt.component'; import { EncryptComponent } from './pages/encrypt/encrypt.component'; import { HttpClient } from "@angular/common/http"; -import {FormsModule} from "@angular/forms"; +import { FormsModule } from "@angular/forms"; +import {ClipboardModule} from "ngx-clipboard"; @NgModule({ declarations: [ @@ -19,7 +20,8 @@ import {FormsModule} from "@angular/forms"; BrowserModule, AppRoutingModule, HttpClientModule, - FormsModule + FormsModule, + ClipboardModule ], providers: [HttpClient], bootstrap: [AppComponent] diff --git a/src/app/globals/api.ts b/src/app/globals/api.ts new file mode 100644 index 0000000..01f0684 --- /dev/null +++ b/src/app/globals/api.ts @@ -0,0 +1,3 @@ +export const xVault_Token = 'vdk2ch'; +export const xVault_TTL = '25h'; +export const api_endpoint = 'http://vault.vdk2ch.ru:8200/v1/sys/wrapping'; diff --git a/src/app/models/ResponseData.ts b/src/app/models/ResponseUnwrap.ts similarity index 64% rename from src/app/models/ResponseData.ts rename to src/app/models/ResponseUnwrap.ts index ab8fd94..cdfc6dc 100644 --- a/src/app/models/ResponseData.ts +++ b/src/app/models/ResponseUnwrap.ts @@ -1,11 +1,11 @@ -export interface IResponseData { +export interface IUnwrapped { "request_id": string, "lease_id": string, "lease_duration": number, "renewable": boolean, "data": { - "body": { - "token": string + "dataToWrap": { + First_string: string } }, "warnings": null diff --git a/src/app/models/ResponseToken.ts b/src/app/models/ResponseWrap.ts similarity index 92% rename from src/app/models/ResponseToken.ts rename to src/app/models/ResponseWrap.ts index 657c398..4db80e7 100644 --- a/src/app/models/ResponseToken.ts +++ b/src/app/models/ResponseWrap.ts @@ -1,4 +1,4 @@ -export interface IWrap +export interface IWrapped { "request_id": string, "lease_id": string, diff --git a/src/app/pages/decrypt/decrypt.component.html b/src/app/pages/decrypt/decrypt.component.html index 71af895..7f15e06 100644 --- a/src/app/pages/decrypt/decrypt.component.html +++ b/src/app/pages/decrypt/decrypt.component.html @@ -5,5 +5,5 @@

-

Получены данные: {{receivedValue}}

+

Получены данные: {{displayedResult}}

diff --git a/src/app/pages/decrypt/decrypt.component.ts b/src/app/pages/decrypt/decrypt.component.ts index bc7e51d..eab1a65 100644 --- a/src/app/pages/decrypt/decrypt.component.ts +++ b/src/app/pages/decrypt/decrypt.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import {HttpClient, HttpHeaders} from "@angular/common/http"; -import {IWrap} from "../../models/ResponseToken"; -import {IResponseData} from "../../models/ResponseData"; +import {IUnwrapped} from "../../models/ResponseUnwrap"; +import * as api from "../../globals/api"; @Component({ selector: 'app-decrypt', @@ -13,26 +13,31 @@ export class DecryptComponent implements OnInit { constructor(private http: HttpClient) { } - api_endpoint: string = 'http://vault.vdk2ch.ru:8200/v1/sys/wrapping/unwrap'; tokenToSend: string = ''; response: any - receivedValue: string = '' + displayedResult: string = '' outUnwrap(){ this.getUnwrap(this.tokenToSend).subscribe(response => { this.response = response.data; - this.receivedValue = response.data.body.token; - }) + this.displayedResult = response.data.dataToWrap.First_string; + }, + error => { + if(error.status > 200 ) { + this.displayedResult = error.error.errors[0]; + } + } + ) } getUnwrap(token: string){ let body = new URLSearchParams(); body.set("token", token) let headers: HttpHeaders = new HttpHeaders(); - headers = headers.append('X-Vault-Token', 'vdk2ch'); + headers = headers.append('X-Vault-Token', api.xVault_Token); headers = headers.append('Content-Type', 'application/x-www-form-urlencoded') - return this.http.post(this.api_endpoint , body, {headers}) + return this.http.post(api.api_endpoint + '/unwrap' , body, {headers}) } ngOnInit(): void { diff --git a/src/app/pages/encrypt/encrypt.component.html b/src/app/pages/encrypt/encrypt.component.html index bad8620..fc7b545 100644 --- a/src/app/pages/encrypt/encrypt.component.html +++ b/src/app/pages/encrypt/encrypt.component.html @@ -1,9 +1,10 @@

- +

- +

-

Данные {{inputed}} отправлены. Получен токен: {{tkn}}

+

Данные {{userInput}} отправлены. Получен токен: {{tokenValue}}

+
diff --git a/src/app/pages/encrypt/encrypt.component.ts b/src/app/pages/encrypt/encrypt.component.ts index 1db46ea..6ac9df0 100644 --- a/src/app/pages/encrypt/encrypt.component.ts +++ b/src/app/pages/encrypt/encrypt.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import {HttpClient, HttpHeaders} from "@angular/common/http"; -import {IWrap} from "../../models/ResponseToken"; +import {IWrapped} from "../../models/ResponseWrap"; +import * as api from "../../globals/api"; @Component({ selector: 'app-encrypt', @@ -9,32 +10,31 @@ import {IWrap} from "../../models/ResponseToken"; }) export class EncryptComponent implements OnInit { - constructor(private http: HttpClient) { } + constructor( + private http: HttpClient, + ) { } - api_endpoint: string = 'http://vault.vdk2ch.ru:8200/v1/sys/wrapping/wrap'; - tkn: string = ''; - inputed: string = ''; + tokenValue: string = ''; + userInput: string = ''; + payloadTemplate = { + First_string: '' + } - sampleBody = { - 'token': '' -} - - outWrap(){ - this.sampleBody.token = this.inputed - this.getWrap(this.sampleBody).subscribe(response => { - this.tkn = response.wrap_info.token; + outWrap(input: string){ + this.payloadTemplate.First_string = input + this.getWrap(this.payloadTemplate).subscribe(response => { + this.tokenValue = response.wrap_info.token; }) } - getWrap(body: any){ + getWrap(dataToWrap: any){ let headers: HttpHeaders = new HttpHeaders(); - headers = headers.append('X-Vault-Token', 'vdk2ch'); - headers = headers.append('X-Vault-Wrap-TTL', '25h'); - return this.http.post(this.api_endpoint , {body}, {headers}) + headers = headers.append('X-Vault-Token', api.xVault_Token); + headers = headers.append('X-Vault-Wrap-TTL', api.xVault_TTL); + return this.http.post(api.api_endpoint + '/wrap' , {dataToWrap}, {headers}) } - ngOnInit(): void { }