Get_Credentials requirement in Advanced Cluster Managemnt 35/14635/4
authorSANDHYA.JS <sandhya.j@tataelxsi.co.in>
Tue, 15 Oct 2024 06:11:45 +0000 (11:41 +0530)
committerSANDHYA.JS <sandhya.j@tataelxsi.co.in>
Wed, 6 Nov 2024 06:14:47 +0000 (11:44 +0530)
- Added get credentials button under k8s action to download the
  get credentials .yaml file

Change-Id: I38f8017e5265e4e8abaf12340a1c85c98c08fc22
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
src/app/k8s/k8s-action/K8sActionComponent.html
src/app/k8s/k8s-action/K8sActionComponent.ts
src/assets/i18n/de.json
src/assets/i18n/en.json
src/assets/i18n/es.json
src/assets/i18n/pt.json
src/services/SharedService.ts

index ddce99c..efa3616 100644 (file)
@@ -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}}">
         <i class="fas fa-compress-alt"></i> {{'PAGE.K8S.SCALE' | translate}}
       </button>
+      <button *ngIf="!isKSU && !isProfile && isCluster" type="button" class="btn btn-primary dropdown-item"
+        placement="left" (click)="getCredentials()" container="body" ngbTooltip="{{'PAGE.K8S.GETCREDENTIALS' | translate}}">
+        <i class="fas fa-download icons"></i> {{'PAGE.K8S.GETCREDENTIALS' | translate}}
+      </button>
     </div>
-  </div>
\ No newline at end of file
+  </div>
+  <app-loader [waitingMessage]="message" *ngIf="isLoadingDownloadResult"></app-loader>
\ No newline at end of file
index eef33ca..4723deb 100644 (file)
 /**
  * @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);
+  }
 }
index 727432c..5827990 100644 (file)
             "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",
index 34f99c9..6d496de 100644 (file)
             "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",
index 1f08c66..db9c80a 100644 (file)
             "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",
index 2dfe108..5f28681 100644 (file)
             "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",
index 4b7bc76..2a87382 100644 (file)
@@ -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();
             }