From b5347157689e7d2fe9cab7c9233d00b2eed0a853 Mon Sep 17 00:00:00 2001 From: "SANDHYA.JS" Date: Tue, 15 Oct 2024 11:41:45 +0530 Subject: [PATCH] Get_Credentials requirement in Advanced Cluster Managemnt - Added get credentials button under k8s action to download the get credentials .yaml file Change-Id: I38f8017e5265e4e8abaf12340a1c85c98c08fc22 Signed-off-by: SANDHYA.JS --- .../k8s/k8s-action/K8sActionComponent.html | 7 +- src/app/k8s/k8s-action/K8sActionComponent.ts | 82 ++++++++++++++++++- src/assets/i18n/de.json | 3 +- src/assets/i18n/en.json | 3 +- src/assets/i18n/es.json | 3 +- src/assets/i18n/pt.json | 3 +- src/services/SharedService.ts | 12 ++- 7 files changed, 103 insertions(+), 10 deletions(-) diff --git a/src/app/k8s/k8s-action/K8sActionComponent.html b/src/app/k8s/k8s-action/K8sActionComponent.html index ddce99c..efa3616 100644 --- a/src/app/k8s/k8s-action/K8sActionComponent.html +++ b/src/app/k8s/k8s-action/K8sActionComponent.html @@ -89,5 +89,10 @@ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.i placement="left" (click)="editCluster('scale')" container="body" ngbTooltip="{{'PAGE.K8S.SCALE' | translate}}"> {{'PAGE.K8S.SCALE' | translate}} + - \ No newline at end of file + + \ No newline at end of file diff --git a/src/app/k8s/k8s-action/K8sActionComponent.ts b/src/app/k8s/k8s-action/K8sActionComponent.ts index eef33ca..4723deb 100644 --- a/src/app/k8s/k8s-action/K8sActionComponent.ts +++ b/src/app/k8s/k8s-action/K8sActionComponent.ts @@ -18,17 +18,21 @@ /** * @file K8 Action Component */ -import { Component, Injector } from '@angular/core'; +import { HttpHeaders } from '@angular/common/http'; +import { ChangeDetectorRef, Component, Injector } from '@angular/core'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core'; -import { MODALCLOSERESPONSEDATA } from 'CommonModel'; +import { NotifierService } from 'angular-notifier'; +import { ERRORDATA, GETAPIURLHEADER, MODALCLOSERESPONSEDATA } from 'CommonModel'; import { DeleteComponent } from 'DeleteComponent'; +import { environment } from 'environment'; import { K8sAddClusterComponent } from 'K8sAddClusterComponent'; import { K8sAttachProfileComponent } from 'K8sAttachProfileComponent'; import { K8sInfraConfigAddComponent } from 'K8sInfraConfigAddComponent'; import { INFRACONFIGPAYLOAD, K8SCLUSTERDATADISPLAY, K8SPayload, K8SREPODATADISPLAY } from 'K8sModel'; import { KSUAddComponent } from 'KSUAddComponent'; -import { SharedService } from 'SharedService'; +import { RestService } from 'RestService'; +import { isNullOrUndefined, SharedService } from 'SharedService'; import { ShowInfoComponent } from 'ShowInfoComponent'; /** * Creating component @@ -68,6 +72,9 @@ export class K8sActionComponent { /** Check cluster or not @public */ public isCluster = false; + /** Check the loading results for loader status @public */ + public isLoadingDownloadResult: boolean = false; + /** Instance of the modal service @private */ private modalService: NgbModal; @@ -77,17 +84,40 @@ export class K8sActionComponent { /** Contains instance ID @private */ private instanceID: string; + /** Utilizes rest service for any CRUD operations @private */ + private restService: RestService; + + /** Notifier service to popup notification @private */ + private notifierService: NotifierService; + + /** Detect changes for the User Input */ + private cd: ChangeDetectorRef; + + /** Set timeout @private */ + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + private timeOut: number = 1000; + + /** Controls the header form @private */ + private headers: HttpHeaders; + constructor(injector: Injector) { this.injector = injector; this.modalService = this.injector.get(NgbModal); + this.notifierService = this.injector.get(NotifierService); this.sharedService = this.injector.get(SharedService); this.translateService = this.injector.get(TranslateService); + this.restService = this.injector.get(RestService); + this.cd = this.injector.get(ChangeDetectorRef); } /** * Lifecyle Hooks the trigger before component is instantiate */ public ngOnInit(): void { + this.headers = new HttpHeaders({ + Accept: 'application/zip, application/json', + 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0' + }); this.instanceID = this.value.identifier; this.getK8sType = this.value.pageType; this.state = this.value.state; @@ -219,6 +249,45 @@ export class K8sActionComponent { }); } + /** Download credentials @public */ + public getCredentials(): void { + this.isLoadingDownloadResult = true; + const httpOptions: GETAPIURLHEADER = { + headers: this.headers, + responseType: 'blob' + }; + this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.instanceID + '/get_creds') + .subscribe((res: { op_id: string }) => { + if (!isNullOrUndefined(res.op_id)) { + this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.instanceID + '/get_creds_file' + '/' + res.op_id, httpOptions) + .subscribe((response: Blob) => { + this.isLoadingDownloadResult = true; + if (!isNullOrUndefined(response)) { + this.isLoadingDownloadResult = false; + const binaryData: Blob[] = []; + binaryData.push(response); + this.sharedService.downloadFiles(this.value.name, binaryData, response.type); + this.isLoadingDownloadResult = false; + this.changeDetactionforDownload(); + } + }, (error: ERRORDATA) => { + this.isLoadingDownloadResult = false; + this.notifierService.notify('error', this.translateService.instant('ERROR')); + this.changeDetactionforDownload(); + if (typeof error.error === 'object') { + error.error.text().then((data: string): void => { + error.error = JSON.parse(data); + this.restService.handleError(error, 'getBlob'); + }); + } + }); + } + }, (error: ERRORDATA) => { + this.isLoadingDownloadResult = false; + this.restService.handleError(error, 'get'); + }); + } + /** Clone KSU @public */ public cloneKsu(): void { // eslint-disable-next-line security/detect-non-literal-fs-filename @@ -233,4 +302,11 @@ export class K8sActionComponent { // Catch Navigation Error }); } + + /** Change the detaction @public */ + public changeDetactionforDownload(): void { + setTimeout(() => { + this.cd.detectChanges(); + }, this.timeOut); + } } diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index 727432c..5827990 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -571,7 +571,8 @@ "UPLOADCONFIGGZLABEL": "Bitte laden Sie die Datei im tar.gz-Format hoch", "REGISTEREDSUCCESSFULLY": "K8s Erfolgreich registriert", "OKA": "OKA", - "PATH": "SW-Katalogpfad" + "PATH": "SW-Katalogpfad", + "GETCREDENTIALS": "Anmeldeinformationen abrufen" }, "OSMREPO": { "MENUOSMREPO": "OSM-Repositorys", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 34f99c9..6d496de 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -571,7 +571,8 @@ "UPLOADCONFIGGZLABEL": "Please upload file with tar.gz format", "REGISTEREDSUCCESSFULLY": "K8s Registered Successfully", "OKA": "OKA", - "PATH": "SW Catalog Path" + "PATH": "SW Catalog Path", + "GETCREDENTIALS": "Get Credentials" }, "OSMREPO": { "MENUOSMREPO": "OSM Repositories", diff --git a/src/assets/i18n/es.json b/src/assets/i18n/es.json index 1f08c66..db9c80a 100644 --- a/src/assets/i18n/es.json +++ b/src/assets/i18n/es.json @@ -571,7 +571,8 @@ "UPLOADCONFIGGZLABEL": "Por favor, cargue el archivo con formato tar.gz", "REGISTEREDSUCCESSFULLY": "K8s Registrado con éxito", "OKA": "OKA", - "PATH": "Ruta del catálogo SW" + "PATH": "Ruta del catálogo SW", + "GETCREDENTIALS": "Obtener credenciales" }, "OSMREPO": { "MENUOSMREPO": "Repositorios OSM", diff --git a/src/assets/i18n/pt.json b/src/assets/i18n/pt.json index 2dfe108..5f28681 100644 --- a/src/assets/i18n/pt.json +++ b/src/assets/i18n/pt.json @@ -571,7 +571,8 @@ "UPLOADCONFIGGZLABEL": "Carregue o ficheiro no formato tar.gz", "REGISTEREDSUCCESSFULLY": "K8s registado com sucesso", "OKA": "OKA", - "PATH": "Caminho do Catálogo SW" + "PATH": "Caminho do Catálogo SW", + "GETCREDENTIALS": "Obter credenciais" }, "OSMREPO": { "MENUOSMREPO": "Repositórios OSM", diff --git a/src/services/SharedService.ts b/src/services/SharedService.ts index 4b7bc76..2a87382 100644 --- a/src/services/SharedService.ts +++ b/src/services/SharedService.ts @@ -246,9 +246,17 @@ export class SharedService { // eslint-disable-next-line @typescript-eslint/no-explicit-any const newVariable: any = window.navigator; if (newVariable.msSaveOrOpenBlob) { - newVariable.msSaveBlob(new Blob(binaryData, { type: filetype }), 'OSM_Export_' + name + '.tar.gz'); + if (filetype === 'text/plain') { + newVariable.msSaveBlob(new Blob(binaryData, { type: 'text/yaml' }), 'OSM_Export_' + name + '.yaml'); + } else { + newVariable.msSaveBlob(new Blob(binaryData, { type: filetype }), 'OSM_Export_' + name + '.tar.gz'); + } } else { - downloadLink.setAttribute('download', 'OSM_Export_' + name + '.tar.gz'); + if (filetype === 'text/plain') { + downloadLink.setAttribute('download', 'OSM_Export_' + name + '.yaml'); + } else { + downloadLink.setAttribute('download', 'OSM_Export_' + name + '.tar.gz'); + } document.body.appendChild(downloadLink); downloadLink.click(); } -- 2.25.1