From 997bd4952195e80a080e4480be7006ddda6ac23e Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 3 Jan 2025 22:13:03 +0000 Subject: Initial commit --- globus-weblinks | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 globus-weblinks (limited to 'globus-weblinks') 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)) -- cgit v1.2.3