Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include user email among outputs of check_terra_env task #508

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions pipes/WDL/tasks/tasks_terra.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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"

Expand All @@ -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" \
Expand Down Expand Up @@ -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")
Expand Down
Loading