import { Component, OnInit } from '@angular/core';
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {IWrap} from "../../models/ResponseToken";

@Component({
  selector: 'app-encrypt',
  templateUrl: './encrypt.component.html',
  styleUrls: ['./encrypt.component.scss']
})
export class EncryptComponent implements OnInit {

  constructor(private http: HttpClient) { }

  api_endpoint: string = 'http://vault.vdk2ch.ru:8200/v1/sys/wrapping/wrap';
  tkn: string = '';
  inputed: string = '';

  sampleBody = {
    'token': ''
}

  outWrap(){
    this.sampleBody.token = this.inputed
    this.getWrap(this.sampleBody).subscribe(response => {
      this.tkn = response.wrap_info.token;
    })
  }

  getWrap(body: 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<IWrap>(this.api_endpoint , {body}, {headers})
  }



  ngOnInit(): void {
  }


}
