Skip to content

Commit

Permalink
try returning workspace info based on API return
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkinsc committed Oct 20, 2023
1 parent 60cfa93 commit 0d3ab84
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 21 additions & 4 deletions pipes/WDL/tasks/tasks_terra.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ task get_gcloud_env_info {
command <<<
set -ex

# ========== method 1: from google project IAM label metadata
gcloud auth print-access-token

GOOGLE_PROJECT_ID="$(gcloud config list --format='value(core.project)')"
echo "$GOOGLE_PROJECT_ID" > google_project_id.txt

#get project namespace:
WORKSPACE_NAMESPACE="$(gcloud projects describe $GOOGLE_PROJECT_ID --format='value(labels.workspacenamespace)')"
Expand All @@ -57,12 +59,23 @@ task get_gcloud_env_info {
echo "WORKSPACE_NAMESPACE: ${WORKSPACE_NAMESPACE}"
echo "WORKSPACE_NAME: ${WORKSPACE_NAME}"

ls -lah /cromwell_root
# ========== method 2: matching a project returned by the API based on the google project ID

# get list of workspaces, limiting the output to only the fields we need
curl -X 'GET' \
"https://leonardo.dsde-dev.broadinstitute.org/api/google/v1/apps/${GOOGLE_PROJECT_ID}" \
-H 'accept: text/plain' \
-H "Authorization: Bearer $(gcloud auth print-access-token)"
'https://api.firecloud.org/api/workspaces?fields=workspace.name%2Cworkspace.namespace%2Cworkspace.googleProject' \
-H 'accept: application/json' \
-H "Authorization: Bearer $(gcloud auth print-access-token)" > workspace_list.json

# extract workspace name
WORKSPACE_NAME=$(jq -cr '.[] | select( .workspace.googleProject == "terra-bf70b335" ).workspace | .name' workspace_list.json)
echo "$WORKSPACE_NAME" > workspace_name.txt

# extract workspace namespace
WORKSPACE_NAMESPACE=$(jq -cr '.[] | select( .workspace.googleProject == "terra-bf70b335" ).workspace | .namespace' workspace_list.json)
echo "$WORKSPACE_NAMESPACE" > workspace_namespace.txt

# ======================================================================================

touch additional_command_stdout.log

Expand All @@ -80,6 +93,10 @@ task get_gcloud_env_info {
output {
Array[String] env_info_files = glob("./*_info.log")
File additional_command_stdout = "additional_command_stdout.log"

String workspace_name = read_string("workspace_name.txt")
String workspace_namespace = read_string("workspace_namespace.txt")
String google_project_id = read_string("google_project_id.txt")
}
runtime {
docker: "quay.io/broadinstitute/viral-baseimage:0.1.20"
Expand Down
4 changes: 4 additions & 0 deletions pipes/WDL/workflows/dump_gcloud_env_info.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ workflow dump_gcloud_env_info {
output {
Array[String] gcloud_env_info_files = get_gcloud_env_info.env_info_files
File additional_command_stdout = get_gcloud_env_info.additional_command_stdout

String workspace_name = get_gcloud_env_info.workspace_name
String workspace_namespace = get_gcloud_env_info.workspace_namespace
String google_project_id = get_gcloud_env_info.google_project_id
}
}

0 comments on commit 0d3ab84

Please sign in to comment.