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 <sandhya.j@tataelxsi.co.in>
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 @@
         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
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 @@
   /** 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 @@
   /** 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 @@
     });
   }
 
+  /** 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 @@
       // Catch Navigation Error
     });
   }
+
+  /** Change the detaction @public */
+  public changeDetactionforDownload(): void {
+    setTimeout(() => {
+      this.cd.detectChanges();
+    }, this.timeOut);
+  }
 }