Skip to content

Commit

Permalink
fix(platform): Update platform urls
Browse files Browse the repository at this point in the history
  • Loading branch information
marijanlekic committed Nov 13, 2020
1 parent f0f51a6 commit 468c89b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 55 deletions.
45 changes: 30 additions & 15 deletions src/app/auth/model/auth-credentials.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ import {withLatestFrom, take} from "rxjs/operators";
</button>
</div>
<div *ngIf="form.dirty && form.invalid">
<div *ngIf="form.dirty && form.invalid">
<span class="text-warning" *ngIf="form.get('token').hasError('required')">
<i class="fa fa-warning fa-fw"></i>
<i class="fa fa-warning fa-fw"></i>
Token cannot be empty
</span>
Expand Down Expand Up @@ -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);
});

}

Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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}`);

}

Expand All @@ -318,4 +324,3 @@ export class PlatformCredentialsModalComponent implements OnInit {
};
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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("/");

Expand Down

0 comments on commit 468c89b

Please sign in to comment.