diff --git a/pipes/WDL/tasks/tasks_terra.wdl b/pipes/WDL/tasks/tasks_terra.wdl index 92ddd3708..8fca11439 100644 --- a/pipes/WDL/tasks/tasks_terra.wdl +++ b/pipes/WDL/tasks/tasks_terra.wdl @@ -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)')" @@ -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 @@ -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" diff --git a/pipes/WDL/workflows/dump_gcloud_env_info.wdl b/pipes/WDL/workflows/dump_gcloud_env_info.wdl index e917bdcb7..17b2499f6 100644 --- a/pipes/WDL/workflows/dump_gcloud_env_info.wdl +++ b/pipes/WDL/workflows/dump_gcloud_env_info.wdl @@ -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 } }