Skip to content

Commit

Permalink
CHE-8538 fix removing SSH key errors for UD
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Mar 10, 2018
1 parent 8d26f5f commit 91d1f68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {CheSsh} from '../../../../components/api/che-ssh.factory';
*/
export class WorkspaceDetailsSshCtrl {

static $inject = ['$route', 'cheSsh', 'cheWorkspace', 'cheNotification', '$mdDialog', '$log', '$q'];
static $inject = ['$route', 'cheSsh', 'cheWorkspace', 'cheNotification', '$mdDialog', '$log', '$q', '$timeout'];

/**
* Workspace.
Expand Down Expand Up @@ -62,6 +62,10 @@ export class WorkspaceDetailsSshCtrl {
private workspaceId: string;

private sshKeyPair : any;
/**
* Loading state of the page.
*/
private isLoading: boolean;

/**
* True if one machine has ssh agent enabled.
Expand All @@ -79,13 +83,15 @@ export class WorkspaceDetailsSshCtrl {
cheNotification: CheNotification,
$mdDialog: ng.material.IDialogService,
$log: ng.ILogService,
$q: ng.IQService) {
$q: ng.IQService,
$timeout : ng.ITimeoutService) {
this.cheWorkspace = cheWorkspace;
this.cheSsh = cheSsh;
this.cheNotification = cheNotification;
this.$mdDialog = $mdDialog;
this.$log = $log;
this.$q = $q;
this.$timeout = $timeout;

this.machineSshAgents = [];
this.namespace = $route.current.params.namespace;
Expand All @@ -102,10 +108,12 @@ export class WorkspaceDetailsSshCtrl {
this.workspace = this.cheWorkspace.getWorkspaceByName(this.namespace, this.workspaceName);
this.workspaceId = this.workspace.id;

this.isLoading = true;

// get ssh key
this.cheSsh.fetchKey('workspace', this.workspaceId).finally(() => {
this.sshKeyPair = this.cheSsh.getKey('workspace', this.workspaceId);

this.isLoading = false;
});

let defaultEnv : string = this.workspace.config.defaultEnv;
Expand All @@ -127,22 +135,30 @@ export class WorkspaceDetailsSshCtrl {
* Remove the default workspace keypair
*/
removeDefaultKey() {
this.isLoading = true;
this.cheSsh.removeKey('workspace', this.workspaceId).then(
() => {
this.$timeout(() => {
this.updateData();
}, 3000);
}, (error: any) => {
this.isLoading = false;
this.$log.error('Cannot remove default key: ', error);
});
}

/**
* Generate a new default workspace keypair
*/
generateDefaultKey() {
this.isLoading = true;
this.cheSsh.generateKey('workspace', this.workspaceId).then(() => {
this.$timeout(() => {
this.updateData();
}, 3000);
}, (error: any) => {
this.isLoading = false;
this.$log.error('Cannot generate default key: ', error);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
Red Hat, Inc. - initial API and implementation
-->
<div class="progress-line">
<md-progress-linear md-mode="indeterminate"
ng-show="workspaceDetailsSshCtrl.isLoading"></md-progress-linear>
</div>
<md-content flex class="workspace-ssh-content">

<div layout="row" flex class="workspace-ssh-content-invalid-notification" ng-if="workspaceDetailsSshCtrl.workspace.status !== 'RUNNING'">
Expand All @@ -33,11 +37,13 @@
class=""></che-text-info>

<che-button-danger che-button-title="Remove default SSH key"
ng-disabled="workspaceDetailsSshCtrl.isLoading"
ng-click="workspaceDetailsSshCtrl.removeDefaultKey()"></che-button-danger>
</div>

<div layout="column" ng-if="!workspaceDetailsSshCtrl.sshKeyPair">
<che-button-primary che-button-title="Generate"
ng-disabled="workspaceDetailsSshCtrl.isLoading"
ng-click="workspaceDetailsSshCtrl.generateDefaultKey()"></che-button-primary>
<span class="workspace-ssh-content-notice">This workspace does not have a generated SSH key. We can generate a new one here or you can add your own in the IDE.</span>
<span ng-if="workspaceDetailsSshCtrl.workspace.status === 'RUNNING'">Note: Workspace is currently in RUNNING state. It will require a restart of the workspace in order to be taken into account.</span>
Expand Down

0 comments on commit 91d1f68

Please sign in to comment.