Skip to content

Commit

Permalink
Provide automatic consent for Globus (#304)
Browse files Browse the repository at this point in the history
* Prompt for Globus consent

* Update data_access consent check (#306)

* Update data_access consent check

* None should return False

* Updates

---------

Co-authored-by: Nick Tyler <[email protected]>
  • Loading branch information
forsyth2 and tylern4 authored Oct 24, 2023
1 parent 717ffb8 commit d881bc9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
3 changes: 1 addition & 2 deletions tests/test_globus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
r"theta.*\.alcf\.anl\.gov": "08925f04-569f-11e7-bef8-22000b9a448b",
r"blueslogin.*\.lcrc\.anl\.gov": "61f9954c-a4fa-11ea-8f07-0a21f750d19b",
r"chr.*\.lcrc\.anl\.gov": "61f9954c-a4fa-11ea-8f07-0a21f750d19b",
r"cori.*\.nersc\.gov": "9d6d99eb-6d04-11e5-ba46-22000b92c6ec",
r"perlmutter.*\.nersc\.gov": "6bdc7956-fc0f-4ad2-989c-7aa5ee643a79", # If this doesn't work, use cori
r"perlmutter.*\.nersc\.gov": "6bdc7956-fc0f-4ad2-989c-7aa5ee643a79",
}


Expand Down
41 changes: 37 additions & 4 deletions zstash/globus.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
r"chrlogin.*\.lcrc\.anl\.gov": "61f9954c-a4fa-11ea-8f07-0a21f750d19b",
r"b\d+\.lcrc\.anl\.gov": "61f9954c-a4fa-11ea-8f07-0a21f750d19b",
r"chr.*\.lcrc\.anl\.gov": "61f9954c-a4fa-11ea-8f07-0a21f750d19b",
r"cori.*\.nersc\.gov": "9d6d99eb-6d04-11e5-ba46-22000b92c6ec",
r"compy.*\.pnl\.gov": "68fbd2fa-83d7-11e9-8e63-029d279f7e24",
r"perlmutter.*\.nersc\.gov": "6bdc7956-fc0f-4ad2-989c-7aa5ee643a79", # If this doesn't work, use cori
r"perlmutter.*\.nersc\.gov": "6bdc7956-fc0f-4ad2-989c-7aa5ee643a79",
}

remote_endpoint = None
Expand All @@ -39,6 +38,40 @@
archive_directory_listing: IterableTransferResponse = None


def check_endpoint_version_5(ep_id):
output = transfer_client.get_endpoint(ep_id)
version = output.get("gcs_version", "0.0")
if output["gcs_version"] is None:
return False
elif int(version.split(".")[0]) >= 5:
return True
return False


def submit_transfer_with_checks(transfer_data):
try:
task = transfer_client.submit_transfer(transfer_data)
except TransferAPIError as err:
if err.info.consent_required:
scopes = "urn:globus:auth:scope:transfer.api.globus.org:all["
for ep_id in [remote_endpoint, local_endpoint]:
if check_endpoint_version_5(ep_id):
scopes += f" *https://auth.globus.org/scopes/{ep_id}/data_access"
scopes += " ]"
native_client = NativeClient(
client_id="6c1629cf-446c-49e7-af95-323c6412397f", app_name="Zstash"
)
native_client.login(requested_scopes=scopes)
# Quit here and tell user to re-try
print(
"Consents added, please re-run the previous command to start transfer"
)
sys.exit(0)
else:
raise err
return task


def globus_activate(hpss: str):
"""
Read the local globus endpoint UUID from ~/.zstash.ini.
Expand Down Expand Up @@ -196,7 +229,7 @@ def globus_transfer(
)
else:
logger.error("Transfer FAILED")
task = transfer_client.submit_transfer(transfer_data)
task = submit_transfer_with_checks(transfer_data)
task_id = task.get("task_id")
transfer_data = None
except TransferAPIError as e:
Expand Down Expand Up @@ -270,7 +303,7 @@ def globus_finalize(non_blocking: bool = False):

if transfer_data:
try:
last_task = transfer_client.submit_transfer(transfer_data)
last_task = submit_transfer_with_checks(transfer_data)
last_task_id = last_task.get("task_id")
except TransferAPIError as e:
if e.code == "NoCredException":
Expand Down

0 comments on commit d881bc9

Please sign in to comment.