From 468c89b890bef5f4ddf4a2abadb1aae8fac4ef22 Mon Sep 17 00:00:00 2001 From: marijanlekic Date: Fri, 13 Nov 2020 11:57:04 +0100 Subject: [PATCH] fix(platform): Update platform urls --- src/app/auth/model/auth-credentials.ts | 45 +++++++---- .../platform-credentials-modal.component.ts | 77 ++++++++++--------- .../platform-app.service.ts | 16 +++- 3 files changed, 83 insertions(+), 55 deletions(-) diff --git a/src/app/auth/model/auth-credentials.ts b/src/app/auth/model/auth-credentials.ts index e5fe0db8d..cc5b2d99d 100644 --- a/src/app/auth/model/auth-credentials.ts +++ b/src/app/auth/model/auth-credentials.ts @@ -1,10 +1,10 @@ -import {User} from "../../../../electron/src/sbg-api-client/interfaces/user"; -import {UserPlatformIdentifier} from "./user-platform-identifier"; +import { User } from "../../../../electron/src/sbg-api-client/interfaces/user"; +import { UserPlatformIdentifier } from "./user-platform-identifier"; interface PlatformEntry { name: string; shortName: string; - devTokenURL: string; + platformURL: string; } export class AuthCredentials implements UserPlatformIdentifier { @@ -13,39 +13,54 @@ export class AuthCredentials implements UserPlatformIdentifier { static readonly TOKEN_VALIDATION_REGEXP = "^[0-9a-f]{8}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{4}[0-9a-f]{12}$"; + static readonly stagingLookupByAPIURL: { [key: string]: PlatformEntry } = { + "https://staging-api.sbgenomics.com": { + "name": "Seven Bridges", + "shortName": "SBG STAGING", + "platformURL": "https://staging-igor.sbgenomics.com" + }, + "https://cgc-staging-api.sbgenomics.com" : { + "name": "Seven Bridges", + "shortName": "CGC STAGING", + "platformURL": "https://cgc-staging.sbgenomics.com" + } + }; + static readonly platformLookupByAPIURL: { [key: string]: PlatformEntry } = { "https://api.sbgenomics.com": { "name": "Seven Bridges", "shortName": "SBG", - "devTokenURL": "https://igor.sbgenomics.com/developer#token", + "platformURL": "https://igor.sbgenomics.com" }, "https://eu-api.sbgenomics.com": { "name": "Seven Bridges (EU)", "shortName": "SBG-EU", - "devTokenURL": "https://eu.sbgenomics.com/developer#token", + "platformURL": "https://eu.sbgenomics.com" }, "https://api.sb.biodatacatalyst.nhlbi.nih.gov": { "name": "BioData Catalyst", "shortName": "BDCatalyst", - "devTokenURL": "https://platform.sb.biodatacatalyst.nhlbi.nih.gov/developer/#token", + "platformURL": "https://platform.sb.biodatacatalyst.nhlbi.nih.gov", }, "https://cgc-api.sbgenomics.com": { "name": "Cancer Genomics Cloud", "shortName": "CGC", - "devTokenURL": "https://cgc.sbgenomics.com/developer#token", + "platformURL": "https://cgc.sbgenomics.com" }, "https://cavatica-api.sbgenomics.com": { "name": "Cavatica", "shortName": "CAVATICA", - "devTokenURL": "https://cavatica.sbgenomics.com/developer#token", + "platformURL": "https://cavatica.sbgenomics.com" }, "https://api.sevenbridges.cn": { "name": "Seven Bridges (China)", "shortName": "SBG-CN", - "devTokenURL": "https://platform.sevenbridges.cn/developer#token", + "platformURL": "https://platform.sevenbridges.cn", }, }; + static readonly platformDevTokenPath = "/developer#token"; + id: string; user: User; url: string; @@ -55,9 +70,9 @@ export class AuthCredentials implements UserPlatformIdentifier { // this.ensureValidURL(url); // this.ensureValidToken(token); - this.url = url; + this.url = url; this.token = token; - this.user = user; + this.user = user; this.id = this.getHash(); } @@ -96,8 +111,8 @@ export class AuthCredentials implements UserPlatformIdentifier { * @see {@link AuthCredentials.equals} Instance method for comparing equality to another instance */ static isSimilar(x?: AuthCredentials, y?: AuthCredentials): boolean { - const onlyXExists = x !== undefined && y === undefined; - const onlyYExists = y !== undefined && x === undefined; + const onlyXExists = x !== undefined && y === undefined; + const onlyYExists = y !== undefined && x === undefined; const neitherExist = x === undefined && y === undefined; if (onlyXExists || onlyYExists) { @@ -131,9 +146,9 @@ export class AuthCredentials implements UserPlatformIdentifier { } updateToMatch(credentials: AuthCredentials): void { - this.url = credentials.url; + this.url = credentials.url; this.token = credentials.token; - this.user = credentials.user; + this.user = credentials.user; } private ensureValidToken(token: string): void { diff --git a/src/app/core/modals/platform-credentials-modal/platform-credentials-modal.component.ts b/src/app/core/modals/platform-credentials-modal/platform-credentials-modal.component.ts index c1c33b06d..4b9479d6e 100644 --- a/src/app/core/modals/platform-credentials-modal/platform-credentials-modal.component.ts +++ b/src/app/core/modals/platform-credentials-modal/platform-credentials-modal.component.ts @@ -55,9 +55,9 @@ import {withLatestFrom, take} from "rxjs/operators"; -
+
- + Token cannot be empty @@ -161,42 +161,42 @@ export class PlatformCredentialsModalComponent implements OnInit { take(1) ).subscribe((results: [AuthCredentials | undefined, AuthCredentials[]]) => { - const [active, all] = results; + const [active, all] = results; - // Determine whether we are adding new creds or updating old ones - const isEditing = this.tokenOnly; + // Determine whether we are adding new creds or updating old ones + const isEditing = this.tokenOnly; - const editedCredentials = new AuthCredentials(url, token, user); + const editedCredentials = new AuthCredentials(url, token, user); - let maybeUserUpdate = Promise.resolve(); + let maybeUserUpdate = Promise.resolve(); - if (isEditing) { - if (editedCredentials.equals(active) || this.forceActivateUser) { - // If we are editing credentials that appear to be active, update it - maybeUserUpdate = this.auth.setActiveCredentials(editedCredentials); - } - - } else { - // Activate added credentials - maybeUserUpdate = this.auth.setActiveCredentials(credentials); - const component = this.notificationBarService.showDynamicNotification(GetStartedNotificationComponent, { - type: "success" - }); - - component.environment = AuthCredentials.getPlatformLabel(url); - component.username = user.username; - - component.dismiss.pipe( - take(1) - ).subscribe(() => { - this.notificationBarService.dismissDynamicNotification(component); - }); + if (isEditing) { + if (editedCredentials.equals(active) || this.forceActivateUser) { + // If we are editing credentials that appear to be active, update it + maybeUserUpdate = this.auth.setActiveCredentials(editedCredentials); } - maybeUserUpdate.then(() => this.global.reloadPlatformData()); + } else { + // Activate added credentials + maybeUserUpdate = this.auth.setActiveCredentials(credentials); + const component = this.notificationBarService.showDynamicNotification(GetStartedNotificationComponent, { + type: "success" + }); - this.submit.next(true); - }); + component.environment = AuthCredentials.getPlatformLabel(url); + component.username = user.username; + + component.dismiss.pipe( + take(1) + ).subscribe(() => { + this.notificationBarService.dismissDynamicNotification(component); + }); + } + + maybeUserUpdate.then(() => this.global.reloadPlatformData()); + + this.submit.next(true); + }); } @@ -229,7 +229,7 @@ export class PlatformCredentialsModalComponent implements OnInit { if (!(val in AuthCredentials.platformLookupByAPIURL)) { try { const url = new URL(val); - if(url.hostname.endsWith(".sbgenomics.com")){ + if (url.hostname.endsWith(".sbgenomics.com") || url.hostname.endsWith(".nhlbi.nih.gov")) { return null; } else { return {name: true}; @@ -292,10 +292,16 @@ export class PlatformCredentialsModalComponent implements OnInit { const apiURL: string = this.form.get("url").value; - const platform = AuthCredentials.platformLookupByAPIURL[apiURL]; - const url = platform ? platform.devTokenURL : "https://igor.sbgenomics.com/developer#token"; + // Remove port from url + const platformAPIURL = apiURL.replace(/(:[1-9]+)$/, ""); - this.system.openLink(url); + const isPlatform = + AuthCredentials.platformLookupByAPIURL[platformAPIURL] || AuthCredentials.stagingLookupByAPIURL[platformAPIURL]; + + const url = isPlatform ? isPlatform.platformURL : platformAPIURL; + const devTokenPath = AuthCredentials.platformDevTokenPath; + + this.system.openLink(`${url}${devTokenPath}`); } @@ -318,4 +324,3 @@ export class PlatformCredentialsModalComponent implements OnInit { }; } } - diff --git a/src/app/editor-common/components/platform-app-common/platform-app.service.ts b/src/app/editor-common/components/platform-app-common/platform-app.service.ts index 7d5a57fd2..a902af831 100644 --- a/src/app/editor-common/components/platform-app-common/platform-app.service.ts +++ b/src/app/editor-common/components/platform-app-common/platform-app.service.ts @@ -4,6 +4,7 @@ import {AuthService} from "../../../auth/auth.service"; import {NotificationBarService} from "../../../layout/notification-bar/notification-bar.service"; import {SystemService} from "../../../platform-providers/system.service"; import {take} from "rxjs/operators"; +import {AuthCredentials} from "../../../auth/model/auth-credentials"; @Injectable() export class PlatformAppService { @@ -25,15 +26,22 @@ export class PlatformAppService { } // Remove port from url - let platformURL = credentials.url.replace(/.com:[1-9]+/, ".com"); + const platformAPIURL = credentials.url.replace(/(:[1-9]+)$/, "") - // If its not a vayu - if (!~platformURL.indexOf("-vayu")) { + let platformURL = platformAPIURL; - platformURL = ~platformURL.indexOf("-api") ? platformURL.replace("-api", "") : "https://igor.sbgenomics.com"; + const isPlatform = + AuthCredentials.platformLookupByAPIURL[platformAPIURL] || AuthCredentials.stagingLookupByAPIURL[platformAPIURL]; + + if (!~platformAPIURL.indexOf("-vayu")) { + + platformURL = (isPlatform && isPlatform.platformURL) + || platformURL.replace("-api", "") + || "https://igor.sbgenomics.com"; } + // URL example: u/ivanbatic/test-project/apps/#ivanbatic/test-project/bamtools-index-2-4-0 const [userSlug, projectSlug, appSlug, revisionID = ""] = appID.split("/");