diff --git a/src/app/accountinfo/accountinfo.component.html b/src/app/accountinfo/accountinfo.component.html index e59a260ae5a9df27074c6d6ee6c5bf6f64c1f612..8aa198a3359a9bbe0eedc712b588dd5c31d2423c 100644 --- a/src/app/accountinfo/accountinfo.component.html +++ b/src/app/accountinfo/accountinfo.component.html @@ -1,4 +1,7 @@ <div fxLayout="column" fxLayoutAlign="start none" style="width: 100%" class="strudel-accountinfo-typography"> + <div *ngIf="nowSeconds(identity$ | async) ; let time"> + Login certificates expire in {{ time }} + </div> <div *ngIf="identity$.value !== null && identity$.value !== undefined"> <!--<div *ngIf="identity$.value.systemalerts.value !== null">--> <div *ngFor="let h of (identity$.value.systemalerts | async)"> diff --git a/src/app/accountinfo/accountinfo.component.ts b/src/app/accountinfo/accountinfo.component.ts index 2992e72621638e9312d5deabe0844121ebe40dfa..af15fc43f13cba213e09b12c03362de5383b42c3 100644 --- a/src/app/accountinfo/accountinfo.component.ts +++ b/src/app/accountinfo/accountinfo.component.ts @@ -67,4 +67,27 @@ export class AccountinfoComponent implements OnInit { } } + nowSeconds(id: Identity) { + let seconds = (id.expiry - Date.now().valueOf())/1000; + console.log('seconds remaining',seconds); + let remaining = this.secondsToHms(seconds); + console.log('login seconds remaining',remaining); + return remaining; + } + secondsToHms(d: number) { + var sign = "" + if (d < 0) { + d = -d; + sign="-" + } + + var h: number = Math.floor(d / 3600); + var m: number = Math.floor(d % 3600 / 60); + var s: number = Math.floor(d % 3600 % 60); + + var hDisplay = h > 0 ? h + (h == 1 ? " hour " : " hours ") : ""; + var mDisplay = m > 0 ? m + (m == 1 ? " minute " : " minutes ") : ""; + return sign + hDisplay + mDisplay ; + } + } diff --git a/src/app/authorisation.service.ts b/src/app/authorisation.service.ts index e00fcf8c8916ce7e1369c62345eb9f6701b51866..1104a676cfe959ca24ea23c3145ea9dd7476591a 100644 --- a/src/app/authorisation.service.ts +++ b/src/app/authorisation.service.ts @@ -207,14 +207,13 @@ public getKeys(id?: Identity) { catchError((e) => { this.querySshAgentError(e); return of([])}), tap((resp) => { console.log('agent contents',resp) }), tap((resp) => { console.log('agent contents',resp) }), + switchMap((resp) => of(this.addExpiryField(resp))), tap((resp) => { if (this.agentContents.value !== null && this.agentContents.value.length > resp.length) { this.notifications.notify("Your login expired. Please login again"); - console.log('login expired'); } else { this.notifications.notify(""); }; - console.log('updating agent contents'); this.agentContents.next(resp) }), catchError((e) => { console.error('updateAGentContents error',e) ; return of([])}) @@ -223,6 +222,17 @@ public getKeys(id?: Identity) { return agentpipe$ } + private addExpiryField(resp): any[] { + var res: any[] + res = [] + for (let id of resp) { + var validstr: String; + validstr = id.Valid[0]; + id.expiry = Date.parse(validstr.split(" ")[3]) + res.push(id); + } + return res + } private killAgent() { this.notifications.notify("Logging out") diff --git a/src/app/computesites.service.ts b/src/app/computesites.service.ts index 2a1e9954a22018e739faaeb792fb71b6451e9602..42b049926055d3dcf7bb3e3088e258d0c440a0f3 100644 --- a/src/app/computesites.service.ts +++ b/src/app/computesites.service.ts @@ -204,7 +204,7 @@ export class ComputesitesService { let principals = this.siteMatch(certs[i],cs); for (let principal of principals) { if (principal != null) { - let id = new Identity(principal,cs); + let id = new Identity(principal,cs,certs[i].expiry); identities.push(id); if (cs.appCatalogUri != null || cs.appCatalogCmd != null) { appidentities.push(id); diff --git a/src/app/identity.ts b/src/app/identity.ts index a037fbbb9dacc25455978eef0f3b5f862f0ccf79..ac8610079b5f224d3e3b00c2447eb178228eca8b 100644 --- a/src/app/identity.ts +++ b/src/app/identity.ts @@ -12,7 +12,8 @@ export class Identity { accountalerts: BehaviorSubject<Health[]>; joblist: BehaviorSubject<Job[]>; quotas: any[]; - constructor( username: string, site: Computesite) { + expiry: number; + constructor( username: string, site: Computesite, expiry: number) { this.username = username; this.site = site; this.keyCerts = []; @@ -20,10 +21,11 @@ export class Identity { this.accountalerts = new BehaviorSubject<Health[]>(null); this.joblist = new BehaviorSubject<Job[]>([]); this.quotas = []; + this.expiry = expiry; } copy_skip_catalog(): Identity { - let id = new Identity(null,null); + let id = new Identity(null,null,null); id.username = this.username; id.systemalerts = null; id.accountalerts = null;