Skip to content

Commit

Permalink
refactor: Centralize Platform information
Browse files Browse the repository at this point in the history
1. All platform data/metadata are now stored in
   src/app/auth/model/auth-credentials.ts
2. This is a central source of truth from which
   other components, like platform-credentials-modal.component.ts
   can get Platform data like API endpoints, labels etc.
3. This refactor was needed because the existing
   hacky formula for extracting information from
   the API URL breaks with the China setup and
4. It is error prone to add platform information
   in multiple places, for example when F4C was
   added the short and long names were not updated.
   We now use DRY principle and centralize the
   platform list.
5. China platform added to list
  • Loading branch information
Kaushik Ghose committed Feb 22, 2019
1 parent 1f72279 commit c1a57dd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 39 deletions.
76 changes: 52 additions & 24 deletions src/app/auth/model/auth-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ 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 platformLookupByAPIURL = {
"https://api.sbgenomics.com": {
"name": "Seven Bridges",
"shortName": "SBG",
"devTokenURL": "https://igor.sbgenomics.com/developer#token",
},
"https://eu-api.sbgenomics.com": {
"name": "Seven Bridges (EU)",
"shortName": "SBG-EU",
"devTokenURL": "https://eu.sbgenomics.com/developer#token",
},
"https://api.sevenbridges.cn": {
"name": "Seven Bridges (China)",
"shortName": "SBG-CN",
"devTokenURL": "https://platform.sevenbridges.cn/developer#token",
},
"https://cgc-api.sbgenomics.com": {
"name": "Cancer Genomics Cloud",
"shortName": "CGC",
"devTokenURL": "https://cgc.sbgenomics.com/developer#token",
},
"https://cavatica-api.sbgenomics.com": {
"name": "Cavatica",
"shortName": "CAVATICA",
"devTokenURL": "https://cavatica.sbgenomics.com/developer#token",
},
"https://f4c-api.sbgenomics.com": {
"name": "Fair4Cures",
"shortName": "F4C",
"devTokenURL": "https://f4c.sbgenomics.com/developer#token",
},
}

id: string;
user: User;
url: string;
Expand Down Expand Up @@ -35,35 +68,30 @@ export class AuthCredentials implements UserPlatformIdentifier {
return url.slice(8, url.length - 15);
}

static getPlatformList(): Array<Map<string, string>> {
let lu = this.platformLookupByAPIURL
let platformList = []
for (let apiURL in lu) {
platformList.push({text: lu[apiURL]["name"], value: apiURL})
}
return platformList
}

static getPlatformShortName(url: string): string {
const subdomain = AuthCredentials.getSubdomain(url);
switch (subdomain) {
case "api":
return "SBG";
case "eu-api":
return "EU";
case "cgc-api":
return "CGC";
case "cavatica-api":
return "CAVATICA";
default:
return subdomain.indexOf("vayu") === -1 ? subdomain : subdomain.split(".")[0];
if(url in this.platformLookupByAPIURL) {
return this.platformLookupByAPIURL[url]["shortName"]
} else {
const subdomain = AuthCredentials.getSubdomain(url)
return subdomain.indexOf("vayu") === -1 ? subdomain : subdomain.split(".")[0]
}
}

static getPlatformLabel(url: string): string {
const subdomain = AuthCredentials.getSubdomain(url);
switch (subdomain) {
case "api":
return "Seven Bridges";
case "eu-api":
return "Seven Bridges (EU)";
case "cgc-api":
return "Cancer Genomics Cloud";
case "cavatica-api":
return "Cavatica";
default:
return subdomain.indexOf("vayu") === -1 ? subdomain : subdomain.split(".")[0];
if(url in this.platformLookupByAPIURL) {
return this.platformLookupByAPIURL[url]["name"]
} else {
const subdomain = AuthCredentials.getSubdomain(url)
return subdomain.indexOf("vayu") === -1 ? subdomain : subdomain.split(".")[0]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,8 @@ export class PlatformCredentialsModalComponent implements OnInit {
/** FormGroup for modal inputs */
form: FormGroup;

platformList = [
{text: "Seven Bridges (Default)", value: "https://api.sbgenomics.com"},
{text: "Seven Bridges (EU)", value: "https://eu-api.sbgenomics.com"},
{text: "Seven Bridges (China)", value: "https://api.sevenbridges.cn/"},
{text: "Cancer Genomics Cloud", value: "https://cgc-api.sbgenomics.com"},
{text: "Cavatica", value: "https://cavatica-api.sbgenomics.com"},
{text: "Fair4Cures", value: "https://f4c-api.sbgenomics.com"}
];
platformList = AuthCredentials.getPlatformList()


constructor(private system: SystemService,
private auth: AuthService,
Expand Down Expand Up @@ -289,14 +283,12 @@ export class PlatformCredentialsModalComponent implements OnInit {

openTokenPage() {
const apiURL: string = this.form.get("url").value;
const apiSubdomain = apiURL.slice("https://".length, apiURL.length - ".sbgenomics.com".length);

let platformSubdomain = "igor";
if (apiSubdomain.endsWith("-api")) {
platformSubdomain = apiSubdomain.slice(0, apiSubdomain.length - ".com".length);
if(apiURL in AuthCredentials.platformLookupByAPIURL) {
this.system.openLink(AuthCredentials.platformLookupByAPIURL[apiURL]["devTokenURL"])
} else {
// Most likely a vayu
this.system.openLink("https://igor.sbgenomics.com/developer#token")
}
const url = `https://${platformSubdomain}.sbgenomics.com/developer#token`;
this.system.openLink(url);
}

close() {
Expand Down

0 comments on commit c1a57dd

Please sign in to comment.