Skip to content

Commit

Permalink
try to auth so we can gsutilc cp
Browse files Browse the repository at this point in the history
  • Loading branch information
nikellepetrillo committed Dec 13, 2024
1 parent b43467c commit 6583b6e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 46 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/test_illumina_genotyping_array.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Fetch Dockstore Workflow CommitID
run: |
# Wait for Dockstore to update
sleep 180
sleep 1
# Capture the output of the script (commit ID)
DOCKSTORE_COMMIT_HASH_FROM_FETCH=$(python scripts/dockstore_api/fetch_dockstore_commit.py \
$DOCKSTORE_TOKEN \
Expand All @@ -113,23 +113,23 @@ jobs:
echo "GITHUB_COMMIT_HASH=${{ github.sha }}" >> $GITHUB_ENV
echo "GitHub Commit Hash: ${{ github.sha }}"
- name: Compare Dockstore and Commit Hashes
id: compare_hashes
run: |
echo "Comparing hashes..."
echo "Dockstore Commit Hash: $DOCKSTORE_COMMIT_HASH"
echo "GitHub Commit Hash: $GITHUB_COMMIT_HASH"
if [ "$DOCKSTORE_COMMIT_HASH" != "$GITHUB_COMMIT_HASH" ]; then
echo "Error: The Dockstore Commit Hash does not match the GitHub Commit Hash!"
echo "Mismatch found: $DOCKSTORE_COMMIT_HASH != $GITHUB_COMMIT_HASH"
exit 1
else
echo "Success: The Dockstore Commit Hash matches the GitHub Commit Hash."
fi
env:
DOCKSTORE_COMMIT_HASH: ${{ env.DOCKSTORE_COMMIT_HASH }}
GITHUB_COMMIT_HASH: ${{ env.GITHUB_COMMIT_HASH }}
# - name: Compare Dockstore and Commit Hashes
# id: compare_hashes
# run: |
# echo "Comparing hashes..."
# echo "Dockstore Commit Hash: $DOCKSTORE_COMMIT_HASH"
# echo "GitHub Commit Hash: $GITHUB_COMMIT_HASH"
#
# if [ "$DOCKSTORE_COMMIT_HASH" != "$GITHUB_COMMIT_HASH" ]; then
# echo "Error: The Dockstore Commit Hash does not match the GitHub Commit Hash!"
# echo "Mismatch found: $DOCKSTORE_COMMIT_HASH != $GITHUB_COMMIT_HASH"
# exit 1
# else
# echo "Success: The Dockstore Commit Hash matches the GitHub Commit Hash."
# fi
# env:
# DOCKSTORE_COMMIT_HASH: ${{ env.DOCKSTORE_COMMIT_HASH }}
# GITHUB_COMMIT_HASH: ${{ env.GITHUB_COMMIT_HASH }}

- name: Set Test Type for PRs
if: ${{ github.event_name == 'pull_request' }}
Expand Down
71 changes: 43 additions & 28 deletions scripts/firecloud_api/firecloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import logging
import time
import subprocess
from google.cloud import storage


# Configure logging to display INFO level and above messages
Expand Down Expand Up @@ -233,35 +234,49 @@ def get_workflow_outputs(self, submission_id, workflow_id, pipeline_name):
logging.error(f"Failed to retrieve workflow outputs. Status code: {response.status_code}")
return None, None

def gsutil_copy(self, source, destination):
"""
Copies files between GCS locations using gsutil with authentication.
:param source: The source GCS path (e.g., "gs://bucket/source_file").
:param destination: The destination GCS path (e.g., "gs://bucket/destination_file").
:return: Output of the gsutil command.
"""
# Retrieve a valid user token
token = self.get_user_token(self.delegated_creds)

# Set up the environment variable for gsutil authentication
os.environ['GOOGLE_OAUTH_ACCESS_TOKEN'] = token

# Prepare the gsutil command
command = ["gsutil", "cp", source, destination]
#echo the command
print(f"Running command: {' '.join(command)}")


try:
# Execute the gsutil copy command
result = subprocess.run(command, capture_output=True, text=True, check=True)
# def gsutil_copy(self, source, destination):
# """
# Copies files between GCS locations using gsutil with authentication.
#
# :param source: The source GCS path (e.g., "gs://bucket/source_file").
# :param destination: The destination GCS path (e.g., "gs://bucket/destination_file").
# :return: Output of the gsutil command.
# """
# # Retrieve a valid user token
# token = self.get_user_token(self.delegated_creds)
#
# # Set up the environment variable for gsutil authentication
# os.environ['GOOGLE_OAUTH_ACCESS_TOKEN'] = token
#
# # Prepare the gsutil command
# command = ["gsutil", "cp", source, destination]
# #echo the command
# print(f"Running command: {' '.join(command)}")


# try:
# # Execute the gsutil copy command
# result = subprocess.run(command, capture_output=True, text=True, check=True)
#
# # Return the command output
# return result.stdout
# except subprocess.CalledProcessError as e:
# logging.error(f"gsutil copy failed: {e.stderr}")
# raise RuntimeError(f"gsutil copy failed: {e.stderr}") from e
# exit(1)


def copy_gcs_file(source, destination):
client = storage.Client() # Uses GOOGLE_APPLICATION_CREDENTIALS implicitly
source_bucket_name, source_blob_name = source.replace("gs://", "").split("/", 1)
destination_bucket_name, destination_blob_name = destination.replace("gs://", "").split("/", 1)

source_bucket = client.bucket(source_bucket_name)
source_blob = source_bucket.blob(source_blob_name)
destination_bucket = client.bucket(destination_bucket_name)

source_bucket.copy_blob(source_blob, destination_bucket, destination_blob_name)

# Return the command output
return result.stdout
except subprocess.CalledProcessError as e:
logging.error(f"gsutil copy failed: {e.stderr}")
raise RuntimeError(f"gsutil copy failed: {e.stderr}") from e

def main(self):
logging.info("Starting process based on action.")
Expand Down

0 comments on commit 6583b6e

Please sign in to comment.