Skip to content

Commit a6fc3cc

Browse files
committed
refactor: way to change region and profile, now session flow is managed more clearly
1 parent d1623dd commit a6fc3cc

File tree

6 files changed

+39
-33
lines changed

6 files changed

+39
-33
lines changed

src/app/services/credentials.service.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ export class CredentialsService extends NativeService {
6767

6868
refreshCredentials() {
6969
// Get all the info we need
70-
const workspace = this.configurationService.getDefaultWorkspaceSync();
71-
7270
if (!this.refreshStrategySubcribeAll) {
7371
this.refreshStrategySubcribeAll = true;
7472
concat(
75-
this.awsStrategy.refreshCredentials(workspace),
76-
this.azureStrategy.refreshCredentials(workspace),
77-
this.awsSsoStrategy.refreshCredentials(workspace)
73+
this.awsStrategy.refreshCredentials(this.configurationService),
74+
this.azureStrategy.refreshCredentials(this.configurationService),
75+
this.awsSsoStrategy.refreshCredentials(this.configurationService)
7876
).subscribe(
7977
() => {
8078
this.appService.redrawList.emit(true);

src/app/services/workspace.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Injectable} from '@angular/core';
1+
import {EventEmitter, Injectable} from '@angular/core';
22
import {HttpClient} from '@angular/common/http';
33
import {AppService, LoggerLevel, ToastLevel} from '../services-system/app.service';
44
import {NativeService} from '../services-system/native-service';
@@ -13,9 +13,15 @@ import {ProxyService} from './proxy.service';
1313
import {environment} from '../../environments/environment';
1414
import {KeychainService} from '../services-system/keychain.service';
1515
import {SessionService} from './session.service';
16+
import {CredentialsService} from './credentials.service';
1617

1718
// Import AWS node style
1819
const AWS = require('aws-sdk');
20+
21+
export enum SessionStatus {
22+
ERROR
23+
}
24+
1925
@Injectable({
2026
providedIn: 'root'
2127
})
@@ -259,7 +265,7 @@ export class WorkspaceService extends NativeService {
259265
// Something went wrong save it to the logger file
260266
this.appService.logger(err.code, LoggerLevel.ERROR, this);
261267
this.appService.logger(err.stack, LoggerLevel.ERROR, this);
262-
// this.appService.toast('There was a problem assuming role with SAML, please retry', ToastLevel.WARN);
268+
this.appService.toast('There was a problem assuming role with SAML, please retry', ToastLevel.WARN);
263269

264270
// Emit ko
265271
this.appService.refreshReturnStatusEmit.emit(session);

src/app/session/session-card/session-card.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</ng-container>
1010
</div>
1111
<div class="information-offset" (click)="switchCredentials()">
12-
<i class="status-item fas fa-circle {{session.active ? 'active' : 'offline'}}" *ngIf="!session.loading"></i>
13-
<i class="status-item far fa-spinner-third fa-spin" *ngIf="session.loading"></i>
12+
<i class="status-item fas fa-circle {{session.active ? 'active' : 'offline'}}" *ngIf="!(session.loading && (session.account.type === eAccountType.AWS_SSO))"></i>
13+
<i class="status-item far fa-spinner-third fa-spin" *ngIf="session.loading && (session.account.type === eAccountType.AWS_SSO)"></i>
1414
</div>
1515

1616
<ng-container dropdown placement="right" [autoClose]="true">
@@ -82,7 +82,7 @@
8282
<ng-select bindLabel="{{session.account.type === eAccountType.AZURE ? 'location' : 'region'}}" bindValue="{{session.account.type === eAccountType.AZURE ? 'location' : 'region'}}" [items]="regionOrLocations" [(ngModel)]="selectedDefaultRegion" placeholder="{{placeholder}}"></ng-select>
8383

8484
<button type="button" (click)="goBack();" class="pull-left disabled">Back</button>
85-
<button type="button" (click)="changeDefaultRegion();" [disabled]="!selectedDefaultRegion" [ngClass]="(!selectedDefaultRegion) ? 'pull-right disabled': 'pull-right'">Save</button>
85+
<button type="button" (click)="changeRegion();" [disabled]="!selectedDefaultRegion" [ngClass]="(!selectedDefaultRegion) ? 'pull-right disabled': 'pull-right'">Save</button>
8686
</div>
8787
</div>
8888
</ng-template>
@@ -104,7 +104,7 @@
104104
placeholder="select a profile"></ng-select>
105105

106106
<button type="button" (click)="goBack();" class="pull-left disabled">Back</button>
107-
<button type="button" (click)="changeDefaultProfile();" [disabled]="!selectedProfile" [ngClass]="(!selectedProfile) ? 'pull-right disabled': 'pull-right'">Save</button>
107+
<button type="button" (click)="changeProfile();" [disabled]="!selectedProfile" [ngClass]="(!selectedProfile) ? 'pull-right disabled': 'pull-right'">Save</button>
108108
</div>
109109
</div>
110110
</ng-template>

src/app/session/session-card/session-card.component.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,23 @@ export class SessionCardComponent extends AntiMemLeak implements OnInit {
248248
/**
249249
* Set the region for the session
250250
*/
251-
changeDefaultRegion() {
251+
changeRegion() {
252252
if (this.selectedDefaultRegion) {
253-
this.workspace = this.configurationService.getDefaultWorkspaceSync();
254-
255-
this.workspace.sessions.forEach(session => {
256-
if (session.id === this.session.id) {
257-
session.account.region = this.selectedDefaultRegion;
258-
this.session.account.region = this.selectedDefaultRegion;
259-
this.configurationService.updateWorkspaceSync(this.workspace);
260-
261-
this.sessionService.invalidateSessionToken(session);
262-
263-
if (this.session.active) {
264-
this.startSession();
265-
} else {
266-
this.appService.redrawList.emit(true);
267-
}
268-
}
269-
});
253+
254+
if (this.session.active) {
255+
this.sessionService.stopSession(this.session);
256+
}
257+
258+
this.session.account.region = this.selectedDefaultRegion;
259+
this.sessionService.invalidateSessionToken(this.session);
260+
this.sessionService.updateSession(this.session);
261+
262+
if (this.session.active) {
263+
this.startSession();
264+
} else {
265+
this.appService.redrawList.emit(true);
266+
}
267+
270268

271269
this.appService.toast('Default region has been changed!', ToastLevel.SUCCESS, 'Region changed!');
272270
this.modalRef.hide();
@@ -321,10 +319,10 @@ export class SessionCardComponent extends AntiMemLeak implements OnInit {
321319
}
322320
}
323321

324-
changeDefaultProfile() {
322+
changeProfile() {
325323
if (this.selectedProfile) {
326324
if (this.session.active) {
327-
this.sessionService.removeFromIniFile(this.session.profile);
325+
this.sessionService.stopSession(this.session);
328326
}
329327

330328
this.sessionService.addProfile(this.selectedProfile);

src/app/shared/tray-menu/tray-menu.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class TrayMenuComponent extends AntiMemLeak implements OnInit {
4949
let icon = '';
5050
let label = '';
5151
const profile = this.configurationService.getDefaultWorkspaceSync().profiles.filter(p => p.id === session.profile)[0];
52-
const iconValue = profile.name === 'default' ? 'home' : 'user';
52+
const iconValue = (profile && profile.name === 'default') ? 'home' : 'user';
5353

5454
switch (session.account.type) {
5555
case AccountType.AWS_PLAIN_USER:

src/app/strategies/refreshCredentialsStrategy.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import {Workspace} from '../models/workspace';
22
import {Session} from '../models/session';
33
import {concat, Observable, of} from 'rxjs';
4+
import {CredentialsService} from '../services/credentials.service';
5+
import {ConfigurationService} from '../services-system/configuration.service';
46

57
export abstract class RefreshCredentialsStrategy {
6-
refreshCredentials(workspace: Workspace): Observable<any> {
8+
refreshCredentials(configurationService: ConfigurationService): Observable<any> {
9+
const workspace = configurationService.getDefaultWorkspaceSync();
10+
711
const activeSessions = this.getActiveSessions(workspace);
812

913
// Refresh all active sessions credentials

0 commit comments

Comments
 (0)