Skip to content

Commit

Permalink
initial hack proof of principe
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Sep 30, 2023
1 parent 249f942 commit 235887f
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions js/drs/terraResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
async function resolve(drsURL, accessToken) {

const response = await postData(drsURL, accessToken)
console.log(response)
}

async function postData(drsURL, accessToken) {
// Default options are marked with *
const response = await fetch("https://drshub.dsde-prod.broadinstitute.org/api/v4/drs/resolve", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${accessToken}`,
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify({
url: drsURL,
fields: ["bucket", "contentType", "fileName", "gsUri", "hashes", "localizationPath", "name", "size", "timeCreated", "timeUpdated"]
}), // body data type must match "Content-Type" header
})
return response.text() // parses JSON response into native JavaScript objects
}


(async () => {
// await resolve("drs://data.terra.bio/v2_3174119c-a10f-4826-a487-08f1bf831a8a", "eyJhbGciO")
// await resolve("drs://data.terra.bio/v2_10a3a0c2-df0a-4950-8c3e-64c444deea36", "eyJhbGciOiJSUz")

await resolve("drs://dg.4503:dg.4503/c64fded3-459b-4fca-82bc-35d154e9aa91", "Access Token"),
await resolve("drs://dg.4503:dg.4503/a5d35aac-ec73-46cc-9fb0-13503717aac4", "eyJhbGciOiJS")


})()

/*
/usr/local/bin/node /Users/jrobinso/igv-team Dropbox/James Robinson/projects/igv.js/js/drs/terraResolver.js
{
"bucket" : "datarepo-8e14968c-bucket",
"contentType" : "binary/octet-stream",
"fileName" : "heart_slc25a3.bam",
"gsUri" : "gs://datarepo-8e14968c-bucket/75db154a-1119-4b21-8962-4b679cd1b8c0/3174119c-a10f-4826-a487-08f1bf831a8a/heart_slc25a3.bam",
"hashes" : {
"crc32c" : "9b0ad5b4",
"md5" : "1806446c79c6fae35df0fea9ce7674f0"
},
"localizationPath" : "/igv/heart_slc25a3.bam",
"name" : "75db154a-1119-4b21-8962-4b679cd1b8c0/3174119c-a10f-4826-a487-08f1bf831a8a/heart_slc25a3.bam",
"size" : 318324,
"timeCreated" : "2023-09-28T16:09:58.459Z",
"timeUpdated" : "2023-09-28T16:09:58.459Z"
}
{
"bucket" : "datarepo-8e14968c-bucket",
"contentType" : "binary/octet-stream",
"fileName" : "heart_slc25a3.bam.bai",
"gsUri" : "gs://datarepo-8e14968c-bucket/75db154a-1119-4b21-8962-4b679cd1b8c0/10a3a0c2-df0a-4950-8c3e-64c444deea36/heart_slc25a3.bam.bai",
"hashes" : {
"crc32c" : "59bbaef0",
"md5" : "448e60d39c6eda63fc649de87fe2bb43"
},
"localizationPath" : "/igv/heart_slc25a3.bam.bai",
"name" : "75db154a-1119-4b21-8962-4b679cd1b8c0/10a3a0c2-df0a-4950-8c3e-64c444deea36/heart_slc25a3.bam.bai",
"size" : 48688,
"timeCreated" : "2023-09-28T16:09:58.558Z",
"timeUpdated" : "2023-09-28T16:09:58.558Z"
}
Process finished with exit code 0
{
"bucket" : "nih-nhlbi-biodata-catalyst-1000-genomes",
"contentType" : "application/json",
"fileName" : "HG03197.final.cram",
"gsUri" : "gs://nih-nhlbi-biodata-catalyst-1000-genomes/CCDG_14151/Project_CCDG_14151_B01_GRM_WGS.cram.2020-02-12/Sample_HG03197/analysis/HG03197.final.cram",
"hashes" : {
"md5" : "1b3ad8a0bab634829a11adfc965dd0df"
},
"localizationPath" : null,
"name" : "CCDG_14151/Project_CCDG_14151_B01_GRM_WGS.cram.2020-02-12/Sample_HG03197/analysis/HG03197.final.cram",
"size" : 15045663134,
"timeCreated" : "2020-10-02T16:08:49.348Z",
"timeUpdated" : "2020-10-02T16:08:49.348Z"
}
{
"bucket" : "nih-nhlbi-biodata-catalyst-1000-genomes",
"contentType" : "application/json",
"fileName" : "HG03197.final.cram.crai",
"gsUri" : "gs://nih-nhlbi-biodata-catalyst-1000-genomes/CCDG_14151/Project_CCDG_14151_B01_GRM_WGS.cram.2020-02-12/Sample_HG03197/analysis/HG03197.final.cram.crai",
"hashes" : {
"md5" : "7aa39824444f8c21c7c8e0c42e45aa34"
},
"localizationPath" : null,
"name" : "CCDG_14151/Project_CCDG_14151_B01_GRM_WGS.cram.2020-02-12/Sample_HG03197/analysis/HG03197.final.cram.crai",
"size" : 1311059,
"timeCreated" : "2020-10-02T16:08:49.455Z",
"timeUpdated" : "2020-10-02T16:08:49.455Z"
}
*/

0 comments on commit 235887f

Please sign in to comment.