aboutsummaryrefslogtreecommitdiff
path: root/globus-weblinks
diff options
context:
space:
mode:
authorArun Isaac2025-01-03 22:13:03 +0000
committerArun Isaac2025-01-03 22:13:03 +0000
commit997bd4952195e80a080e4480be7006ddda6ac23e (patch)
treeeec50e82879a2f4575644ac7e00e0661b036bebc /globus-weblinks
downloadglobus-weblinks-997bd4952195e80a080e4480be7006ddda6ac23e.tar.gz
globus-weblinks-997bd4952195e80a080e4480be7006ddda6ac23e.tar.lz
globus-weblinks-997bd4952195e80a080e4480be7006ddda6ac23e.zip
Initial commit
Diffstat (limited to 'globus-weblinks')
-rwxr-xr-xglobus-weblinks42
1 files changed, 42 insertions, 0 deletions
diff --git a/globus-weblinks b/globus-weblinks
new file mode 100755
index 0000000..74fd6f0
--- /dev/null
+++ b/globus-weblinks
@@ -0,0 +1,42 @@
+#! /usr/bin/env python3
+
+import argparse
+from pathlib import PurePath
+import sys
+import globus_sdk
+
+# This is the tutorial client ID from
+# https://globus-sdk-python.readthedocs.io/en/stable/tutorial.html.
+# Let's not bother to create our own.
+CLIENT_ID = "61338d24-54d5-408f-a10d-66c06b59f6d2"
+
+def get_transfer_token():
+ client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
+ client.oauth2_start_flow()
+
+ authorize_url = client.oauth2_get_authorize_url()
+ print(f"Please go to this URL and login:\n\n{authorize_url}\n",
+ file=sys.stderr)
+
+ print("Please enter the code you get after login here: ",
+ end="", file=sys.stderr)
+ auth_code = input().strip()
+ return (client.oauth2_exchange_code_for_tokens(auth_code)
+ .by_resource_server["transfer.api.globus.org"]["access_token"])
+
+def find_files(transfer_client, endpoint_id, path=PurePath("/")):
+ for file in transfer_client.operation_ls(endpoint_id, path=str(path))["DATA"]:
+ if file["type"] == "dir":
+ yield from find_files(transfer_client, endpoint_id, path / file["name"])
+ else:
+ yield path / file["name"]
+
+parser = argparse.ArgumentParser(description="Get web links for Globus collection")
+parser.add_argument("endpoint_id", metavar="endpoint-id", help="Endpoint ID of collection")
+args = parser.parse_args()
+
+transfer_client = globus_sdk.TransferClient(
+ authorizer=globus_sdk.AccessTokenAuthorizer(get_transfer_token()))
+endpoint = transfer_client.get_endpoint(args.endpoint_id)
+for path in find_files(transfer_client, args.endpoint_id):
+ print(endpoint["https_server"] + str(path))