diff --git a/pipes/WDL/tasks/tasks_terra.wdl b/pipes/WDL/tasks/tasks_terra.wdl index 275b27d4f..a72505498 100644 --- a/pipes/WDL/tasks/tasks_terra.wdl +++ b/pipes/WDL/tasks/tasks_terra.wdl @@ -46,6 +46,7 @@ task check_terra_env { touch google_project_id.txt # create Terra-related output files + touch user_email.txt touch workspace_name.txt touch workspace_namespace.txt touch workspace_bucket_path.txt @@ -61,6 +62,20 @@ task check_terra_env { # write system environment variables to output file env | tee -a env_info.log + # check if running on GCP + if curl -s metadata.google.internal -i | grep -E 'Metadata-Flavor:\s+Google'; then + echo "Cloud platform appears to be GCP"; + echo "true" > RUNNING_ON_GCP + + GCLOUD_OAUTH_BEARER_TOKEN="$(gcloud auth print-access-token)" + + # write gcloud env info to output files + gcloud info | tee -a gcloud_config_info.log + else + echo "NOT running on GCP"; + echo "false" > RUNNING_ON_GCP + fi + GOOGLE_PROJECT_ID="$(gcloud config list --format='value(core.project)')" echo "$GOOGLE_PROJECT_ID" > google_project_id.txt @@ -70,23 +85,19 @@ task check_terra_env { # (shell-portable regex conditional) echo "Job appears to be running on Terra (GCP project ID: ${GOOGLE_PROJECT_ID})" echo "true" > RUNNING_ON_TERRA + + # get user e-mail for Terra account via firecloud API + curl -s -X 'GET' \ + 'https://api.firecloud.org/me?userDetailsOnly=true' \ + -H 'accept: application/json' \ + -H "Authorization: Bearer $GCLOUD_OAUTH_BEARER_TOKEN" > user_info.json + + USER_EMAIL="$(jq -cr '.userEmail' user_info.json | tee user_email.txt)" else echo "NOT running on Terra" echo "false" > RUNNING_ON_TERRA fi - # check if running on GCP - if curl -s metadata.google.internal -i | grep -E 'Metadata-Flavor:\s+Google'; then - echo "Cloud platform appears to be GCP"; - echo "true" > RUNNING_ON_GCP - - # write gcloud env info to output files - gcloud info | tee -a gcloud_config_info.log - else - echo "NOT running on GCP"; - echo "false" > RUNNING_ON_GCP - fi - if grep --quiet "true" RUNNING_ON_GCP && grep --quiet "true" RUNNING_ON_TERRA; then echo "Running on Terra+GCP" @@ -112,8 +123,6 @@ task check_terra_env { #GOOGLE_PROJECT_ID="$(sed -n -E 's!.*(terra-[0-9a-f]+).*# project to use if requester pays$!\1!p' /cromwell_root/gcs_localization.sh | sort -u)" # ======================================= - GCLOUD_OAUTH_BEARER_TOKEN="$(gcloud auth print-access-token)" - # === request workspace name AND namespace from API, based on bucket path / ID === curl -s -X 'GET' \ "https://api.firecloud.org/api/workspaces/id/${WORKSPACE_ID}?fields=workspace.name%2Cworkspace.namespace%2Cworkspace.googleProject" \ @@ -201,6 +210,8 @@ task check_terra_env { String google_project_id = read_string("google_project_id.txt") + String user_email = read_string("user_email.txt") + String workspace_id = read_string("workspace_id.txt") String workspace_name = read_string("workspace_name.txt") String workspace_namespace = read_string("workspace_namespace.txt")